From 349e2a8f3df31c720d9e4c6442d1632d90522023 Mon Sep 17 00:00:00 2001 From: duanshuwen Date: Sat, 11 Apr 2026 18:00:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8Dtoast=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages-booking/index.vue | 233 ++++++++++++++++++------------------ 1 file changed, 117 insertions(+), 116 deletions(-) diff --git a/src/pages-booking/index.vue b/src/pages-booking/index.vue index 385c2ad..e54a57f 100644 --- a/src/pages-booking/index.vue +++ b/src/pages-booking/index.vue @@ -2,7 +2,7 @@ @@ -147,7 +147,7 @@ watch( if (newQuantity > currentLength) { // 数量增加,添加新的表单项 const newForms = Array.from({ length: newQuantity - currentLength }, () => - createEmptyUserForm(), + createEmptyUserForm() ); userFormList.value.push(...newForms); } else if (newQuantity < currentLength) { @@ -158,7 +158,7 @@ watch( // 等待DOM更新完成 await nextTick(); }, - { immediate: false }, + { immediate: false } ); onLoad((options) => { @@ -184,7 +184,7 @@ const getGoodsDetail = async (commodityId) => { // 取commodityFacilityList前3个 orderData.value.commodityFacilityList = res.data.commodityFacilityList.slice( 0, - 3, + 3 ); }; @@ -211,119 +211,120 @@ const validateUserForms = () => { // 处理支付点击事件 const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => { - try { - console.log("处理支付点击事件", userFormList.value); - // 校验用户姓名 - if (!validateUserForms()) { - return; - } - - // 校验手机号 - if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) { - uni.showToast({ title: "请输入正确的手机号", icon: "none" }); - return; - } - - // 购买的商品id - const commodityId = goodsData.commodityId; - // 消费者信息 - const consumerInfoEntityList = userFormList.value; - // 购买数量 - const purchaseAmount = consumerInfoEntityList.length; - // 支付方式 0-微信 1-支付宝 2-云闪付 - const payWay = "0"; - // 支付渠道 0-app 1-小程序 2-h5 - const paySource = "1"; - - const params = { - commodityId, - purchaseAmount, - payWay, - paySource, - consumerInfoEntityList, - }; - - // 预约日期,酒店类型不需要 - if (orderData.value.orderType != 0) { - params.reservationDate = selectedReservationDate.value; - } - - //酒店类型添加入住时间、离店时间 - if (goodsData.orderType == 0 && selectedDate.value) { - const { startDate, endDate } = selectedDate.value; - // 入住时间 - params.checkInData = startDate; - // 离店时间 - params.checkOutData = endDate; - } - - // 点击后立即展示 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; - } - - const { data } = res; - const { nonceStr, packageVal, paySign, signType, timeStamp } = data; - - // 验证支付参数是否完整 - if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { - uni.hideLoading(); - setTimeout(() => { - uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); - }, 100); - return; - } - - // 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突) - uni.hideLoading(); - - // 调用微信支付 - 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" }); - }, - }); - } catch (error) { - console.error(error); - uni.hideLoading(); // 提前关闭 loading,确保 toast 能在安卓正常弹出 - setTimeout(() => { - uni.showToast({ title: "请求出错,请重试", icon: "none" }); - }, 100); - } finally { - // 最终兜底关闭 loading - uni.hideLoading(); + console.log("处理支付点击事件", userFormList.value); + // 校验用户姓名 + if (!validateUserForms()) { + return; } + + // 校验手机号 + if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) { + uni.showToast({ title: "请输入正确的手机号", icon: "none" }); + return; + } + + // 购买的商品id + const commodityId = goodsData.commodityId; + // 消费者信息 + const consumerInfoEntityList = userFormList.value; + // 购买数量 + const purchaseAmount = consumerInfoEntityList.length; + // 支付方式 0-微信 1-支付宝 2-云闪付 + const payWay = "0"; + // 支付渠道 0-app 1-小程序 2-h5 + const paySource = "1"; + + const params = { + commodityId, + purchaseAmount, + payWay, + paySource, + consumerInfoEntityList, + }; + + // 预约日期,酒店类型不需要 + if (orderData.value.orderType != 0) { + params.reservationDate = selectedReservationDate.value; + } + + //酒店类型添加入住时间、离店时间 + if (goodsData.orderType == 0 && selectedDate.value) { + const { startDate, endDate } = selectedDate.value; + // 入住时间 + params.checkInData = startDate; + // 离店时间 + params.checkOutData = endDate; + } + + // 点击后立即展示 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; + } + + const { data } = res; + const { nonceStr, packageVal, paySign, signType, timeStamp } = data; + + // 验证支付参数是否完整 + if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) { + uni.hideLoading(); + setTimeout(() => { + uni.showToast({ title: "支付参数错误,请重试", icon: "none" }); + }, 100); + return; + } + + // 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突) + uni.hideLoading(); + + // 调用微信支付 + 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" }); + }, + }); + // try { + + // } catch (error) { + // console.error(error); + // uni.hideLoading(); // 提前关闭 loading,确保 toast 能在安卓正常弹出 + // setTimeout(() => { + // uni.showToast({ title: "请求出错,请重试", icon: "none" }); + // }, 100); + // } finally { + // // 最终兜底关闭 loading + // uni.hideLoading(); + // } }, 1000);