das() {
var today = new Date()
this.today = today
this.today = this.today.getTime()
console.log(this.today, 'this.today ')
console.log(today, 'today')
var tomorrow = new Date(this.time)
console.log(tomorrow, 'tomorrow')
tomorrow.setDate(today.getDate() + 1)
console.log(tomorrow, 'tomorrow2')
this.timestamp = tomorrow.getTime()
console.log(this.timestamp, '时间戳')
this.getOrderDetail()
this.countDown()
},
countDown() {
// 当前时间
let nowTime = this.today
// new Date()
// 获取创建订单15分钟后的时间,this.payForm.create_time:订单创建时间
let endTime = this.timestamp
// new Date(this.payForm.create_time);
// endTime.setMinutes(endTime.getMinutes() + 15) // 结束时间,获取创建订单15分钟后的时间
// 两个日期相差的时间戳,以毫秒为单位(1000ms = 1s)
let totalTime = endTime - nowTime
// 结束时间大于现在的时间
if (totalTime > 0) {
let timer = setInterval(() => {
if (totalTime >= 0) {
//获取天数
let day =
Math.floor((totalTime / 1000 / 3600 / 24)%1);
// parseInt((diff / 1000 / 60 / 60 / 24) % 1)
//获取小时数
let h =
Math.floor((totalTime % (3600 * 24 * 1000)) / 1000 / 3600);
//获取分钟数
let minutes =
Math.floor((((totalTime % (3600 * 24 * 1000)) / 1000) % 3600) / 60);
//获取秒数
let seconds =
Math.floor((((totalTime % (3600 * 24 * 1000)) / 1000) % 3600) % 60).toString()
.padStart(2, "0");;
this.days = day
this.hs = h
this.minutes = minutes
this.seconds = seconds
totalTime -= 1000;
// console.log(totalTime)
} else {
clearInterval(timer); // 停止调用函数
this.isEnd = true
}
}, 1000);
} else {
this.isEnd = true
}
},
getOrderDetail() {
let val = 86400000
// if (res.data.code === 200) {
// this.resData = res.data.data
// let temp = res.data.data
86400000
let payDiff = this.today // status=1 表示待支付 服务器待付款时间差
let deliverDiff = this.timestamp // status=2 表示待收货 服务器待收货时间差 (只会返回其中一种状态)
console.log(payDiff, 'payDiff')
console.log(deliverDiff, 'deliverDiff')
let asd = deliverDiff - payDiff
this.countdown(asd)
// if (payDiff) {
// this.countdown(payDiff)
// } else if (deliverDiff) {
// this.countdown(deliverDiff)
// }
// }
},
// 倒计时
countdown(diff) {
let diffTime = diff // 时间差 s转为ms
this.runBack(diffTime)
},
runBack(diff) {
if (this.mis == '01') {
console.log('删除啦')
}
if (diff > 0) {
let dd = parseInt((diff / 1000 / 60 / 60 / 24) % 1)
let hh = parseInt((diff / 1000 / 60 / 60) % 24)
let mm = parseInt((diff / 1000 / 60) % 60)
let mms = Math.floor((((diff % (3600 * 24 * 1000)) / 1000) % 3600) % 60).toString()
// .padStart(2, "0");;
// (diff % (1000 * 60)) / 1000;
this.day = dd > 9 ? dd : '0' + dd
this.hour = hh > 9 ? hh : '0' + hh
this.minute = mm > 9 ? mm : '0' + mm
this.mis = mms > 9 ? mms : '0' + mms
// 递归的方式使用setTimeOut(),相当于setInterval(),显示动态时间效果
// setTimeOut()方法会返回一个数值ID,便于清除定时器时使用
this.timer = setTimeout(() => {
diff -= 1000
this.runBack(diff)
}, 1000)
} else {
// 订单已过期
this.day = '00'
this.hour = '00'
this.minute = '00'
}
},
注意!!! 仅当笔记使用如有侵权请联系删除
标签:60,console,倒计时,let,支付,diff,today,1000 From: https://www.cnblogs.com/sishe/p/17648379.html