完善功能

This commit is contained in:
wangxiaowei
2025-12-11 19:17:38 +08:00
parent d77dbb20f3
commit a05b724a0f
4 changed files with 217 additions and 65 deletions

View File

@ -19,7 +19,8 @@
</view> </view>
</view> </view>
<view class="title2 d-b-c"> <view class="title2 d-b-c">
<view>场地费(¥{{ bill.cdf.price }}元/小时)</view> <!-- <view>场地费(¥{{ bill.cdf.price }}元/小时)</view> -->
<view>小时</view>
<view>x{{ bill.cdf.nums }}</view> <view>x{{ bill.cdf.nums }}</view>
</view> </view>
</view> </view>
@ -46,7 +47,8 @@
</view> </view>
</view> </view>
<view class="title2 d-b-c"> <view class="title2 d-b-c">
<view>灯光费(¥{{ bill.dgf.price }}元/小时)</view> <!-- <view>灯光费(¥{{ bill.dgf.price }}元/小时)</view> -->
<view>小时</view>
<view>x{{ bill.dgf.nums }}</view> <view>x{{ bill.dgf.nums }}</view>
</view> </view>
</view> </view>
@ -56,7 +58,7 @@
<view class="title1 d-b-c"> <view class="title1 d-b-c">
<view>折扣优惠</view> <view>折扣优惠</view>
<view> <view>
<price-format color="#FA2B21" :subscript-size="30" :first-size="30" :second-size="30" :price="bill.dis" :showSubscript="false"></price-format> <text style="color: #FA2B21;"> -</text> <price-format color="#FA2B21" :subscript-size="30" :first-size="30" :second-size="30" :price="bill.dis"></price-format>
</view> </view>
</view> </view>
</view> </view>
@ -76,7 +78,7 @@
<view class="d-f d-c j-c-b"> <view class="d-f d-c j-c-b">
<view> <view>
合计: <price-format color="#FF5951" :subscript-size="26" :first-size="40" :second-size="40" :price="bill.total"></price-format> 合计: <price-format color="#FF5951" :subscript-size="26" :first-size="40" :second-size="40" :price="bill.total"></price-format>
<text style="margin-left: 10rpx;color: #FA2B21;font-size: 26rpx;">{{ userDiscount }}折</text> <text style="margin-left: 10rpx;color: #FA2B21;font-size: 26rpx;" v-if="userDiscount > 0">{{ userDiscount }}折</text>
</view> </view>
<view class="d-f j-c-c a-i-c" style="margin-top: 10rpx;" @click="closeBillPopup"> <view class="d-f j-c-c a-i-c" style="margin-top: 10rpx;" @click="closeBillPopup">
<view class="price-detail">费用明细</view> <view class="price-detail">费用明细</view>
@ -360,7 +362,17 @@
}, },
onLoad(args) { 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.orderId = args.orderId || 0; // 订单ID
this.venueId = args.venueId || 0; // 场馆ID this.venueId = args.venueId || 0; // 场馆ID
this.typeId = args.typeId || 1; // 网球场1 篮球场2 this.typeId = args.typeId || 1; // 网球场1 篮球场2
@ -371,6 +383,7 @@
}, },
onUnload() { onUnload() {
uni.removeStorageSync('billDetail')
switch(this.result) { switch(this.result) {
case 'success': case 'success':
uni.$emit('payment', { result: true, order_id: this.orderId }) uni.$emit('payment', { result: true, order_id: this.orderId })
@ -380,12 +393,11 @@
} }
}, },
methods: { methods: {
// 判断 payType 是否为整数 // 判断 payType 是否为整数
isPayTypeInt() { isPayTypeInt() {
return Number.isInteger(Number(this.payType)); return Number.isInteger(Number(this.payType));
}, },
getData() { getData() {
let self = this; let self = this;
uni.showLoading({ uni.showLoading({
@ -446,7 +458,6 @@
) )
} }
// 获取订单详情 // 获取订单详情
self._post( self._post(
'order.groundOrder/orderGroundDetails', 'order.groundOrder/orderGroundDetails',
@ -459,7 +470,22 @@
self.order = res.data.lists; self.order = res.data.lists;
self.countSelectedTime = self.order.hours 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; self.loadding = false;
@ -528,6 +554,13 @@
if (n == 'balance') { if (n == 'balance') {
this.balancePopup = true; this.balancePopup = true;
} else { } else {
this.userAccount = 0;
this.userDiscount = 0;
this.currentType = '';
// 如果是微信支付的话则重新获取订单信息
let bill = uni.getStorageSync('billDetail') || {};
bill = JSON.parse(bill);
this.bill = bill
this.balancePopup = false; this.balancePopup = false;
} }
}, },
@ -581,7 +614,22 @@
}, },
function(res) { function(res) {
const data = res.data 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({ uni.requestPayment({
provider: 'wxpay', provider: 'wxpay',
timeStamp: data.payment.timeStamp, timeStamp: data.payment.timeStamp,
@ -646,8 +694,8 @@
'ground.ground/yuePay', 'ground.ground/yuePay',
{ {
app_id: self.getAppId(), app_id: self.getAppId(),
order_id: this.orderId, order_id: self.orderId,
pay_type: this.currentType pay_type: self.currentType
}, },
function(res) { function(res) {
if (res.code == 1) { if (res.code == 1) {
@ -730,9 +778,9 @@
} }
}, },
// 确认选择 // 确认选择充值卡
confirmCard() { confirmCard() {
if (this.userBalance['balance' + this.currentType] <= 0) { if (this.userBalance['balance' + this.currentType] <= 0 && this.bill.total > 0) {
uni.showToast({ uni.showToast({
title: '余额不足,请选择其他会员卡', title: '余额不足,请选择其他会员卡',
icon: 'none' icon: 'none'
@ -742,8 +790,17 @@
this.userAccount = this.userBalance['balance' + this.currentType]; this.userAccount = this.userBalance['balance' + this.currentType];
this.userDiscount = this.balance['discount' + 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.payType = this.currentType;
this.countPrice(); // this.countPrice();
this.balancePopup = false; this.balancePopup = false;
} }
} }

View File

@ -26,7 +26,8 @@
</view> </view>
</view> </view>
<view class="title2 d-b-c"> <view class="title2 d-b-c">
<view>场地费(¥{{ bill.cdf.price }}元/小时)</view> <!-- <view>场地费(¥{{ bill.cdf.price }}元/小时)</view> -->
<view>小时</view>
<view>x{{ bill.cdf.nums }}</view> <view>x{{ bill.cdf.nums }}</view>
</view> </view>
</view> </view>
@ -53,7 +54,8 @@
</view> </view>
</view> </view>
<view class="title2 d-b-c"> <view class="title2 d-b-c">
<view>灯光费(¥{{ bill.dgf.price }}元/小时)</view> <!-- <view>灯光费(¥{{ bill.dgf.price }}元/小时)</view> -->
<view>小时</view>
<view>x{{ bill.dgf.nums }}</view> <view>x{{ bill.dgf.nums }}</view>
</view> </view>
</view> </view>
@ -161,7 +163,7 @@
<view class="" style="margin-bottom: 6rpx; text-align: center;">{{ item2.title }}</view> <view class="" style="margin-bottom: 6rpx; text-align: center;">{{ item2.title }}</view>
<view <view
v-for="(item3, index3) in item2.time" :key="index3" v-for="(item3, index3) in item2.time" :key="index3"
@click="handleSelectTime(item2.title, item3.t, item3.status, item2.room_id)" @click="handleSelectTime(item2.title, item3.t, item3.status, item2.room_id, item3.price, item3.light_price)"
class="cg-info-time" :class="[ class="cg-info-time" :class="[
item3.status == 1 item3.status == 1
? 'cg-info-time-none' ? 'cg-info-time-none'
@ -169,8 +171,10 @@
? 'cg-info-time-select' ? 'cg-info-time-select'
: 'cg-info-time-normal' : 'cg-info-time-normal'
]" > ]" >
<!-- <template v-if="item3.t != '22:00'"> -->
<template v-if="item3.price > 0">{{ item3.price }}</template> <template v-if="item3.price > 0">{{ item3.price }}</template>
<template v-else>免费</template> <template v-else>免费</template>
<!-- </template> -->
</view> </view>
</view> </view>
</view> </view>
@ -281,6 +285,7 @@ export default {
selectedWeekDay: '', selectedWeekDay: '',
selectedReserveTime: [], selectedReserveTime: [],
countSelectedTime: 0, countSelectedTime: 0,
roomSelectList: []
}; };
}, },
@ -392,35 +397,40 @@ export default {
// 计算费用明细 // 计算费用明细
totalPrice() { totalPrice() {
let self = this // let self = this
self._post( // self._post(
'ground.ground/countPrice', // 'ground.ground/countPrice',
{ // {
app_id: self.getAppId(), // app_id: self.getAppId(),
room_id: self.id, // room_id: self.id,
nums: this.countSelectedTime, // nums: this.countSelectedTime,
type_id: self.venue.type_id, // type_id: self.venue.type_id,
}, // day: this.selectedWeekTimes,
function(res) { // room_msg: JSON.stringify(this.roomSelectList)
const result = res.data.lists // },
self.bill = { // function(res) {
total: result.order_amount, // const result = res.data.lists
cdf: { // self.bill = {
nums: result.nums, // total: result.order_amount,
price: result.room_price, // cdf: {
total: result.room_all_price // nums: result.nums,
}, // price: result.room_price,
dgf: { // total: result.room_all_price
nums: result.nums, // },
price: result.light_price, // dgf: {
total: result.light_all_price // 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; this.showPrice = true;
}, },
// 篮球场-立即预约 // 立即预约
toReserve() { toReserve() {
let self = this let self = this
// 一进来就锁定,彻底防止高频点击 // 一进来就锁定,彻底防止高频点击
@ -451,6 +461,12 @@ export default {
mask: true, mask: true,
}); });
try { 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( self._post(
'order.groundOrder/submitStoreOrder', 'order.groundOrder/submitStoreOrder',
@ -458,12 +474,16 @@ export default {
app_id: self.getAppId(), app_id: self.getAppId(),
ground_id: self.id, ground_id: self.id,
room_list: JSON.stringify(self.selectedReserveTime), room_list: JSON.stringify(self.selectedReserveTime),
type: this.typeId, type: self.typeId,
start_end: self.selectedReserveTime[0].start_time + '-' + self.selectedReserveTime[self.selectedReserveTime.length -1].end_time start_end: startTimestamp + '-' + endTimestamp,
amount_price: self.bill.total
}, },
function(res) { function(res) {
self.loadding = false; self.loadding = false;
if(res.code) { if(res.code) {
// 记录费用明细到缓存中
// uni.setStorageSync('billDetail', JSON.stringify(self.bill));
uni.$on('payment', params => { uni.$on('payment', params => {
console.log("🚀 ~ params:", params) console.log("🚀 ~ params:", params)
uni.showLoading({ uni.showLoading({
@ -511,11 +531,17 @@ export default {
url: `/bundle/reserve/confirm?venueId=${self.venue.id}&roomId=${self.id}&typeId=${self.typeId}` url: `/bundle/reserve/confirm?venueId=${self.venue.id}&roomId=${self.id}&typeId=${self.typeId}`
}); });
} }
}, },
/**
*
* @param title
* @param time
* @param status
*/
handleSelectTime(title, time, status) { handleSelectTime(title, time, status) {
if (status == 1) { let self = this
if (status == 1) {
return; return;
} }
// 多选逻辑selectedTime为对象按title区分 // 多选逻辑selectedTime为对象按title区分
@ -530,16 +556,27 @@ export default {
// 未选中则添加 // 未选中则添加
this.selectedTime[title].push(time); this.selectedTime[title].push(time);
} }
this.countSelectedTime = Object.values(this.selectedTime).reduce((acc, times) => acc + times.length, 0); this.countSelectedTime = Object.values(this.selectedTime).reduce((acc, times) => acc + times.length, 0);
this.totalPrice()
// 遍历所有已选时间,生成 room_list // 遍历所有已选时间,生成 room_list
const room_list = []; const room_list = [];
let totalPrice = 0;
let totalLightPrice = 0;
let amount_price = 0;
Object.keys(this.selectedTime).forEach(roomTitle => { Object.keys(this.selectedTime).forEach(roomTitle => {
const roomId = this.cdList.find(cd => cd.title === roomTitle)?.room_id; 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 => { 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', 需拆分 // t 可能是 '09:00-10:00' 或 '09:00', 需拆分
let start_time = t, end_time = ''; let start_time = t, end_time = '';
if (t.includes('-')) { if (t.includes('-')) {
@ -557,24 +594,73 @@ export default {
day_time: this.selectedWeekTimes, day_time: this.selectedWeekTimes,
start_time, start_time,
end_time, end_time,
room_price: timeObj ? timeObj.price : 0,
light_price: timeObj ? timeObj.light_price : 0,
amount_price,
}); });
}); });
}); });
this.selectedReserveTime = room_list; 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) { selectWeek(item, index) {
let self = this let self = this
self.currentWeek = index self.currentWeek = index
self.selectedWeekDay = item.value[1] + '' + item.value[0] self.selectedWeekDay = item.value[1] + '' + item.value[0]
self.selectedWeekTimes = item.times 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.selectedTime = []
self.selectedReserveTime = []
self.getReserveTime() self.getReserveTime()
}, },
// 获取预定时间
getReserveTime() { getReserveTime() {
let self = this; let self = this;
let params = {} let params = {}
@ -601,8 +687,13 @@ export default {
self.timeList = res.data.lists3 self.timeList = res.data.lists3
// 初始化选择的时间 // 初始化选择的时间
self.selectedWeekDay = res.data.lists2[0].value[1] + '' + res.data.lists2[0].value[0] if (!self.selectedWeekDay) {
self.selectedWeekTimes = res.data.lists2[0].times 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 self.loadding = false
} }

View File

@ -1,7 +1,7 @@
{ {
"name" : "星及茗茶", "name" : "秀湖网球中心",
"appid" : "__UNI__0C79E17", "appid" : "__UNI__A95F43A",
"description" : "星及茗茶", "description" : "秀湖网球中心",
"versionName" : "2.0.1", "versionName" : "2.0.1",
"versionCode" : 201, "versionCode" : 201,
"transformPx" : false, "transformPx" : false,
@ -153,7 +153,7 @@
"minified" : true "minified" : true
}, },
"usingComponents" : true, "usingComponents" : true,
"requiredPrivateInfos" : [ "getLocation" ], "requiredPrivateInfos" : [ "getLocation" ],
"permission" : { "permission" : {
"scope.userLocation" : { "scope.userLocation" : {
"desc" : "获取您与体育场馆的距离" "desc" : "获取您与体育场馆的距离"

View File

@ -440,13 +440,17 @@
self.cancelReservePopup = false; self.cancelReservePopup = false;
if(res.code) { if(res.code) {
uni.hideLoading();
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
duration: 2000, duration: 2000,
icon: 'success' icon: 'success'
}); });
self.getData(); setTimeout(() => {
uni.hideLoading();
self.getData();
}, 500);
} else {
uni.hideLoading();
} }
} }
); );