index.js 2.0 KB

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