index.js 3.3 KB

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