topic.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. onPullDownRefresh() {
  40. wx.showNavigationBarLoading() //在标题栏中显示加载
  41. this.getTopic();
  42. wx.hideNavigationBarLoading() //完成停止加载
  43. wx.stopPullDownRefresh() //停止下拉刷新
  44. },
  45. getTopic: function() {
  46. let that = this;
  47. that.setData({
  48. scrollTop: 0,
  49. showPage: false,
  50. topicList: []
  51. });
  52. // 页面渲染完成
  53. wx.showToast({
  54. title: '加载中...',
  55. icon: 'loading',
  56. duration: 2000
  57. });
  58. util.request(api.TopicList, {
  59. page: that.data.page,
  60. limit: that.data.limit
  61. }).then(function(res) {
  62. if (res.errno === 0) {
  63. that.setData({
  64. scrollTop: 0,
  65. topicList: res.data.list,
  66. showPage: true,
  67. count: res.data.total
  68. });
  69. }
  70. wx.hideToast();
  71. });
  72. },
  73. prevPage: function(event) {
  74. if (this.data.page <= 1) {
  75. return false;
  76. }
  77. var that = this;
  78. that.setData({
  79. page: that.data.page - 1
  80. });
  81. this.getTopic();
  82. }
  83. })