完善订单页面

This commit is contained in:
wangxiaowei
2025-12-08 01:37:33 +08:00
parent becadb1d0c
commit 4a0d0c1114
6 changed files with 348 additions and 141 deletions

View File

@ -54,10 +54,10 @@
<!-- 使用余额支付优惠的折扣 -->
<view style="margin-top: 52rpx;" v-if="bill.dis">
<view class="title1 d-b-c">
<view style="color: #4C9F44;">优惠</view>
<view>折扣优惠</view>
<view>
<text style="margin-right: 6rpx;"> - </text>
<price-format color="#303133" :subscript-size="30" :first-size="30" :second-size="30" :price="bill.dis"></price-format>
<text style="margin-right: 6rpx;color: #FA2B21;"> - </text>
<price-format color="#FA2B21" :subscript-size="30" :first-size="30" :second-size="30" :price="bill.dis"></price-format>
</view>
</view>
</view>
@ -75,8 +75,9 @@
<view class="price2 bg-white" style="margin: 0; padding: 56rpx 22rpx 42rpx;">
<view class="d-b-c price-block" style="margin: 0;">
<view class="d-f d-c j-c-b">
<view class="">
<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;">8折</text>
</view>
<view class="d-f j-c-c a-i-c" style="margin-top: 10rpx;" @click="closeBillPopup">
<view class="price-detail">费用明细</view>
@ -171,7 +172,7 @@
<view :class="payType == 'wxpay' ? 'item active' : 'item'" @tap="payTypeFunc('wxpay')" style="padding-bottom: 10rpx;">
<view class="d-s-c">
<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-weixin"></span></view>
<text class="key">微信支付</text>
<text class="key">微信支付</text>
</view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view>
@ -244,6 +245,9 @@
payType: 'wxpay', // 支付方式 wxpay\balance
balance: 0,
order: {},
result: '',
loadding: true,
_submitting: false
};
},
@ -257,6 +261,17 @@
this.getData();
},
onUnload() {
switch(this.result) {
case 'success':
uni.$emit('payment', { result: true, order_id: this.orderId })
break;
case 'fail':
default: uni.$emit('payment', { result: false, order_id: this.orderId })
}
},
methods: {
getData() {
let self = this;
@ -264,12 +279,12 @@
title: '加载中'
});
const reserveDate = uni.getStorageSync('reserveDate') || null
self.date = reserveDate
self.countSelectedTime = reserveDate && reserveDate.duration ? reserveDate.duration : 0
if (self.typeId == 2) {
self.countSelectedTime = 4
}
// const reserveDate = uni.getStorageSync('reserveDate') || null
// self.date = reserveDate
// self.countSelectedTime = reserveDate && reserveDate.duration ? reserveDate.duration : 0
// if (self.typeId == 2) {
// self.countSelectedTime = 4
// }
// 获取余额
self._post(
@ -372,7 +387,6 @@
total: result.light_all_price
}
}
console.log("🚀 ~ self.bill:", self.bill)
self.loadding = false;
}
@ -401,58 +415,158 @@
// 去支付
toConfirm() {
if (this._submitting) return;
this._submitting = true;
if (this.countSelectedTime === 0) {
uni.showToast({title: '请选择时间后再预定', icon: 'none'});
this._submitting = false;
return;
}
const finish = () => { this._submitting = false; };
if (this.payType == 'wxpay') {
// 包装原有回调,确保无论成功失败都解锁
const oldWxPay = this.wxPay;
this.wxPay = (...args) => {
oldWxPay.apply(this, args);
this.wxPay = oldWxPay;
};
oldWxPay.call(this);
setTimeout(finish, 3000); // 兜底3秒自动解锁
} else if (this.payType == 'balance') {
const oldBalancePay = this.balancePay;
this.balancePay = (...args) => {
oldBalancePay.apply(this, args);
this.balancePay = oldBalancePay;
};
oldBalancePay.call(this);
setTimeout(finish, 3000);
} else {
finish();
}
},
// 微信支付
wxPay() {
let self = this;
uni.showLoading({
title: '加载中'
});
self._post(
'order.groundOrder/submitStoreOrder',
{
app_id: self.getAppId(),
ground_id: self.venueId,
room_id: self.roomId,
hours: 1,
day_time: self.date ? self.date.date : '',
start_time: self.date ? self.date.startTime : '',
end_time: self.date ? self.date.endTime : '',
},
function(res) {
console.log("🚀 ~ order res:", res)
self._post(
'user.groundOrder/pay',
{
app_id: self.getAppId(),
order_id: res.data.lists.id
},
function(res) {
const data = res.data
console.log("🚀 ~ pay data:", data)
uni.requestPayment({
provider: 'wxpay',
timeStamp: data.payment.timeStamp,
nonceStr: data.payment.nonceStr,
package: 'prepay_id=' + data.payment.prepay_id,
signType: 'MD5',
paySign: data.payment.paySign,
success: res => {
console.log("🚀 ~ pay success res:", res)
},
fail: res => {
console.log("🚀 ~ pay fail res:", res)
uni.reLaunch({
url: '/pages/order/cg-my-order',
});
},
try {
self._post(
'user.groundOrder/pay',
{
app_id: self.getAppId(),
order_id: this.orderId
},
function(res) {
const data = res.data
console.log("🚀 ~ pay data:", data)
uni.requestPayment({
provider: 'wxpay',
timeStamp: data.payment.timeStamp,
nonceStr: data.payment.nonceStr,
package: 'prepay_id=' + data.payment.prepay_id,
signType: 'MD5',
paySign: data.payment.paySign,
success: res => {
self.result = 'success'
console.log("🚀 ~ pay success res:", res)
uni.showToast({
title: '支付成功',
icon: 'none'
});
self.loadding = false;
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
},
fail: res => {
console.log("🚀 ~ pay error res:", res)
self.result = 'fail'
self.loadding = false;
uni.showToast({
title: '支付失败',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
},
});
}
)
} catch (error) {
console.log("🚀 ~ pay error res:", res)
self.result = 'fail'
self.loadding = false;
uni.showToast({
title: '支付失败',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
}
},
// 余额支付
balancePay() {
let self = this;
uni.showLoading({
title: '加载中'
});
try {
self._post(
'ground.ground/yuePay',
{
app_id: self.getAppId(),
order_id: this.orderId
},
function(res) {
if (res.code == 1) {
self.result = 'success'
uni.showToast({
title: '支付成功',
icon: 'none'
});
self.loadding = false;
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
} else {
self.result = 'fail'
self.loadding = false;
uni.showToast({
title: '支付失败',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
}
)
self.loadding = false;
}
)
}
)
} catch (error) {
self.result = 'fail'
self.loadding = false;
uni.showToast({
title: '支付失败',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
}
}
}
};

View File

@ -280,7 +280,6 @@ export default {
selectedWeekDay: '',
selectedReserveTime: [],
countSelectedTime: 0,
submitting: false // 防止重复提交
};
},
@ -437,22 +436,14 @@ export default {
// 篮球场-立即预约
toReserve() {
let self = this
if (self.submitting) {
uni.showToast({
title: '正在提交,请勿重复操作',
icon: 'none'
});
return;
}
// 一进来就锁定,彻底防止高频点击
self.submitting = true;
if (self.typeId == 1) {
if (self.selectedReserveTime.length === 0) {
uni.showToast({
title: '请选择预约时间',
icon: 'none'
});
self.submitting = false;
return;
}
uni.showLoading({
@ -467,11 +458,32 @@ export default {
app_id: self.getAppId(),
ground_id: self.id,
room_list: JSON.stringify(self.selectedReserveTime),
type: this.typeId
},
function(res) {
self.loadding = false;
self.submitting = false;
if(res.code) {
uni.$on('payment', params => {
console.log("🚀 ~ params:", params)
uni.showLoading({
title: '加载中',
mask: true,
});
setTimeout(() => {
self.loadding = false
uni.$off("payment")
if (params.result) {
uni.redirectTo({
url: `/bundle/reserve/notice?order_id=${params.order_id}`
})
} else {
uni.redirectTo({
url: '/pages/order/cg-my-order'
})
}
}, 500)
})
uni.navigateTo({
url: `/bundle/reserve/confirm?venueId=${self.venue.id}&roomId=${self.id}&typeId=${self.typeId}&orderId=${res.data.lists.id}`
});
@ -479,7 +491,6 @@ export default {
}
)
} catch (error) {
self.submitting = false;
console.error('订单提交失败:', error);
uni.showToast({
title: '订单提交失败,请重试',
@ -493,13 +504,11 @@ export default {
title: '请选择预约时间',
icon: 'none'
});
self.submitting = false;
return;
}
uni.navigateTo({
url: `/bundle/reserve/confirm?venueId=${self.venue.id}&roomId=${self.id}&typeId=${self.typeId}`
});
self.submitting = false;
}
},
@ -616,13 +625,23 @@ export default {
getReserveTime() {
let self = this;
self._post(
'ground.ground/getSchedule',
{
let params = {}
if (self.selectedWeekTimes) {
params = {
app_id: self.getAppId(),
ground_id: self.id,
today: self.selectedWeekTimes
},
}
} else {
params = {
app_id: self.getAppId(),
ground_id: self.id,
}
}
self._post(
'ground.ground/getSchedule',params,
function (res) {
if (res.code) {
self.cdList = res.data.lists1

View File

@ -9,8 +9,8 @@
</view>
<view class="btn">
<view class="btn1">查看订单</view>
<view class="btn2">完成</view>
<view class="btn1" @click="seeOrder">查看订单</view>
<view class="btn2" @click="done">完成</view>
</view>
</view>
</template>
@ -19,18 +19,30 @@
export default {
data() {
return {
order_id: 0
};
},
onLoad(args) {
this.getData();
this.order_id = args.order_id || 0;
},
methods: {
getData() {
},
seeOrder() {
uni.navigateTo({
url: '/pages/order/cg-my-order'
});
},
done() {
uni.reLaunch({
url: '/pages/index/index'
});
}
}
};
</script>