// 待支付订单 倒计时
countDown() {
const that = this
//获取时间戳 (毫秒)
const levelTime = new Date(this.orderDetail.createTime.replace(/-/gi, '/')).getTime() + 1800000 - new Date().getTime() //1800000(时间戳是毫秒 * 1000)倒计时三十分钟 60 *30 *1000
let t = parseInt(levelTime / 1000)
timer = setInterval(() => {
if (t > 0) {
const time = that.$tools.format(t)
that.timeText = `支付剩余时间 ${time.m}:${time.s}`
t--
} else {
clearInterval(timer)
that.timeText = '订单已过期!'
}
}, 1000)
},
//工具
format(t) {
const format = {
d: '00',
h: '00',
m: '00',
s: '00'
}
if (t > 0) {
const d = Math.floor(t / 86400)
const h = Math.floor((t / 3600) % 24)
const m = Math.floor((t / 60) % 60)
const s = Math.floor(t % 60)
format.d = d < 10 ? '0' + d : d
format.h = h < 10 ? '0' + h : h
format.m = m < 10 ? '0' + m : m
format.s = s < 10 ? '0' + s : s
}
return format
},
js 倒计时
最新推荐文章于 2024-07-18 10:24:18 发布