topic.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var that = this;
  32. if (this.data.page+1 > that.data.count / that.data.size) {
  33. return true;
  34. }
  35. that.setData({
  36. "page": parseInt(that.data.page) + 1
  37. });
  38. this.getTopic();
  39. },
  40. getTopic: function(){
  41. let that = this;
  42. that.setData({
  43. scrollTop: 0,
  44. showPage: false,
  45. topicList: []
  46. });
  47. // 页面渲染完成
  48. wx.showToast({
  49. title: '加载中...',
  50. icon: 'loading',
  51. duration: 2000
  52. });
  53. util.request(api.TopicList, { page: that.data.page, size: that.data.size }).then(function (res) {
  54. if (res.errno === 0) {
  55. that.setData({
  56. scrollTop: 0,
  57. topicList: res.data.data,
  58. showPage: true,
  59. count: res.data.count
  60. });
  61. }
  62. wx.hideToast();
  63. });
  64. },
  65. onPullDownRefresh() {
  66. this.getTopic();
  67. },
  68. prevPage: function (event) {
  69. if (this.data.page <= 1) {
  70. return false;
  71. }
  72. var that = this;
  73. that.setData({
  74. "page": parseInt(that.data.page) - 1
  75. });
  76. this.getTopic();
  77. }
  78. })