refactor(booking): clean up toast and payment code
Replace verbose uni.showToast object syntax with shorter direct calls, remove unnecessary setTimeout wrappers around error toast calls, clean up redundant loading state handling, and remove unused WeChat pay and app payment placeholder code.
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, nextTick } from "vue";
|
||||
import { useRouter } from 'vue-router'
|
||||
import TopNavBar from "@/components/TopNavBar/index.vue";
|
||||
import DateRangeSection from "@/components/DateRangeSection/index.vue";
|
||||
import ContactSection from "./components/ConactSection/index.vue";
|
||||
@@ -75,6 +76,9 @@ import { GOODS_TYPE } from "@/constants/type";
|
||||
import { ThrottleUtils } from "@/utils/ThrottleUtils";
|
||||
import { PhoneUtils } from "@/utils/PhoneUtils";
|
||||
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const refundVisible = ref(false);
|
||||
const detailVisible = ref(false);
|
||||
const orderData = ref({});
|
||||
@@ -155,8 +159,11 @@ const getGoodsDetail = async (commodityId) => {
|
||||
|
||||
// 跳转商品详情
|
||||
const navigateToDetail = ({ commodityId }) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/goods/index?commodityId=${commodityId}`,
|
||||
router.push({
|
||||
path: "/pages/goods/index",
|
||||
query: {
|
||||
commodityId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -167,7 +174,7 @@ const validateUserForms = () => {
|
||||
});
|
||||
|
||||
if (invalidUsers.length) {
|
||||
uni.showToast({ title: "请填写姓名", icon: "none" });
|
||||
showToast("请填写姓名");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -180,7 +187,7 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
// 预约日期,酒店类型不需要
|
||||
if (orderData.value.reservationEnabled) {
|
||||
if (!selectedReservationDate.value) {
|
||||
uni.showToast({ title: "请选择预约日期", icon: "none" });
|
||||
showToast("请选择预约日期");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -192,7 +199,7 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
showToast("请输入正确的手机号");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -230,20 +237,12 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
}
|
||||
|
||||
// 点击后立即展示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
const res = await orderPay(params);
|
||||
console.log("确认订单---2:", res);
|
||||
uni.hideLoading();
|
||||
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: res.msg || "订单创建失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -252,50 +251,8 @@ const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
setTimeout(() => {
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 调用微信支付
|
||||
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",
|
||||
success: () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages-order/order/list",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: (e) => {
|
||||
console.error("支付失败:", e);
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "支付功能开发中",
|
||||
showCancel: false,
|
||||
});
|
||||
// #endif
|
||||
}, 1000);
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user