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