topic.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. getApp().onPullDownRefresh()
  68. },
  69. prevPage: function (event) {
  70. if (this.data.page <= 1) {
  71. return false;
  72. }
  73. var that = this;
  74. that.setData({
  75. "page": parseInt(that.data.page) - 1
  76. });
  77. this.getTopic();
  78. }
  79. })