list.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. mixins: [require('../../mixin/globalMixin.js')],
  6. data: {
  7. currentTab: 0,
  8. scekillTimeList: [],
  9. endTime: 10000,
  10. list: [],
  11. clearTimer: false
  12. },
  13. secTime: '',
  14. seckill_share_title: '',
  15. seckill_share_image: '',
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. status.setNavBgColor();
  21. app.setShareConfig();
  22. this.secTime = options.time || '';
  23. },
  24. /**
  25. * 生命周期函数--监听页面显示
  26. */
  27. onShow: function () {
  28. let that = this;
  29. util.check_login_new().then((res) => {
  30. that.setData({needAuth: !res})
  31. res && (0, status.cartNum)('', true).then((resp) => {
  32. resp.code == 0 && that.setData({
  33. cartNum: resp.data
  34. })
  35. });
  36. })
  37. this.loadPage();
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. this.setData({ clearTimer: false })
  44. },
  45. loadPage: function(){
  46. this.getInfo();
  47. },
  48. /**
  49. * 授权成功回调
  50. */
  51. authSuccess: function () {
  52. const that = this;
  53. this.setData({
  54. showEmpty: false,
  55. needAuth: false,
  56. showAuthModal: false
  57. }, () => {
  58. that.loadPage()
  59. })
  60. },
  61. authModal: function () {
  62. if (this.data.needAuth) {
  63. this.setData({
  64. showAuthModal: !this.data.showAuthModal
  65. });
  66. return false;
  67. }
  68. return true;
  69. },
  70. getInfo: function(){
  71. let that = this;
  72. app.util.request({
  73. url: 'entry/wxapp/index',
  74. data: {
  75. controller: 'scekill.get_scekill_info'
  76. },
  77. dataType: 'json',
  78. success: function (res) {
  79. if(res.data.code==0){
  80. let {
  81. seckill_is_open,
  82. scekill_time_arr,
  83. seckill_page_title,
  84. seckill_bg_color,
  85. seckill_share_title,
  86. seckill_share_image,
  87. showTabbar
  88. } = res.data.data;
  89. wx.setNavigationBarTitle({
  90. title: seckill_page_title || '整点秒杀'
  91. })
  92. let myDate = new Date();
  93. let curHour = myDate.getHours(); // 当前时间
  94. console.log('当前时间:', curHour);
  95. let curSeckillIdx = 0; //当前时间索引
  96. let scekillTimeArr = scekill_time_arr || []; //显示的时间段
  97. // if (scekill_time_arr.length > 5) {}
  98. //判断各个时段状态
  99. let scekillTimeList = [];
  100. let currentTab = 0;
  101. if (scekillTimeArr.length) {
  102. scekillTimeArr.forEach((item, idx) => {
  103. let secObj = {};
  104. //state: 0已开抢 1疯抢中 2即将开抢
  105. if (item == curHour) {
  106. secObj.state = 1;
  107. secObj.desc = '疯抢中';
  108. currentTab = idx;
  109. } else if (item < curHour) {
  110. secObj.state = 0;
  111. secObj.desc = '已开抢';
  112. } else {
  113. secObj.state = 2;
  114. secObj.desc = '即将开抢';
  115. }
  116. secObj.timeStr = (item < 10 ? '0' + item : item) + ':00';
  117. secObj.seckillTime = item;
  118. scekillTimeList.push(secObj);
  119. })
  120. if (that.secTime!='') {
  121. let k = scekillTimeArr.findIndex((n) => n == that.secTime);
  122. if (k > 0) currentTab = k;
  123. }
  124. that.getSecKillGoods(scekillTimeArr[currentTab]);
  125. }
  126. let curTimeStr = (scekillTimeArr[currentTab]*1 + 1);
  127. if (that.secTime!='' && curHour!=scekillTimeArr[currentTab]) {
  128. curTimeStr = (scekillTimeArr[currentTab]*1);
  129. }
  130. let endTime = new Date(new Date().toLocaleDateString()).getTime() + curTimeStr*60*60*1000;
  131. that.seckill_share_title = seckill_share_title;
  132. that.seckill_share_image = seckill_share_image;
  133. that.setData({ scekillTimeList, seckill_bg_color, currentTab, endTime, showTabbar })
  134. }
  135. }
  136. })
  137. },
  138. handleClick(e) {
  139. let that = this;
  140. let currentTab = e.currentTarget.dataset.index;
  141. let scekillTimeList = this.data.scekillTimeList;
  142. let day = new Date(new Date().toLocaleDateString()).getTime();
  143. let curTimeItem = scekillTimeList[currentTab];
  144. let endTime = 0;
  145. if (curTimeItem.state == 1) {
  146. endTime = day + (curTimeItem.seckillTime * 1 + 1) * 60 * 60 * 1000;
  147. } else {
  148. if (curTimeItem.state == 2) {
  149. endTime = day + (curTimeItem.seckillTime * 1) * 60 * 60 * 1000 + 1;
  150. }
  151. }
  152. this.setData({
  153. list: [],
  154. currentTab,
  155. endTime,
  156. clearTimer: true
  157. }, ()=>{
  158. that.getSecKillGoods(curTimeItem.seckillTime);
  159. })
  160. },
  161. getSecKillGoods: function (seckill_time) {
  162. wx.showLoading();
  163. var that = this;
  164. var cur_community = wx.getStorageSync('community');
  165. var token = wx.getStorageSync('token');
  166. app.util.request({
  167. url: 'entry/wxapp/index',
  168. data: {
  169. controller: 'index.load_gps_goodslist',
  170. token: token,
  171. pageNum: 1,
  172. head_id: cur_community.communityId,
  173. seckill_time,
  174. is_seckill: 1,
  175. per_page: 10000
  176. },
  177. dataType: 'json',
  178. success: function (res) {
  179. wx.stopPullDownRefresh();
  180. wx.hideLoading();
  181. if (res.data.code == 0) {
  182. let list = res.data.list || [];
  183. list = that.transTime(list);
  184. let showEmpty = false;
  185. if (list.length == 0) showEmpty = true;
  186. that.setData({ list, clearTimer: false, showEmpty })
  187. } else {
  188. that.setData({ clearTimer: false, showEmpty: true })
  189. }
  190. }
  191. })
  192. },
  193. /**
  194. * 结束时间判断
  195. */
  196. transTime: function (list) {
  197. let that = this;
  198. let e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0;
  199. e === 0 && list.map(function (t) {
  200. t.end_time *= 1000;
  201. t.actEnd = t.end_time <= new Date().getTime();
  202. })
  203. return list;
  204. },
  205. endCurSeckill: function(){
  206. this.loadPage();
  207. },
  208. /**
  209. * 页面相关事件处理函数--监听用户下拉动作
  210. */
  211. onPullDownRefresh: function () {
  212. this.loadPage();
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage: function () {
  218. var member_id = wx.getStorageSync('member_id');
  219. let {
  220. seckill_share_title,
  221. seckill_share_image
  222. } = this;
  223. return {
  224. title: seckill_share_title,
  225. path: "lionfish_comshop/moduleA/seckill/list?share_id=" + member_id,
  226. imageUrl: seckill_share_image,
  227. success: function () { },
  228. fail: function () { }
  229. };
  230. },
  231. onShareTimeline: function() {
  232. var member_id = wx.getStorageSync('member_id');
  233. let {
  234. seckill_share_title,
  235. seckill_share_image
  236. } = this;
  237. var query= `share_id=${member_id}`;
  238. return {
  239. title: seckill_share_title,
  240. imageUrl: seckill_share_image,
  241. query,
  242. success: function() {},
  243. fail: function() {}
  244. };
  245. }
  246. })