index.js 3.5 KB

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