index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import wxh from '../../../utils/wxh.js';
  2. import { getSeckillIndexTime, getSeckillList } from '../../../api/activity.js';
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. topImage:'',
  10. parameter: {
  11. 'navbar': '1',
  12. 'return': '1',
  13. 'title': '限时秒杀',
  14. 'color': true,
  15. 'class': '0'
  16. },
  17. seckillList:[],
  18. timeList:[],
  19. active:5,
  20. scrollLeft:0,
  21. interval:0,
  22. status:1,
  23. countDownHour: "00",
  24. countDownMinute: "00",
  25. countDownSecond: "00",
  26. page : 1,
  27. limit : 20,
  28. loading:false,
  29. loadend: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.loading) return;
  80. if(that.data.loadend) return;
  81. that.setData({loading:true,loadTitle:'正在搜索'});
  82. getSeckillList(that.data.timeList[that.data.active].id, data).then(res=>{
  83. wx.hideLoading();
  84. var seckillList = res.data;
  85. var loadend = seckillList.length < that.data.limit;
  86. that.data.seckillList = app.SplitArray(seckillList, that.data.seckillList);
  87. that.setData({
  88. seckillList: that.data.seckillList,
  89. loading: false,
  90. loadend: loadend,
  91. page: that.data.page + 1,
  92. loadTitle: loadend ? '已全部加载' : '加载更多',
  93. });
  94. }).catch(err=>{
  95. wx.hideLoading();
  96. that.setData({ loading: false, loadTitle: "加载更多" });
  97. });
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. if(this.data.interval){
  114. clearInterval(this.data.interval);
  115. this.setData({ interval: null });
  116. }
  117. },
  118. /**
  119. * 生命周期函数--监听页面卸载
  120. */
  121. onUnload: function () {
  122. },
  123. /**
  124. * 页面相关事件处理函数--监听用户下拉动作
  125. */
  126. onPullDownRefresh: function () {
  127. },
  128. /**
  129. * 页面上拉触底事件的处理函数
  130. */
  131. onReachBottom: function () {
  132. this.getSeckillList();
  133. }
  134. })