fix: 待支付|再次预定交互逻辑调整
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
v-if="shouldShowButton"
|
||||
:class="['reserve-button', { loading: isLoading }]"
|
||||
:disabled="isLoading"
|
||||
@click="handleButtonClick"
|
||||
@click="handleButtonClick(orderData)"
|
||||
>
|
||||
{{ isLoading ? "处理中..." : buttonText }}
|
||||
</button>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user