topic.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. var app = getApp()
  4. Page({
  5. data: {
  6. // text:"这是一个页面"
  7. topicList: [],
  8. page: 1,
  9. size: 10,
  10. count: 0,
  11. scrollTop: 0,
  12. showPage: false
  13. },
  14. onLoad: function (options) {
  15. // 页面初始化 options为页面跳转所带来的参数
  16. this.getTopic();
  17. },
  18. onReady: function () {
  19. // 页面渲染完成
  20. },
  21. onShow: function () {
  22. // 页面显示
  23. },
  24. onHide: function () {
  25. // 页面隐藏
  26. },
  27. onUnload: function () {
  28. // 页面关闭
  29. },
  30. nextPage: function (event) {
  31. console.log();
  32. var that = this;
  33. if (this.data.page+1 > that.data.count / that.data.size) {
  34. return true;
  35. }
  36. that.setData({
  37. "page": parseInt(that.data.page) + 1
  38. });
  39. this.getTopic();
  40. },
  41. getTopic: function(){
  42. let that = this;
  43. that.setData({
  44. scrollTop: 0,
  45. showPage: false,
  46. topicList: []
  47. });
  48. // 页面渲染完成
  49. wx.showToast({
  50. title: '加载中...',
  51. icon: 'loading',
  52. duration: 2000
  53. });
  54. util.request(api.TopicList, { page: that.data.page, size: that.data.size }).then(function (res) {
  55. if (res.errno === 0) {
  56. that.setData({
  57. scrollTop: 0,
  58. topicList: res.data.data,
  59. showPage: true,
  60. count: res.data.count
  61. });
  62. }
  63. wx.hideToast();
  64. });
  65. },
  66. prevPage: function (event) {
  67. if (this.data.page <= 1) {
  68. return false;
  69. }
  70. var that = this;
  71. that.setData({
  72. "page": parseInt(that.data.page) - 1
  73. });
  74. this.getTopic();
  75. }
  76. })