activity.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. pageIndex: 1,
  6. pageSize:10,
  7. activeData: [],//活动列表
  8. bottom: false,
  9. vid:''
  10. },
  11. onLoad: function (options) {
  12. this.setData({ vid: options.vid });
  13. this.getHotActivity(0);
  14. },
  15. getHotActivity(status) {
  16. let that = this;
  17. util.ajax({
  18. func: "v2/voucher/articles",
  19. data: { "vid": that.data.vid, "pageSize": that.data.pageSize, "pageIndex": that.data.pageIndex}
  20. }, function (res) {
  21. if (res.code == 0) {
  22. let datas = res.data.list, activeData = that.data.activeData, bottom = false;
  23. if (datas.length < 10 && that.data.pageIndex>1) bottom = true;
  24. if (that.data.pageIndex == 1) {
  25. activeData = datas;
  26. } else {
  27. activeData = [...activeData, ...datas];
  28. }
  29. that.setData({ activeData, bottom })
  30. } else {
  31. util.showTips(res.reason);
  32. }
  33. if (status == '0') {//onshow
  34. } else if (status == '1') {//onReachBottom
  35. wx.hideNavigationBarLoading();
  36. } else if (status == '2') {//onPullDownRefresh
  37. wx.stopPullDownRefresh();
  38. wx.hideNavigationBarLoading();
  39. }
  40. });
  41. },
  42. onReachBottom: function () {
  43. if (this.data.bottom) return false
  44. this.setData({ pageIndex: this.data.pageIndex+1})
  45. this.getHotActivity(1);
  46. },
  47. onPullDownRefresh: function () {
  48. let that = this;
  49. if (!util.isObjEmpty(app.globalData.city)) {
  50. wx.showNavigationBarLoading();
  51. that.setData({ pageIndex: 1});
  52. setTimeout(function () {
  53. that.getHotActivity(2);
  54. }, 1000);
  55. } else {
  56. wx.stopPullDownRefresh();
  57. }
  58. }
  59. })