feat: 提交订单的loading 添加
This commit is contained in:
@@ -203,16 +203,22 @@ const validateUserForms = () => {
|
|||||||
|
|
||||||
// 处理支付点击事件
|
// 处理支付点击事件
|
||||||
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||||
|
// 点击后立即展示 loading
|
||||||
|
uni.showLoading({ title: "正在提交订单..." });
|
||||||
|
|
||||||
|
try {
|
||||||
console.log("处理支付点击事件", userFormList.value);
|
console.log("处理支付点击事件", userFormList.value);
|
||||||
// 判断是酒店类型
|
// 判断是酒店类型
|
||||||
if (goodsData.commodityTypeCode === "0") {
|
if (goodsData.commodityTypeCode === "0") {
|
||||||
// 校验用户姓名
|
// 校验用户姓名
|
||||||
if (!validateUserForms()) {
|
if (!validateUserForms()) {
|
||||||
|
uni.hideLoading();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 校验手机号
|
// 校验手机号
|
||||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -250,6 +256,7 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
|||||||
|
|
||||||
// 检查接口返回数据
|
// 检查接口返回数据
|
||||||
if (!res || !res.data) {
|
if (!res || !res.data) {
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -259,17 +266,14 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
|||||||
|
|
||||||
// 验证支付参数是否完整
|
// 验证支付参数是否完整
|
||||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||||
// console.error("支付参数不完整:", {
|
uni.hideLoading();
|
||||||
// nonceStr: !!nonceStr,
|
|
||||||
// packageVal: !!packageVal,
|
|
||||||
// paySign: !!paySign,
|
|
||||||
// signType: !!signType,
|
|
||||||
// timeStamp: !!timeStamp,
|
|
||||||
// });
|
|
||||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
// 调用微信支付
|
// 调用微信支付
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: "wxpay",
|
provider: "wxpay",
|
||||||
@@ -293,6 +297,13 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
|||||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||||
|
} finally {
|
||||||
|
// 防止某些分支忘记 hide,确保最终关闭 loading(requestPayment 后也可以安全调用 hide)
|
||||||
|
uni.hideLoading();
|
||||||
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -71,10 +71,14 @@ const handleButtonClick = async (orderData) => {
|
|||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/goods/index?commodityId=${orderData.commodityId}`,
|
url: `/pages/goods/index?commodityId=${orderData.commodityId}`,
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 待支付状态,调用支付接口
|
// 待支付状态,调用支付接口
|
||||||
if (statusCode.value === "0") {
|
if (statusCode.value === "0") {
|
||||||
|
// 显示 loading
|
||||||
|
uni.showLoading({ title: "正在提交订单..." });
|
||||||
|
|
||||||
const orderId = orderData.orderId;
|
const orderId = orderData.orderId;
|
||||||
const payWay = orderData.payWay;
|
const payWay = orderData.payWay;
|
||||||
const paySource = orderData.paySource;
|
const paySource = orderData.paySource;
|
||||||
@@ -84,6 +88,7 @@ const handleButtonClick = async (orderData) => {
|
|||||||
|
|
||||||
// 检查接口返回数据
|
// 检查接口返回数据
|
||||||
if (!res || !res.data) {
|
if (!res || !res.data) {
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,17 +98,14 @@ const handleButtonClick = async (orderData) => {
|
|||||||
|
|
||||||
// 验证支付参数是否完整
|
// 验证支付参数是否完整
|
||||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||||
// console.error("支付参数不完整:", {
|
uni.hideLoading();
|
||||||
// nonceStr: !!nonceStr,
|
|
||||||
// packageVal: !!packageVal,
|
|
||||||
// paySign: !!paySign,
|
|
||||||
// signType: !!signType,
|
|
||||||
// timeStamp: !!timeStamp,
|
|
||||||
// });
|
|
||||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
// 调用微信支付
|
// 调用微信支付
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: "wxpay",
|
provider: "wxpay",
|
||||||
@@ -126,6 +128,7 @@ const handleButtonClick = async (orderData) => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("操作失败:", error);
|
console.error("操作失败:", error);
|
||||||
|
uni.hideLoading();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user