index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const { Tab } = require('../../assets/libs/zanui/index');
  2. var app = getApp();
  3. Page(Object.assign({}, Tab, {
  4. data: {
  5. postList: [],
  6. loading: false,
  7. nodata: false,
  8. nomore: false,
  9. tab: {
  10. list: [],
  11. selectedId: '0',
  12. scroll: true,
  13. height: 44
  14. },
  15. },
  16. category: 0,
  17. page: 1,
  18. onLoad: function (option) {
  19. var that = this;
  20. this.category = 0;
  21. this.page = 1;
  22. this.setData({ ["tab.list"]: app.globalData.tabList });
  23. this.loadPost();
  24. },
  25. onPullDownRefresh: function () {
  26. this.setData({ nodata: false, nomore: false });
  27. this.page = 1;
  28. this.loadPost(function () {
  29. wx.stopPullDownRefresh();
  30. });
  31. },
  32. onReachBottom: function () {
  33. var that = this;
  34. this.loadPost(function (data) {
  35. if (data.postList.length == 0) {
  36. app.info("暂无更多数据");
  37. }
  38. });
  39. },
  40. loadPost: function (cb) {
  41. var that = this;
  42. if (that.data.nomore == true || that.data.loading == true) {
  43. return;
  44. }
  45. this.setData({ loading: true });
  46. app.request('/post/index', { model: this.model, category: this.category, page: this.page }, function (data, ret) {
  47. that.setData({
  48. loading: false,
  49. nodata: that.page == 1 && data.postList.length == 0 ? true : false,
  50. nomore: that.page > 1 && data.postList.length == 0 ? true : false,
  51. postList: that.page > 1 ? that.data.postList.concat(data.postList) : data.postList,
  52. });
  53. that.page++;
  54. typeof cb == 'function' && cb(data);
  55. }, function (data, ret) {
  56. app.error(ret.msg);
  57. });
  58. },
  59. handleZanTabChange(e) {
  60. var componentId = e.componentId;
  61. var selectedId = e.selectedId;
  62. this.category = selectedId;
  63. this.page = 1;
  64. this.setData({
  65. nodata: false,
  66. nomore: false,
  67. [`${componentId}.selectedId`]: selectedId
  68. });
  69. wx.pageScrollTo({ scrollTop: 0 });
  70. this.loadPost();
  71. }
  72. }))