group.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. groupList: [],
  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. });
  47. // 页面渲染完成
  48. wx.showToast({
  49. title: '加载中...',
  50. icon: 'loading',
  51. duration: 2000
  52. });
  53. util.request(api.GroupList, { page: that.data.page, size: that.data.size }).then(function (res) {
  54. if (res.errno === 0) {
  55. that.setData({
  56. scrollTop: 0,
  57. groupList: res.data.data,
  58. showPage: true,
  59. count: res.data.count
  60. });
  61. }
  62. wx.hideToast();
  63. });
  64. },
  65. prevPage: function (event) {
  66. if (this.data.page <= 1) {
  67. return false;
  68. }
  69. var that = this;
  70. that.setData({
  71. "page": parseInt(that.data.page) - 1
  72. });
  73. this.getTopic();
  74. }
  75. })