From f5c197620cf7d1ff2946973cb79f16b8e58f4729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Tue, 4 Nov 2025 15:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=85=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=89=A9=E4=BD=99=E6=94=AF=E4=BB=98=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E9=83=A8=E5=88=86=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/myOrders/orderDetails/index.vue | 81 ++++++++++++++++++------ 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/packages/myOrders/orderDetails/index.vue b/packages/myOrders/orderDetails/index.vue index 8e3d5343..1c03ec02 100644 --- a/packages/myOrders/orderDetails/index.vue +++ b/packages/myOrders/orderDetails/index.vue @@ -171,31 +171,76 @@ export default { }, onLoad(options) { const item = JSON.parse(options?.item); - // 启动倒计时 - item.order_status == "1" ? this.startCountdown() : ""; - this.status = JSON.stringify(item.order_status); this.orderInfo = item; + // 启动倒计时 + // item.order_status == "1" ? this.startCountdown() : ""; + this.startCountdown() + this.status = JSON.stringify(item.order_status); }, methods: { startCountdown() { - // 倒计时模拟 - let seconds = 10 * 60; // 10分钟 - const timer = setInterval(() => { - seconds--; + // 检查订单信息中是否有时效时间戳 + if (!this.orderInfo.timeout_time_stamp) { + console.error('订单时效时间戳不存在'); + return; + } + + // 获取当前时间和订单超时时间 + const now = Math.floor(new Date().getTime() / 1000); + const timeoutTime = this.orderInfo.timeout_time_stamp; + + // 判断当前时间是否已超过超时时间 + if (now > timeoutTime) { + // 已超过超时时间,直接取消订单 + this.handleOrderCancellation(); + return; + } + + // 计算剩余时间(秒) + let remainingSeconds = timeoutTime - now; + // 确保剩余时间不为负数 + remainingSeconds = Math.max(0, remainingSeconds); + + // 更新倒计时显示的函数 + const updateCountdownDisplay = (seconds) => { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const secs = seconds % 60; - this.countdown = `${hours}:${minutes.toString().padStart(2, "0")}:${secs - .toString() - .padStart(2, "0")}`; - if (seconds <= 0) { + this.countdown = `${hours}:${minutes.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`; + }; + + // 立即更新一次显示 + updateCountdownDisplay(remainingSeconds); + + // 设置定时器,每秒更新一次倒计时 + const timer = setInterval(() => { + remainingSeconds--; + + updateCountdownDisplay(remainingSeconds); + + // 检查是否已经超时 + if (remainingSeconds <= 0) { clearInterval(timer); - // 倒计时结束,处理订单 - uni.showToast({ title: "订单已取消", icon: "none" }); - setTimeout(() => uni.navigateBack(), 1500); + // 倒计时结束,取消订单 + this.handleOrderCancellation(); } }, 1000); }, + + // 处理订单取消 + handleOrderCancellation() { + const params = { + order_id: this.orderInfo.id, + method: 1, + cancel_reason: '倒计时结束取消', + }; + request(afterSaleApi.cancelOrConfirm, "POST", params).then((res) => { + uni.showToast({ title: "订单已取消", icon: "none" }); + setTimeout(() => { + uni.navigateBack(); + }, 1500); + }); + }, cancelOrder() { uni.showModal({ title: "提示", @@ -217,7 +262,7 @@ export default { }, }); }, - + // 申请退款 applyRefund() { uni.showModal({ @@ -238,7 +283,7 @@ export default { } }); }, - + // 确认收货 confirmReceiving() { uni.showModal({ @@ -298,7 +343,7 @@ export default { update_time: this.orderInfo.update_time, user_id: this.orderInfo.user_id })); - + NavgateTo(`/packages/shop/groupPurchaseSubmit/index?shopCarList=${JSON.stringify(transformedItems)}`) }, checkLogistics() { @@ -308,7 +353,7 @@ export default { orderEvaluate() { NavgateTo(`/packages/myOrders/orderEvaluate/index?item=${JSON.stringify(this.orderInfo)}`); }, - + // 售后按钮 afterSale() { NavgateTo(`/packages/myOrders/afterSale/index`);