diff --git a/pages/order_details.vue b/pages/order_details.vue index d82412d..e78b60c 100644 --- a/pages/order_details.vue +++ b/pages/order_details.vue @@ -193,7 +193,7 @@
等待付款
剩余时间 - {{ min }}分钟 {{ sec }}秒自动关闭 + {{ hours }}小时 {{ min }}分钟 {{ sec }}秒自动关闭
@@ -674,8 +674,10 @@ export default { label: "双皮奶", }, ], - min: "", - sec: "", + //倒计时相关 + hours: "",//小时 + min: "",//分钟 + sec: "",//秒 order_create_time: "", logisticsData: {}, contentText: "", @@ -710,8 +712,11 @@ export default { this.tableData.map((item) => { item.buyer_messag = this.orderData.buyer_message; }); - this.order_create_time = res.data.create_time; - this.countdown(); + this.order_create_time = res.data.create_time + res + .data.auto_close; + if(this.orderData.order_status == 0){ + this.countdown2(); + } // -1-已关闭 1-待收货 2-待发货 3-待付款 4-取消订单 5-已完成 if (this.orderData.order_status == -1) { this.orderType = -1; @@ -1005,6 +1010,42 @@ export default { }, 1000); } }, + countdown2() { + // 获取当前时间的时间戳(毫秒) + const now = new Date().getTime(); + // 计算订单自动关闭的时间戳(假设 order_create_time 是秒级时间戳) + const closeTime = this.order_create_time * 1000; + // 计算距离订单自动关闭的总毫秒数 + let distance = closeTime - now; + + // 使用 setInterval 每秒执行一次 + const interval = setInterval(() => { + // 如果剩余时间小于等于0,清除定时器并将时间设置为00:00:00 + if (distance <= 0) { + clearInterval(interval); + this.hours = '00'; + this.min = '00'; + this.sec = '00'; + return; + } + + + // 计算剩余的小时数 + const hours = Math.floor(distance / (1000 * 60 * 60)); + // 计算剩余的分钟数 + const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); + // 计算剩余的秒数 + const seconds = Math.floor((distance % (1000 * 60)) / 1000); + + // 将小时、分钟、秒数格式化为两位数字符串 + this.hours = String(hours).padStart(2, '0'); + this.min = String(minutes).padStart(2, '0'); + this.sec = String(seconds).padStart(2, '0'); + + // 减少一秒 + distance -= 1000; + }, 1000); // 每秒执行一次 + } }, };