index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const { Tab } = require('../../assets/libs/zanui/index');
  2. var app = getApp();
  3. Page(Object.assign({}, Tab, {
  4. data: {
  5. bannerList: [],
  6. postList: [],
  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. channel: 0,
  18. page: 1,
  19. onLoad: function () {
  20. var that = this;
  21. this.channel = 0;
  22. this.page = 1;
  23. this.setData({ ["tab.list"]: app.globalData.tabList });
  24. app.request('/index/index', {}, function (data, ret) {
  25. that.setData({
  26. bannerList: data.bannerList,
  27. postList: data.postList,
  28. ["tab.list"]: data.tabList
  29. });
  30. }, function (data, ret) {
  31. app.error(ret.msg);
  32. });
  33. },
  34. onPullDownRefresh: function () {
  35. this.setData({ nodata: false, nomore: false });
  36. this.page = 1;
  37. this.loadPost(function () {
  38. wx.stopPullDownRefresh();
  39. });
  40. },
  41. onReachBottom: function () {
  42. var that = this;
  43. this.loadPost(function (data) {
  44. if (data.postList.length == 0) {
  45. that.setData({ nomore: true, loading:false });
  46. app.info("暂无更多数据");
  47. }
  48. });
  49. },
  50. loadPost: function (cb) {
  51. var that = this;
  52. if (that.data.nomore == true || that.data.loading == true) {
  53. return;
  54. }
  55. this.setData({ loading: true });
  56. app.request('/post/index', { channel: this.channel, page: this.page }, function (data, ret) {
  57. that.setData({
  58. loading: false,
  59. nodata: that.page == 1 && data.postList.length == 0 ? true : false,
  60. nomore: that.page > 1 && data.postList.length == 0 ? true : false,
  61. postList: that.page > 1 ? that.data.postList.concat(data.postList) : data.postList,
  62. });
  63. that.page++;
  64. typeof cb == 'function' && cb(data);
  65. }, function (data, ret) {
  66. app.error(ret.msg);
  67. });
  68. },
  69. handleZanTabChange(e) {
  70. var componentId = e.componentId;
  71. var selectedId = e.selectedId;
  72. this.channel = selectedId;
  73. this.page = 1;
  74. this.setData({
  75. nodata: false,
  76. nomore: false,
  77. [`${componentId}.selectedId`]: selectedId
  78. });
  79. wx.pageScrollTo({ scrollTop: 0 });
  80. this.loadPost();
  81. },
  82. onShareAppMessage: function () {
  83. return {
  84. title: 'FastAdmin',
  85. desc: '基于ThinkPHP5和Bootstrap的极速后台框架',
  86. path: '/page/index/index'
  87. }
  88. }
  89. }))