完善功能

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 class="title2 d-b-c">
<view>场地费(¥{{ bill.cdf.price }}元/小时)</view>
<!-- <view>场地费(¥{{ bill.cdf.price }}元/小时)</view> -->
<view>小时</view>
<view>x{{ bill.cdf.nums }}</view>
</view>
</view>
@ -46,7 +47,8 @@
</view>
</view>
<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>
</view>
@ -56,7 +58,7 @@
<view class="title1 d-b-c">
<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>
@ -76,7 +78,7 @@
<view class="d-f d-c j-c-b">
<view>
合计: <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 class="d-f j-c-c a-i-c" style="margin-top: 10rpx;" @click="closeBillPopup">
<view class="price-detail">费用明细</view>
@ -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;
}
}