From 729eba5a3b110630f4e3c30641109761b636d27c Mon Sep 17 00:00:00 2001 From: ISFP_T <68358856@qq.com> Date: Wed, 15 Oct 2025 16:03:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=B7=B3=E8=BD=AC=E7=AD=89=E5=BE=85=E5=BC=B9?= =?UTF-8?q?=E5=87=BA=E9=A1=B5=E9=9D=A2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/device/detail.vue | 58 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/pages/device/detail.vue b/pages/device/detail.vue index 92ec4cd..b22d5b9 100644 --- a/pages/device/detail.vue +++ b/pages/device/detail.vue @@ -480,21 +480,73 @@ try { // 调用微信支付分小程序 const payResult = await initiateWeChatScorePayment(res); + console.log('支付分调用结果', payResult); // 成功则跳转等待页,轮询在等待页处理 - if (payResult.errCode == '0') { + if (payResult.errCode == '0' && payResult.extraData && Object.keys(payResult.extraData).length > 0) { console.log('支付分授权成功,准备跳转,时间:', new Date().toLocaleTimeString()); // 直接跳转(订阅消息已经在前面完成了) uni.redirectTo({ url: `/pages/waiting/index?orderNo=${order.orderNo}&deviceId=${deviceId.value}` }); return; + } else { + console.log('支付分未完成授权或用户取消,extraData:', payResult.extraData); + // 用户取消授权,需要取消订单 + try { + uni.showLoading({ + title: '取消订单中' + }); + const cancelRes = await cancelOrder({ orderId: order.orderNo }); + console.log('订单取消结果:', cancelRes); + uni.hideLoading(); + + uni.showToast({ + title: '已取消订单', + icon: 'none', + duration: 2000 + }); + + // 延迟返回首页 + setTimeout(() => { + uni.switchTab({ + url: '/pages/index/index' + }); + }, 2000); + } catch (cancelError) { + console.error('取消订单失败:', cancelError); + uni.hideLoading(); + uni.showToast({ + title: '取消订单失败,请联系客服', + icon: 'none' + }); + } + return; } - // 用户取消等其他情况,不做特殊处理 } catch (payError) { + console.error('支付分调用异常:', payError); + // 支付分调用异常,也需要取消订单 + try { + uni.showLoading({ + title: '取消订单中' + }); + const cancelRes = await cancelOrder({ orderId: order.orderNo }); + console.log('订单取消结果:', cancelRes); + uni.hideLoading(); + } catch (cancelError) { + console.error('取消订单失败:', cancelError); + uni.hideLoading(); + } + uni.showToast({ - title: '支付分调用失败,请重试', + title: '支付分调用失败,订单已取消', icon: 'none' }); + + setTimeout(() => { + uni.switchTab({ + url: '/pages/index/index' + }); + }, 2000); } } else { uni.showToast({