123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- // subPackagesF/pages/seckillActivity/seckillActivity.js
- import {
- get,
- } from '../../../utils/http'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- store_id: '',
- startTime: '', //开始时间
- time: 60 * 60 * 1000, //秒杀开始时间
- timeData: {}, //秒杀倒计时
- activeClass: '', //动态类名是否超出时间或者没到时间
- seckillList: [], //秒杀列表
- end: false, //时间结束
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.setData({
- store_id: wx.getStorageSync('store_id')
- })
- // 获取秒杀列表
- this.seckillList()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- // 获取秒杀列表
- seckillList() {
- get('v2/api/spike/list', {
- store_id: this.data.store_id || wx.getStorageSync('store_id')
- }, (res => {
- if (res.code == 200) {
- // res.data.end_time= "01-10 16:45"
- res.data.start_time = (new Date()).getFullYear() + '-' + res.data.start_time
- res.data.end_time = (new Date()).getFullYear() + '-' + res.data.end_time
- let startDate = res.data.start_time.replace(new RegExp("-", "gm"), "/");
- let endDate = res.data.end_time.replace(new RegExp("-", "gm"), "/");
- let startDateM = (new Date(startDate)).getTime(); //开始时间毫秒数
- let endDateM = (new Date(endDate)).getTime(); //结束时间毫秒数
- let nowTime = Date.now(); //当前时间毫秒数
- let time = Number(startDateM) - Number(nowTime) //大于0活动未开始
- // 如果当前时间比结束时间大(活动结束)
- if (nowTime > endDateM) {
- this.setData({
- activeClass: 'activeClass',
- end: true
- })
- time = 0
- } else {
- // 否则就判断时间是否开始
- if (Number(time) > 0) {
- this.setData({
- activeClass: 'activeClass'
- })
- } else {
- this.setData({
- activeClass: ''
- })
- time = 0
- }
- }
- this.setData({
- seckillList: res.data,
- startTime: res.data.start_time,
- time
- })
- }
- }))
- },
- // 倒计时改变
- onChange(e) {
- let time = e.detail
- if (time.days > 0) {
- e.detail.hours = Number(time.days) * 24 + Number(time.hours)
- }
- time.hours1 = 0
- time.minutes1 = 0
- time.seconds1 = 0
- if (time.seconds >= 10) {
- time.seconds1 = time.seconds.toString().charAt(0)
- time.seconds = time.seconds.toString().charAt(1)
- }
- if (time.hours >= 10) {
- if (time.hours >= 100) {
- time.hours2 = time.hours.toString().charAt(2)
- }
- time.hours1 = time.hours.toString().charAt(0)
- time.hours = time.hours.toString().charAt(1)
- }
- if (time.minutes >= 10) {
- time.minutes1 = time.minutes.toString().charAt(0)
- time.minutes = time.minutes.toString().charAt(1)
- }
- this.setData({
- timeData: time,
- });
- },
- // 倒计时结束
- finishTime() {
- // 活动时间结束不触发
- if (!this.data.end) {
- this.setData({
- activeClass: '',
- })
- }
- if(this.data.activeClass==''){
- let endDate = this.data.seckillList.end_time.replace(new RegExp("-", "gm"), "/");
- let endDateM = (new Date(endDate)).getTime(); //结束时间毫秒数
- let nowTime = Date.now(); //当前时间毫秒数
- let time = endDateM-nowTime
- if(time>0){
- this.setData({
- time
- })
- }else{
- this.setData({
- time:0,
- end:true,
- activeClass: 'activeClass',
- })
- }
- }
- },
- // 跳转到秒杀详情
- goSeckillDetail(e) {
- console.log(e);
- let id = e.currentTarget.dataset.id
- let num = e.currentTarget.dataset.num
- let seckillId = e.currentTarget.dataset.seckillid
- if (num <= 0) {
- wx.showToast({
- title: '抱歉,没有库存了',
- icon: 'none'
- })
- return
- }
- wx.navigateTo({
- url: `/subPackagesF/pages/seckillDetail/seckillDetail?goods_id=${id}&seckill_id=${seckillId}`,
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|