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({