index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var app = getApp();
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. refresh: {
  8. type: Boolean,
  9. value: false,
  10. observer: function (t) {
  11. let that = this;
  12. if (t) this.setData({ pageNum: 1, noMore: false, list: [] }, () => { that.getData() })
  13. }
  14. },
  15. clearTimer: {
  16. type: Boolean,
  17. value: false
  18. },
  19. skin: {
  20. type: Object
  21. }
  22. },
  23. /**
  24. * 组件的初始数据
  25. */
  26. data: {
  27. disabled: false,
  28. list: [],
  29. pageNum: 1,
  30. noMore: false,
  31. rushEndTime: 0
  32. },
  33. /**
  34. * 组件的方法列表
  35. */
  36. methods: {
  37. getData: function () {
  38. var token = wx.getStorageSync('token');
  39. var that = this;
  40. var cur_community = wx.getStorageSync('community');
  41. app.util.request({
  42. 'url': 'entry/wxapp/index',
  43. 'data': {
  44. controller: 'index.load_spikebuy_goodslist',
  45. token: token,
  46. pageNum: that.data.pageNum,
  47. head_id: cur_community.communityId
  48. },
  49. dataType: 'json',
  50. success: function (res) {
  51. if (res.data.code == 0) {
  52. let oldList = that.data.list;
  53. let list = oldList.concat(res.data.list);
  54. let is_show_spike_buy_time = res.data.is_show_spike_buy_time;
  55. //取最大时间
  56. let rushEndTime = that.getTime(list);
  57. console.log(rushEndTime)
  58. that.setData({ list, rushEndTime, is_show_spike_buy_time })
  59. } else {
  60. that.setData({ noMore: true })
  61. }
  62. }
  63. })
  64. },
  65. getMore: function () {
  66. if (this.data.noMore) return;
  67. let that = this;
  68. let pageNum = that.data.pageNum + 1;
  69. console.log(pageNum)
  70. this.setData({ pageNum },
  71. () => {
  72. that.getData();
  73. })
  74. },
  75. openSku: function (e) {
  76. let idx = e.currentTarget.dataset.idx;
  77. this.setData({ disabled: false })
  78. let spuItem = this.data.list[idx];
  79. this.triggerEvent("openSku", {
  80. actId: spuItem.actId,
  81. skuList: spuItem.skuList,
  82. promotionDTO: spuItem.promotionDTO || '',
  83. is_take_vipcard: spuItem.is_take_vipcard,
  84. is_mb_level_buy: spuItem.is_mb_level_buy,
  85. allData: {
  86. spuName: spuItem.spuName,
  87. skuImage: spuItem.skuImage,
  88. actPrice: spuItem.actPrice,
  89. canBuyNum: spuItem.spuCanBuyNum,
  90. stock: spuItem.spuCanBuyNum,
  91. marketPrice: spuItem.marketPrice,
  92. oneday_limit_count: spuItem.oneday_limit_count,
  93. total_limit_count: spuItem.total_limit_count,
  94. one_limit_count: spuItem.one_limit_count
  95. }
  96. })
  97. },
  98. getTime: function (list) {
  99. let that = this;
  100. let end_time = 0;
  101. let e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
  102. e === 0 && list.map(function (t) {
  103. t.end_time *= 1000;
  104. end_time = (t.end_time > end_time) ? t.end_time : end_time;
  105. })
  106. return end_time;
  107. }
  108. }
  109. })