From 500c44ebea42cccc1abb8b1ed739e33512b4acd0 Mon Sep 17 00:00:00 2001 From: duanshuwen Date: Tue, 7 Oct 2025 16:31:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=85=E6=94=AF=E4=BB=98|=E5=86=8D?= =?UTF-8?q?=E6=AC=A1=E9=A2=84=E5=AE=9A=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/components/OrderInfo/index.vue | 122 ++++++++++++------ .../components/OrderInfo/styles/index.scss | 25 ---- src/pages-order/order/detail.vue | 19 ++- src/pages/goods/index.vue | 13 ++ src/request/api/OrderApi.js | 12 +- 5 files changed, 117 insertions(+), 74 deletions(-) diff --git a/src/pages-order/order/components/OrderInfo/index.vue b/src/pages-order/order/components/OrderInfo/index.vue index 6841222..26160a5 100644 --- a/src/pages-order/order/components/OrderInfo/index.vue +++ b/src/pages-order/order/components/OrderInfo/index.vue @@ -27,7 +27,7 @@ v-if="shouldShowButton" :class="['reserve-button', { loading: isLoading }]" :disabled="isLoading" - @click="handleButtonClick" + @click="handleButtonClick(orderData)" > {{ isLoading ? "处理中..." : buttonText }} @@ -52,7 +52,7 @@ const PAY_WAY_MAP = { const isLoading = ref(false); // 定义事件发射器 -const emit = defineEmits(["show-refund-popup"]); +const emit = defineEmits(["show-refund-popup", "pay-success"]); const props = defineProps({ orderData: { @@ -102,51 +102,95 @@ const shouldShowButton = computed(() => { }); // 处理按钮点击事件 -const handleButtonClick = async () => { +const handleButtonClick = async (orderData) => { if (isLoading.value) return; // 防止重复点击 - const status = props.orderData.orderStatus; - const orderId = props.orderData.orderId; - // 支付方式 - const payWay = props.orderData.payWay; - // 支付渠道 - const paySource = "1"; - - if (status === "2") { - // 情况2:待使用状态,显示退款弹窗 - emit("show-refund-popup"); - return; // 直接返回,不执行后续代码 - } - try { isLoading.value = true; - // 情况1:待支付状态或其他状态,先预下单再支付 - // 第一步:预下单 - const res = await orderPayNow({ orderId, payWay, paySource }); - console.log(res); + const status = orderData.orderStatus; - // 仅作为示例,非真实参数信息。 - uni.requestPayment({ - provider: "wxpay", - timeStamp: String(Date.now()), - nonceStr: "A1B2C3D4E5", - package: "prepay_id=wx20180101abcdefg", - signType: "MD5", - paySign: "", - success: (res) => { - console.log("success:" + JSON.stringify(res)); - }, - fail: (err) => { - console.log("fail:" + JSON.stringify(err)); - }, - }); + if (status === "2") { + // 情况2:待使用状态,显示退款弹窗 + emit("show-refund-popup"); + return; // 直接返回,不执行后续代码 + } + + // 再次预定跳转商品详情 + if (["3", "5", "6"].includes(status)) { + uni.navigateTo({ + url: `/pages/goods/index?commodityId=${orderData.commodityId}`, + }); + } + + // 待支付状态,调用支付接口 + if (status === "0") { + const orderId = orderData.orderId; + const payWay = orderData.payWay; + const paySource = orderData.paySource; + + const res = await orderPayNow({ orderId, payWay, paySource }); + console.log("确认订单---2:", res); + + // 检查接口返回数据 + if (!res || !res.data) { + uni.showToast({ + title: "订单创建失败,请重试", + icon: "none", + duration: 2000, + }); + return; + } + + const { data } = res; + const { nonceStr, packageVal, paySign, signType, timeStamp } = data; + + // 验证支付参数是否完整 + if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { + console.error("支付参数不完整:", { + nonceStr: !!nonceStr, + packageVal: !!packageVal, + paySign: !!paySign, + signType: !!signType, + timeStamp: !!timeStamp, + }); + uni.showToast({ + title: "支付参数错误,请重试", + icon: "none", + duration: 2000, + }); + return; + } + + // 调用微信支付 + uni.requestPayment({ + provider: "wxpay", + timeStamp: String(timeStamp), // 确保为字符串类型 + nonceStr: String(nonceStr), + package: String(packageVal), // 确保为字符串类型 + signType: String(signType), + paySign: String(paySign), + success: () => { + uni.showToast({ + title: "支付成功", + icon: "success", + duration: 2000, + success: () => { + emit("pay-success"); + }, + }); + }, + fail: (err) => { + uni.showToast({ + title: "支付失败,请重试", + icon: "none", + duration: 2000, + }); + }, + }); + } } catch (error) { console.error("操作失败:", error); - uni.showToast({ - title: error.message || "操作失败,请重试", - icon: "none", - }); } finally { isLoading.value = false; } diff --git a/src/pages-order/order/components/OrderInfo/styles/index.scss b/src/pages-order/order/components/OrderInfo/styles/index.scss index ddb8177..a9b9f70 100644 --- a/src/pages-order/order/components/OrderInfo/styles/index.scss +++ b/src/pages-order/order/components/OrderInfo/styles/index.scss @@ -28,16 +28,6 @@ $font-weight-semibold: 600; $transition-fast: 0.2s ease; $transition-normal: 0.3s ease; -// 动画关键帧 -@keyframes loading-spin { - 0% { - transform: rotate(0deg); - } - 100% { - transform: rotate(360deg); - } -} - .order-info { background-color: $order-bg-color; border-radius: $order-border-radius; @@ -153,21 +143,6 @@ $transition-normal: 0.3s ease; &::before { display: none; } - - // 加载动画 - &::after { - content: ""; - position: absolute; - left: 50%; - top: 50%; - width: 16px; - height: 16px; - margin: -8px 0 0 -8px; - border: 2px solid transparent; - border-top: 2px solid #fff; - border-radius: $uni-border-radius-circle; - animation: loading-spin 1s linear infinite; - } } } diff --git a/src/pages-order/order/detail.vue b/src/pages-order/order/detail.vue index 27ef63b..6cc1408 100644 --- a/src/pages-order/order/detail.vue +++ b/src/pages-order/order/detail.vue @@ -23,7 +23,11 @@ - + { - const res = await userOrderDetail({ orderId }); +onLoad(({ orderId }) => getOrderDetail(orderId)); +// 获取订单详情 +const getOrderDetail = async (orderId) => { + const res = await userOrderDetail({ orderId }); orderData.value = res.data; console.log(res); -}); +}; // 监听页面滚动事件 const backgroundColor = ref("transparent"); @@ -105,6 +111,11 @@ const handleRefundConfirm = async ({ orderId }) => { }); } }; + +// 再次预定 +const handlePaySuccess = ({ orderId }) => { + getOrderDetail(orderId); +};