seckill.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <!--product/seckill/seckill.wxml-->
  3. <view class="seckill">
  4. <view class="top">
  5. <image :src="picUrlss+'seckillbg.png'" class="background"></image>
  6. <view class=" tab">
  7. <image src="/activity/static/activity/images/seckill.png" class="logo"></image>
  8. <view class="times dflex">
  9. <view v-for="(item, index) in TabList" :key="index"
  10. :class="'li ' + (item.active ? 'active' : '') + ' left'" :data-index="index" @tap="switchTab">
  11. <text :class="item.active ? 'weight' : ''">{{item.label}}</text>
  12. <view :class="'state ' + (item.active? 'bg' :'')">{{item.state}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="conunt" v-if="activityGroup.length > 0">
  18. <view v-for="(item, index) in activityGroup" :key="index" class="li" :data-index="index">
  19. <image :src="item.pic + '?x-oss-process=style/w210'" lazy-load="true" mode="aspectFit" class="proimg"
  20. :data-index="index" @tap="toGroupRemind"></image>
  21. <view class="flex">
  22. <view class="proname" :data-index="index" @tap="toGroupRemind">
  23. {{item.productName}}
  24. </view>
  25. <view class="progress-box" v-if="item.payQuantity&&item.start">
  26. <progress stroke-width="8" color="red" :percent="item.num" border-radius="25rpx"
  27. backgroundColor="#FFB2B8" class="progress"
  28. v-if="item.payQuantity"></progress><text>已抢{{item.payQuantity}}</text>
  29. </view>
  30. <view class="progress-box" v-if="item.makePerson&&!item.start">
  31. <progress stroke-width="8" color="red" :percent="item.makePerson" border-radius="25rpx"
  32. backgroundColor="#FFB2B8" class="progress"
  33. v-if="item.makePerson"></progress><text>已{{item.makePerson}}人预约</text>
  34. </view>
  35. <view class="endtime " :data-index="index" @tap="toGroupRemind" v-if="item.start"><text
  36. class="black">{{item.start ? '距结束' : '距开始'}}</text><text class="red">{{item.times}}</text>
  37. </view>
  38. <view class="endtime" :data-index="index" @tap="toGroupRemind" v-else>
  39. <text class="date">{{item.date}}</text>
  40. <text class="hour">{{item.hour}}</text>
  41. <text class="date">开始</text>
  42. </view>
  43. <view :class="'operate dflex ' + (item.payQuantity?'noyuyue':'yuyue')" v-if="item.start">
  44. <view class="price proprice" :data-index="index" @tap="toGroupRemind">¥<text
  45. class="pce">{{item.money}}</text><text class="del"
  46. v-if="item.marketPrice!=0&&item.money<item.marketPrice">¥{{item.marketPrice}}</text>
  47. </view>
  48. <view class="add-cart" :data-index="index" @tap="toGroupRemind">
  49. 立即抢购
  50. </view>
  51. </view>
  52. <view :class="'operate dflex ' + (item.makePerson?'noyuyue':'yuyue')" v-else>
  53. <view class="price proprice" :data-index="index" @tap="toGroupRemind">¥<text
  54. class="pce">{{item.money}}</text><text class="del">¥{{item.marketPrice}}</text></view>
  55. <view :class="(item.isRemind?'add-cart1':'add-cart') + ' car'">
  56. <image src="/activity/static/activity/images/clock2.png" v-if="!item.isRemind"></image>
  57. <view class="order or" @tap="cancelActivityRemind" :data-index="index" :data-id="item.id"
  58. v-if="item.isRemind">取消预约</view>
  59. <view class="order" @tap="addActivityRemind" :data-index="index" :data-id="item.id" v-else>
  60. 预约</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="nodata" v-if="ishow">
  67. <image :src="picUrlss+'empty_sp.png'"></image>
  68. <text>暂无商品</text>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. // product/seckill/seckill.js
  74. const app = getApp();
  75. const req = require("../../utils/request.js");
  76. const utils = require("../../utils/util.js");
  77. const requsetmessage = require("../../utils/requestmessage.js");
  78. export default {
  79. data() {
  80. return {
  81. picUrlss: req.public.picUrls,
  82. TabList: [{
  83. label: '今天',
  84. active: true,
  85. state: "抢购中",
  86. dayType: 1,
  87. time: ''
  88. }, {
  89. label: '明天',
  90. state: "预热中",
  91. active: false,
  92. time: '',
  93. dayType: 2
  94. }, {
  95. label: '后天',
  96. state: "预热中",
  97. dayType: 3,
  98. time: ''
  99. }, {
  100. label: '',
  101. state: "预热中",
  102. dayType: 4,
  103. active: false,
  104. time: ''
  105. }, {
  106. label: '',
  107. state: "预热中",
  108. dayType: 5,
  109. active: false,
  110. time: ''
  111. }],
  112. form: {
  113. page: 1,
  114. limit: 10,
  115. type: 2,
  116. dayType: 1
  117. },
  118. isRemind: false,
  119. page: 1,
  120. isLoad: true,
  121. dayType: '',
  122. activityGroup: [],
  123. ishow: false,
  124. activityGroupAll: "",
  125. hasmore: ""
  126. };
  127. },
  128. components: {},
  129. props: {},
  130. /**
  131. * 生命周期函数--监听页面加载
  132. */
  133. onLoad: function(options) {
  134. // this.loadGroupAll();
  135. this.query = options;
  136. // this.getTime();//给tab添加动态时间
  137. this.initTab();//初始化tab时间
  138. this.loadGroupAll(); // this.setData({TabList[3].label:})
  139. // this.laterDay(4)[2]
  140. },
  141. onReady: function() {},
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function() {
  146. // this.isLoad = true;
  147. this.form.page = 1; // this.setData({activityGroup:[]})
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function() { // this.clearAllTimer();
  153. // let def = this.data.TabList.findIndex(it => it.active);
  154. // let d={}
  155. // d[`TabList[${def}].active`] = false;
  156. // this.setData(d);
  157. },
  158. /**
  159. * 生命周期函数--监听页面卸载
  160. */
  161. onUnload: function() { // this.clearAllTimer();
  162. },
  163. /**
  164. * 页面相关事件处理函数--监听用户下拉动作
  165. */
  166. onPullDownRefresh: function() {},
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function() {
  171. // this.setData({})
  172. this.form.page++;
  173. this.loadGroupAll(1); // this.clearAllTimer();
  174. // console.log(this.form.page)
  175. },
  176. methods: {
  177. fun_data(aa){
  178. var date1 = new Date(),
  179. time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间
  180. var date2 = new Date(date1);
  181. date2.setDate(date1.getDate()+aa);
  182. // var time2 = date2.getFullYear()+"-"+(date2.getMonth()+1)+"-"+date2.getDate();
  183. var time2 = (date2.getMonth()+1)+"月"+date2.getDate() + "日";
  184. return time2;
  185. },
  186. // 初始化tab导航
  187. initTab(){
  188. let tabList = this.TabList;
  189. tabList[3].label = this.fun_data(4);
  190. tabList[4].label = this.fun_data(5);
  191. },
  192. /**
  193. *
  194. * 设置tab导航
  195. */
  196. switchTab(event) {
  197. let index = event.currentTarget.dataset.index;
  198. let def = this.TabList.findIndex(it => it.active);
  199. let d = {};
  200. // console.log(index, def);
  201. d[`TabList[${def}].active`] = false;
  202. d[`TabList[${index}].active`] = true;
  203. // console.log(d);
  204. this.isLoad = true;
  205. this.form.page = 1;
  206. d['pageList'] = [];
  207. this.form.dayType = this.TabList[index].dayType;
  208. this.setData(d);
  209. this.loadGroupAll(1);
  210. this.clearAllTimer(); // this.getDate()
  211. },
  212. /**
  213. * 获取所有产品列表
  214. */
  215. loadGroupAll(type) {
  216. // console.log(this.isLoad)
  217. let isShowLoading = false;
  218. if (this.form.page == 1 && !isShowLoading) {
  219. req.loadIng('加载中');
  220. isShowLoading = true;
  221. }
  222. if (!this.isLoad) return false;
  223. this.isLoad = false;
  224. let _ts = this;
  225. let from = this.form
  226. if (this.query.merchantId) {
  227. from.merchantId = this.query.merchantId;
  228. } else if (req.getStorage('MERCHANT')) {
  229. from.merchantId = req.getStorage('MERCHANT').id;
  230. }
  231. req.getRequest('/api/activity/list', from, res => {
  232. if (res && res.length == 10) _ts.isLoad = true;
  233. if (from.page > 1) res = _ts.activityGroup.concat(res);
  234. let data = res;
  235. // var data = res.map(it => {
  236. // var allTime = this.getDate(it.startTime);
  237. // it.isRemind = it.remindId, it.num = it.sellStock / it.quantity * 100, it.date =
  238. // allTime.date, it.hour =
  239. // allTime.date1, it.year = new Date(allTime.date2).getTime();
  240. // return it;
  241. // });
  242. // console.log(data, _ts.isLoad);
  243. console.log(data.length)
  244. if (data.length <= 0) {
  245. _ts.ishow = true;
  246. // return false;
  247. }else{
  248. _ts.ishow = false;
  249. }
  250. console.log(isShowLoading)
  251. this.activityGroup = data;
  252. // if (type == 1) {
  253. // _ts.setData({
  254. // activityGroup: data,
  255. // hasmore: res && res.length > 0
  256. // });
  257. // } else {
  258. // data.sort(function(a, b) {
  259. // return Date.parse(a.startTime) - Date.parse(b.startTime);
  260. // });
  261. // /**
  262. // * 商品日期排序
  263. // */
  264. // var arr = [];
  265. // var allTime = {}
  266. // for (var i = 0; i < data.length; i++) {
  267. // if (data[i].end != true && data[i].start == true) {
  268. // allTime = this.getDate(data[i].nowTime);
  269. // } else {
  270. // allTime = this.getDate(data[i].startTime);
  271. // }
  272. // arr.push(allTime.date2);
  273. // }
  274. // /**
  275. // * 数组去重
  276. // */
  277. // let temp = [...new Set(arr)];
  278. // /**
  279. // * 判断日期
  280. // */
  281. // let tabList = [];
  282. // let list = this.TabList;
  283. // // console.log(list, tabList);
  284. // for (let i = 0; i < list.length; i++) {
  285. // tabList.push(list[i].time);
  286. // }
  287. // /**
  288. // * 拿到日期,把空白填补
  289. // */
  290. // temp.forEach(item1 => {
  291. // tabList.forEach((item2, j) => {
  292. // // console.log(item2,item1)
  293. // if (item2 == item1) {
  294. // tabList.splice(j, 1);
  295. // if (tabList.length < 6) {
  296. // tabList.splice(j, 0, 1);
  297. // }
  298. // j -= 1;
  299. // }
  300. // });
  301. // });
  302. // /**
  303. // * 删除没有产品的导航栏
  304. // */
  305. // let newlist = [];
  306. // for (let i = 0; i < list.length; i++) {
  307. // if (tabList[i] == 1) {
  308. // newlist.push(list[i]);
  309. // }
  310. // }
  311. // // console.log(newlist, list, tabList);
  312. // if (newlist.length != 0) {
  313. // // console.log(this.isLoad, "++++++++++++++++++++++++++", newlist[0]);
  314. // // if (!this.isLoad) return false;
  315. // // this.isLoad = false;
  316. // newlist[0]['active'] = true;
  317. // this.setData({
  318. // TabList: newlist
  319. // });
  320. // var all = new Date().getTime()
  321. // if (newlist[0].dayType == 1) {
  322. // _ts.setData({
  323. // activityGroup: data.filter(it => it.year <= all)
  324. // });
  325. // } else {
  326. // _ts.setData({
  327. // activityGroup: data.filter(it => it.date == newlist[0].times)
  328. // });
  329. // }
  330. // // console.log(data, all)
  331. // }
  332. // }
  333. if (isShowLoading) {
  334. uni.hideLoading();
  335. isShowLoading = false;
  336. }
  337. _ts.clearAllTimer();
  338. _ts.initGroupTimer();
  339. });
  340. },
  341. /**
  342. *
  343. *
  344. * 点击li获取商品详情
  345. */
  346. toGroupRemind(event) {
  347. const index = event.currentTarget.dataset.index; // console.log(event)
  348. const activity = this.activityGroup[index];
  349. let merchantId;
  350. if (this.query.merchantId) {
  351. merchantId = this.query.merchantId;
  352. } else if (req.getStorage('MERCHANT')) {
  353. merchantId = req.getStorage('MERCHANT').id;
  354. }
  355. let url = 'activity/seckillDetails/seckillDetails?acid=' + activity.id + "&id=" + activity.productId
  356. if (!merchantId) {
  357. } else {
  358. url += "&merchantId=" + merchantId
  359. }
  360. app.globalData.openPage(url); // console.log('acid', activity.id)
  361. // console.log('productId', activity.productId)
  362. },
  363. /**
  364. * 生命周期函数--监听页面初次渲染完成
  365. */
  366. initGroupTimer() {
  367. //社区拼图定时器
  368. let _ts = this;
  369. if (this.activityGroup && this.activityGroup.length > 0) {
  370. let activityGroup = this.activityGroup;
  371. for (let i = 0, len = activityGroup.length; i < len; i++) {
  372. let group = activityGroup[i];
  373. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  374. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  375. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  376. if (!group.start) endTime = startTime;
  377. let times = parseInt((endTime - nowTime) / 1000);
  378. let timer = setInterval(() => {
  379. times--;
  380. let data = {};
  381. if (times === 0) {
  382. //重新加载列表
  383. data['activityGroup[' + i + '].end'] = true;
  384. clearInterval(timer);
  385. } else {
  386. let n = utils.formatDayTimes(times);
  387. data['activityGroup[' + i + '].times'] = n;
  388. }
  389. _ts.setData(data); // console.log(data)
  390. }, 1000);
  391. this.activityGroup[i]['timer'] = timer; // let fs = [];
  392. // fs['activityGroup[' + i + '].timer'] = timer;
  393. // _ts.setData(fs);
  394. }
  395. }
  396. },
  397. clearAllTimer() {
  398. this.activityGroup.forEach(it => clearInterval(it.timer));
  399. },
  400. /**
  401. *
  402. * 产品活动开始时间转换 year-month-day hour:minute:00
  403. *
  404. */
  405. getDate(str) {
  406. var strArr = str.split(' ');
  407. var time = strArr[0].toString().split('-');
  408. var hose = strArr[1].toString().split(':');
  409. var hour = hose[0];
  410. var minute = hose[1];
  411. var day = time[2];
  412. var month = time[1];
  413. var year = time[0];
  414. var date = (month + '月' + day + '日').toString();
  415. var date1 = (hour + ':' + minute).toString();
  416. var date2 = strArr[0];
  417. var allTime = {
  418. date: (month + '月' + day + '日').toString(),
  419. date1: (hour + ':' + minute).toString(),
  420. date2: strArr[0]
  421. }
  422. return allTime
  423. },
  424. /**
  425. * 时间转换
  426. */
  427. getda(str) {
  428. var strArr = str.split('-');
  429. var day = strArr[2];
  430. var month = strArr[1];
  431. var year = strArr[0];
  432. var date = (month + '月' + day + '日').toString();
  433. return date;
  434. },
  435. /**
  436. * 活动产品预约
  437. */
  438. addActivityRemind(event) {
  439. const index = event.currentTarget.dataset.index;
  440. const id = event.currentTarget.dataset.id; // 订阅调用
  441. req.postRequest('/api/activity/remind', {
  442. activityId: id
  443. }, res => {
  444. requsetmessage.remind(res => {
  445. // console.log(res, "11111111111");
  446. });
  447. req.msg('预约成功');
  448. let data = {};
  449. data['activityGroup[' + index + '].isRemind'] = true;
  450. this.setData(data);
  451. });
  452. },
  453. cancelActivityRemind(event) {
  454. const index = event.currentTarget.dataset.index;
  455. const id = event.currentTarget.dataset.id;
  456. if (req.header.appId == 'ZQ1VK5oc17I387E') {
  457. } else {
  458. req.postRequest('/api/activity/cancel/remind', {
  459. id: id
  460. }, res => {
  461. req.msg('取消预约成功');
  462. let data = {};
  463. data['activityGroup[' + index + '].isRemind'] = false;
  464. this.setData(data);
  465. });
  466. }
  467. },
  468. /**
  469. * 获取当前时间往后退四天
  470. */
  471. laterDay(num) {
  472. var t = new Date();
  473. var iToDay = t.getDate();
  474. var iToMon = t.getMonth();
  475. var iToYear = t.getFullYear();
  476. var arr = [];
  477. var day = []
  478. for (var i = 1; i < num + 1; i++) {
  479. var newDate = new Date(iToYear, iToMon, iToDay + i);
  480. arr.push(newDate.getFullYear() + '-' + (newDate.getMonth() + 1).toString().padStart(2, '0') + "-" +
  481. newDate.getDate()
  482. .toString().padStart(2, '0'));
  483. day.push((newDate.getMonth() + 1).toString().padStart(2, '0') + "月" + newDate.getDate()
  484. .toString().padStart(2, '0') + "日"
  485. )
  486. } // console.log(arr)
  487. var obj={
  488. arr:arr,
  489. day:day
  490. }
  491. return obj;
  492. },
  493. /**
  494. * 给tab添加动态时间
  495. */
  496. getTime() {
  497. const data = this.TabList;
  498. var t = new Date();
  499. var iToDay = t.getDate().toString().padStart(2, '0');
  500. var iToMon = (t.getMonth() + 1).toString().padStart(2, '0');
  501. var iToYear = t.getFullYear();
  502. const rq = (iToYear + '-' + iToMon + '-' + iToDay).toString();
  503. const rq5 = (iToMon + '月' + iToDay + '日').toString()
  504. const rq1 = this.laterDay(4).arr[0];
  505. const rq6 =this.laterDay(4).day[0]
  506. const rq2 = this.laterDay(4).arr[1];
  507. const rq7 =this.laterDay(4).day[1]
  508. const rq3 = this.laterDay(4).arr[2];
  509. const rq8 =this.laterDay(4).day[2]
  510. const rq4 = this.laterDay(4).arr[3]; // console.log("rq" + "---", rq1, rq2, rq3, rq4)
  511. const rq9 =this.laterDay(4).day[3]
  512. data[0].time = rq;
  513. data[0].times = rq5;
  514. data[1].time = rq1;
  515. data[1].times = rq6;
  516. data[2].time = rq2;
  517. data[2].times = rq7;
  518. data[3].label = this.getda(rq3);
  519. data[3].time = rq3;
  520. data[3].times = rq8;
  521. data[4].label = this.getda(rq4);
  522. data[4].time = rq4;
  523. data[4].times = rq9;
  524. this.setData({
  525. TabList: data
  526. }); // console.log(this.data.TabList)
  527. },
  528. }
  529. };
  530. </script>
  531. <style>
  532. @import "./seckill.css";
  533. </style>