Browse Source

不需要同步-修改倒计时问题

master
liutong 2 years ago
parent
commit
4dd01949e7
  1. 51
      pages/order_details.vue

51
pages/order_details.vue

@ -193,7 +193,7 @@
<div class="l">等待付款</div> <div class="l">等待付款</div>
<div class="r qx"> <div class="r qx">
剩余时间 剩余时间
<span class="red">{{ min }}分钟 {{ sec }}秒</span>自动关闭 <span class="red">{{ hours }}小时 {{ min }}分钟 {{ sec }}秒</span>自动关闭
</div> </div>
</div> </div>
@ -674,8 +674,10 @@ export default {
label: "双皮奶", label: "双皮奶",
}, },
], ],
min: "", //倒计时相关
sec: "", hours: "",//小时
min: "",//分钟
sec: "",//秒
order_create_time: "", order_create_time: "",
logisticsData: {}, logisticsData: {},
contentText: "", contentText: "",
@ -710,8 +712,11 @@ export default {
this.tableData.map((item) => { this.tableData.map((item) => {
item.buyer_messag = this.orderData.buyer_message; item.buyer_messag = this.orderData.buyer_message;
}); });
this.order_create_time = res.data.create_time; this.order_create_time = res.data.create_time + res
this.countdown(); .data.auto_close;
if(this.orderData.order_status == 0){
this.countdown2();
}
// -1-已关闭 1-待收货 2-待发货 3-待付款 4-取消订单 5-已完成 // -1-已关闭 1-待收货 2-待发货 3-待付款 4-取消订单 5-已完成
if (this.orderData.order_status == -1) { if (this.orderData.order_status == -1) {
this.orderType = -1; this.orderType = -1;
@ -1005,6 +1010,42 @@ export default {
}, 1000); }, 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); // 每秒执行一次
}
}, },
}; };
</script> </script>

Loading…
Cancel
Save