index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import wxh from '../../../utils/wxh.js';
  2. import {
  3. getSeckillIndexTime,
  4. getSeckillList
  5. } from '../../../api/activity.js';
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. topImage: '',
  13. parameter: {
  14. 'navbar': '1',
  15. 'return': '1',
  16. 'title': '限时秒杀',
  17. 'color': true,
  18. 'class': '0'
  19. },
  20. seckillList: [],
  21. timeList: [],
  22. active: 5,
  23. scrollLeft: 0,
  24. interval: 0,
  25. status: 1,
  26. countDownHour: "00",
  27. countDownMinute: "00",
  28. countDownSecond: "00",
  29. page: 1,
  30. limit: 20,
  31. loading: false,
  32. loadend: false
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (e) {
  38. this.getSeckillConfig();
  39. },
  40. goDetails: function (e) {
  41. wx.navigateTo({
  42. url: '/pages/activity/goods_seckill_details/index?id=' + e.currentTarget.dataset.id + '&time=' + this.data.timeList[this.data.active].stop + '&status=' + this.data.status
  43. })
  44. },
  45. settimeList: function (e) {
  46. var that = this;
  47. that.setData({
  48. active: e.currentTarget.dataset.index
  49. });
  50. if (that.data.interval) {
  51. clearInterval(that.data.interval);
  52. that.setData({
  53. interval: null
  54. });
  55. }
  56. that.setData({
  57. interval: 0,
  58. countDownHour: "00",
  59. countDownMinute: "00",
  60. countDownSecond: "00",
  61. status: that.data.timeList[that.data.active].status,
  62. loadend: false,
  63. page: 1,
  64. seckillList: [],
  65. });
  66. // wxh.time(e.currentTarget.dataset.stop, that);
  67. that.getSeckillList();
  68. },
  69. getSeckillConfig: function () {
  70. let that = this;
  71. getSeckillIndexTime().then(res => {
  72. that.setData({
  73. topImage: res.data.lovely,
  74. timeList: res.data.seckillTime,
  75. active: res.data.seckillTimeIndex
  76. });
  77. if (that.data.timeList.length) {
  78. // wxh.time(that.data.timeList[that.data.active].stop, that);
  79. that.setData({
  80. scrollLeft: (that.data.active - 1.37) * 100
  81. });
  82. // setTimeout(function () { that.setData({ loading: true }) }, 2000);
  83. that.setData({
  84. seckillList: [],
  85. page: 1
  86. });
  87. that.setData({
  88. status: that.data.timeList[that.data.active].status
  89. });
  90. that.getSeckillList();
  91. }
  92. });
  93. },
  94. getSeckillList: function () {
  95. var that = this;
  96. var data = {
  97. page: that.data.page,
  98. limit: that.data.limit
  99. };
  100. if (that.data.loading) return;
  101. if (that.data.loadend) return;
  102. that.setData({
  103. loading: true,
  104. loadTitle: '正在搜索'
  105. });
  106. getSeckillList(that.data.timeList[that.data.active].id, data).then(res => {
  107. wx.hideLoading();
  108. var seckillList = res.data;
  109. var loadend = seckillList.length < that.data.limit;
  110. that.data.seckillList = app.SplitArray(seckillList, that.data.seckillList);
  111. that.setData({
  112. seckillList: that.data.seckillList,
  113. loading: false,
  114. loadend: loadend,
  115. page: that.data.page + 1,
  116. loadTitle: loadend ? '已全部加载' : '加载更多',
  117. });
  118. }).catch(err => {
  119. wx.hideLoading();
  120. that.setData({
  121. loading: false,
  122. loadTitle: "加载更多"
  123. });
  124. });
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. if (this.data.interval) {
  141. clearInterval(this.data.interval);
  142. this.setData({
  143. interval: null
  144. });
  145. }
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload: function () {
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh: function () {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom: function () {
  161. this.getSeckillList();
  162. }
  163. })