From a05b724a0f6652a30d055200b44cb7116da8f8a0 Mon Sep 17 00:00:00 2001 From: wangxiaowei <1121133807@qq.com> Date: Thu, 11 Dec 2025 19:17:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle/reserve/confirm.vue | 93 +++++++++++++---- bundle/reserve/details.vue | 173 ++++++++++++++++++++++++-------- manifest.json | 8 +- pages/order/cg-order-detail.vue | 8 +- 4 files changed, 217 insertions(+), 65 deletions(-) diff --git a/bundle/reserve/confirm.vue b/bundle/reserve/confirm.vue index 1822db5..212f8f7 100644 --- a/bundle/reserve/confirm.vue +++ b/bundle/reserve/confirm.vue @@ -19,7 +19,8 @@ - 场地费(¥{{ bill.cdf.price }}元/小时) + + 小时 x{{ bill.cdf.nums }} @@ -46,7 +47,8 @@ - 灯光费(¥{{ bill.dgf.price }}元/小时) + + 小时 x{{ bill.dgf.nums }} @@ -56,7 +58,7 @@ 折扣优惠 - + - @@ -76,7 +78,7 @@ 合计: - {{ userDiscount }}折 + {{ userDiscount }}折 费用明细 @@ -360,7 +362,17 @@ }, onLoad(args) { - console.log("🚀 ~ args:", args) + // let bill = uni.getStorageSync('billDetail'); + // // if (!bill) { + // // uni.showToast({ title: '获取订单信息失败,请重试', icon: 'none' }); + // // return + // // } + // if (bill) { + // bill = JSON.parse(bill); + // this.bill = bill + // } + + // console.log("🚀 ~ args:", this.bill) this.orderId = args.orderId || 0; // 订单ID this.venueId = args.venueId || 0; // 场馆ID this.typeId = args.typeId || 1; // 网球场1 篮球场2 @@ -371,6 +383,7 @@ }, onUnload() { + uni.removeStorageSync('billDetail') switch(this.result) { case 'success': uni.$emit('payment', { result: true, order_id: this.orderId }) @@ -380,12 +393,11 @@ } }, - methods: { - // 判断 payType 是否为整数 - isPayTypeInt() { - return Number.isInteger(Number(this.payType)); - }, + // 判断 payType 是否为整数 + isPayTypeInt() { + return Number.isInteger(Number(this.payType)); + }, getData() { let self = this; uni.showLoading({ @@ -445,7 +457,6 @@ } ) } - // 获取订单详情 self._post( @@ -459,7 +470,22 @@ self.order = res.data.lists; self.countSelectedTime = self.order.hours - self.countPrice() + // 缓存不存在则直接从订单详情中获取费用明细 + // if (!uni.getStorageSync('billDetail')) { + for (const key in self.order.trade) { + const value = self.order.trade[key]; + for (const item of value) { + self.bill.cdf.nums = self.order.hours; + self.bill.cdf.price = 0; // 假设每个时间段的价格相同 + self.bill.cdf.total += Number(item.room_price); + self.bill.dgf.nums = self.order.hours; + self.bill.dgf.price = 0; // 假设每个时间段的灯光价格相同 + self.bill.dgf.total += Number(item.light_price); + } + } + self.bill.total = self.bill.cdf.total + self.bill.dgf.total; + // } + // self.countPrice() } self.loadding = false; @@ -528,6 +554,13 @@ if (n == 'balance') { this.balancePopup = true; } else { + this.userAccount = 0; + this.userDiscount = 0; + this.currentType = ''; + // 如果是微信支付的话则重新获取订单信息 + let bill = uni.getStorageSync('billDetail') || {}; + bill = JSON.parse(bill); + this.bill = bill this.balancePopup = false; } }, @@ -581,7 +614,22 @@ }, function(res) { const data = res.data - console.log("🚀 ~ pay data:", data) + // 支付订单为0的情况下直接返回成功 + if (data.pay_success && data.pay_success == 1) { + self.result = 'success' + uni.showToast({ + title: '支付成功', + icon: 'none' + }); + self.loadding = false; + + setTimeout(() => { + uni.navigateBack({delta: 1}) + }, 500); + + return; + } + uni.requestPayment({ provider: 'wxpay', timeStamp: data.payment.timeStamp, @@ -646,8 +694,8 @@ 'ground.ground/yuePay', { app_id: self.getAppId(), - order_id: this.orderId, - pay_type: this.currentType + order_id: self.orderId, + pay_type: self.currentType }, function(res) { if (res.code == 1) { @@ -730,9 +778,9 @@ } }, - // 确认选择 + // 确认选择充值卡 confirmCard() { - if (this.userBalance['balance' + this.currentType] <= 0) { + if (this.userBalance['balance' + this.currentType] <= 0 && this.bill.total > 0) { uni.showToast({ title: '余额不足,请选择其他会员卡', icon: 'none' @@ -742,8 +790,17 @@ this.userAccount = this.userBalance['balance' + this.currentType]; this.userDiscount = this.balance['discount' + this.currentType]; + + const discount = Number(this.userDiscount) || 10; // 折扣,默认10(不打折) + + const total = Number(this.bill.total) || 0; + // 保留两位小数,不四舍五入 + const finalPrice = Number((total * (discount / 10)).toFixed(2)); + this.bill.dis = Number((total - finalPrice).toFixed(2)); + this.bill.total = finalPrice; + this.payType = this.currentType; - this.countPrice(); + // this.countPrice(); this.balancePopup = false; } } diff --git a/bundle/reserve/details.vue b/bundle/reserve/details.vue index e6ff558..5727785 100644 --- a/bundle/reserve/details.vue +++ b/bundle/reserve/details.vue @@ -26,7 +26,8 @@ - 场地费(¥{{ bill.cdf.price }}元/小时) + + 小时 x{{ bill.cdf.nums }} @@ -53,7 +54,8 @@ - 灯光费(¥{{ bill.dgf.price }}元/小时) + + 小时 x{{ bill.dgf.nums }} @@ -160,8 +162,8 @@ {{ item2.title }} + + @@ -281,6 +285,7 @@ export default { selectedWeekDay: '', selectedReserveTime: [], countSelectedTime: 0, + roomSelectList: [] }; }, @@ -392,35 +397,40 @@ export default { // 计算费用明细 totalPrice() { - let self = this + // let self = this + + // self._post( + // 'ground.ground/countPrice', + // { + // app_id: self.getAppId(), + // room_id: self.id, + // nums: this.countSelectedTime, + // type_id: self.venue.type_id, + // day: this.selectedWeekTimes, + // room_msg: JSON.stringify(this.roomSelectList) + // }, + // function(res) { + // const result = res.data.lists + // self.bill = { + // total: result.order_amount, + // cdf: { + // nums: result.nums, + // price: result.room_price, + // total: result.room_all_price + // }, + // dgf: { + // nums: result.nums, + // price: result.light_price, + // total: result.light_all_price + // } + // } - self._post( - 'ground.ground/countPrice', - { - app_id: self.getAppId(), - room_id: self.id, - nums: this.countSelectedTime, - type_id: self.venue.type_id, - }, - function(res) { - const result = res.data.lists - self.bill = { - total: result.order_amount, - cdf: { - nums: result.nums, - price: result.room_price, - total: result.room_all_price - }, - dgf: { - nums: result.nums, - price: result.light_price, - total: result.light_all_price - } - } + // self.loadding = false; + // } + // ) + + // TODO 暂时前端写 - self.loadding = false; - } - ) }, // 显示费用明细 @@ -434,7 +444,7 @@ export default { this.showPrice = true; }, - // 篮球场-立即预约 + // 立即预约 toReserve() { let self = this // 一进来就锁定,彻底防止高频点击 @@ -451,6 +461,12 @@ export default { mask: true, }); try { + const start = self.selectedReserveTime[0].day_time + ' ' + self.selectedReserveTime[0].end_time; + const end = self.selectedReserveTime[self.selectedReserveTime.length -1].day_time + ' ' + self.selectedReserveTime[self.selectedReserveTime.length -1].end_time; + // 转换为时间戳 + const startTimestamp = Math.floor(Date.parse(start.replace(/-/g, '/')) / 1000);; + const endTimestamp = Math.floor(Date.parse(end.replace(/-/g, '/')) / 1000);; + // 订单提交 self._post( 'order.groundOrder/submitStoreOrder', @@ -458,12 +474,16 @@ export default { app_id: self.getAppId(), ground_id: self.id, room_list: JSON.stringify(self.selectedReserveTime), - type: this.typeId, - start_end: self.selectedReserveTime[0].start_time + '-' + self.selectedReserveTime[self.selectedReserveTime.length -1].end_time + type: self.typeId, + start_end: startTimestamp + '-' + endTimestamp, + amount_price: self.bill.total }, function(res) { self.loadding = false; if(res.code) { + // 记录费用明细到缓存中 + // uni.setStorageSync('billDetail', JSON.stringify(self.bill)); + uni.$on('payment', params => { console.log("🚀 ~ params:", params) uni.showLoading({ @@ -511,11 +531,17 @@ export default { url: `/bundle/reserve/confirm?venueId=${self.venue.id}&roomId=${self.id}&typeId=${self.typeId}` }); } - }, + /** + * + * @param title + * @param time + * @param status + */ handleSelectTime(title, time, status) { - if (status == 1) { + let self = this + if (status == 1) { return; } // 多选逻辑,selectedTime为对象,按title区分 @@ -530,16 +556,27 @@ export default { // 未选中则添加 this.selectedTime[title].push(time); } - this.countSelectedTime = Object.values(this.selectedTime).reduce((acc, times) => acc + times.length, 0); - this.totalPrice() // 遍历所有已选时间,生成 room_list const room_list = []; + let totalPrice = 0; + let totalLightPrice = 0; + let amount_price = 0; + Object.keys(this.selectedTime).forEach(roomTitle => { const roomId = this.cdList.find(cd => cd.title === roomTitle)?.room_id; + const room = this.cdList.find(cd => cd.title === roomTitle); + this.selectedTime[roomTitle].forEach(t => { + const timeObj = room?.time?.find(item => item.t === t); + if (timeObj) { + totalPrice += Number(timeObj.price) || 0; + totalLightPrice += Number(timeObj.light_price) || 0; + amount_price = Number(timeObj.price) + Number(timeObj.light_price); + } + // t 可能是 '09:00-10:00' 或 '09:00', 需拆分 let start_time = t, end_time = ''; if (t.includes('-')) { @@ -557,24 +594,73 @@ export default { day_time: this.selectedWeekTimes, start_time, end_time, + room_price: timeObj ? timeObj.price : 0, + light_price: timeObj ? timeObj.light_price : 0, + amount_price, }); }); }); this.selectedReserveTime = room_list; - console.log('🚀 ~ room_list:', this.selectedReserveTime); + + // 计算场地费用 + self.bill = { + total: Number(totalPrice) + Number(totalLightPrice), + cdf: { + nums: this.countSelectedTime, + price: 0, // 假设单价100元/小时,实际应从后端获取 + total: totalPrice + }, + dgf: { + nums: this.countSelectedTime, + price: 0, + total: totalLightPrice + } + }; + + // 新增:生成 roomSelectList 变量 + const roomSelectList = Object.keys(this.selectedTime).map(roomTitle => { + const roomId = this.cdList.find(cd => cd.title === roomTitle)?.room_id; + const select_time = (this.selectedTime[roomTitle] || []).join(','); + return { + room_id: roomId, + select_time + }; + }); + this.roomSelectList = roomSelectList; + this.totalPrice() + console.log('🚀 ~ roomSelectList:', roomSelectList); }, + // 选择日期 selectWeek(item, index) { let self = this self.currentWeek = index self.selectedWeekDay = item.value[1] + '' + item.value[0] self.selectedWeekTimes = item.times + // 重置费用明细 + self.bill = { + total: 0, + cdf: { + nums: 0, + price: 0, // 假设单价100元/小时,实际应从后端获取 + total: 0 + }, + dgf: { + nums: 0, + price: 0, + total: 0 + } + }; + + // 重置已选时间 self.selectedTime = [] + self.selectedReserveTime = [] self.getReserveTime() }, + // 获取预定时间 getReserveTime() { let self = this; let params = {} @@ -601,8 +687,13 @@ export default { self.timeList = res.data.lists3 // 初始化选择的时间 - self.selectedWeekDay = res.data.lists2[0].value[1] + '' + res.data.lists2[0].value[0] - self.selectedWeekTimes = res.data.lists2[0].times + if (!self.selectedWeekDay) { + self.selectedWeekDay = res.data.lists2[0].value[1] + '' + res.data.lists2[0].value[0] + } + + if (!self.selectedWeekTimes) { + self.selectedWeekTimes = res.data.lists2[0].times + } self.loadding = false } diff --git a/manifest.json b/manifest.json index ebfc70d..4d4aebd 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { - "name" : "星及茗茶", - "appid" : "__UNI__0C79E17", - "description" : "星及茗茶", + "name" : "秀湖网球中心", + "appid" : "__UNI__A95F43A", + "description" : "秀湖网球中心", "versionName" : "2.0.1", "versionCode" : 201, "transformPx" : false, @@ -153,7 +153,7 @@ "minified" : true }, "usingComponents" : true, - "requiredPrivateInfos" : [ "getLocation" ], + "requiredPrivateInfos" : [ "getLocation" ], "permission" : { "scope.userLocation" : { "desc" : "获取您与体育场馆的距离" diff --git a/pages/order/cg-order-detail.vue b/pages/order/cg-order-detail.vue index 047d595..47536c7 100644 --- a/pages/order/cg-order-detail.vue +++ b/pages/order/cg-order-detail.vue @@ -440,13 +440,17 @@ self.cancelReservePopup = false; if(res.code) { - uni.hideLoading(); uni.showToast({ title: res.msg, duration: 2000, icon: 'success' }); - self.getData(); + setTimeout(() => { + uni.hideLoading(); + self.getData(); + }, 500); + } else { + uni.hideLoading(); } } );