添加储值卡消费

This commit is contained in:
wangxiaowei
2026-05-08 10:41:30 +08:00
parent aed08c445e
commit 4d62d1bd04
2 changed files with 426 additions and 40 deletions

View File

@ -190,6 +190,37 @@
</view> </view>
</Popup> </Popup>
<!-- 储值卡选择弹窗 -->
<Popup :show="storedCardPopup" :width='750' :padding="0" type="bottom" backgroundColor="#fff" radius="32rpx 32rpx 0 0">
<view class="ww100 box-s-b pop-improt typeof pr">
<image style="width: 64rpx;height: 64rpx;position: absolute; top: 26rpx;right: 30rpx;" src="@/static/icon/close2.png" mode="" @click="closeStoredCardPopup"></image>
<view class="d-c-c pt44">
<text class="f34 fb">储值卡选择</text>
</view>
<view class="bg-white card">
<view class="card-item" v-for="item in storedCardList" :key="item.id" :class="currentStoredCardId == item.id ? 'active' : ''" @click="currentStoredCardId = item.id">
<view class="d-f a-i-c">
<view class="card-title">{{ item.name }}</view>
<view class="d-f a-i-c">
<view class="discount">享</view>
<view class="sale">
<text>{{ item.discount }}</text>
<text>折</text>
</view>
</view>
</view>
<view class="d-f a-i-c">
<view class="card-balance">¥{{ formatMoney(item.balance) }}</view>
<view class="icon-box d-c-c card-checkout"><span class="icon iconfont icon-xuanze"></span></view>
</view>
</view>
<view class="card-btn" @click="confirmStoredCard">确定</view>
</view>
</view>
</Popup>
<navbar title="确认订单"></navbar> <navbar title="确认订单"></navbar>
<!-- 预约信息 --> <!-- 预约信息 -->
@ -296,19 +327,33 @@
</view> </view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view> <view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view> </view>
<view v-if="typeId == 1" :class="payType == 'balance' ? 'item active' : 'item'" @tap="payTypeFunc('balance')"> <view v-if="typeId == 1" :class="payType == 'balance' ? 'item active' : 'item'" @tap="payTypeFunc('balance')" style="padding-bottom: 10rpx;">
<view class="d-s-c"> <view class="d-s-c">
<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view> <view class="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view>
<text class="key">平台余额</text> <text class="key">平台余额</text>
</view> </view>
<view class="d-f a-i-c"> <view class="d-f a-i-c">
<view class="mr10 dis" v-if="userAccount > 0"> <view class="mr10 dis" v-if="payType == 'balance' && userAccount > 0">
<!-- <text class="key">余额支付(剩余{{balance}})</text> --> <!-- <text class="key">余额支付(剩余{{balance}})</text> -->
{{ cardType() }} <text style="color: #FF5951;">{{ userDiscount }}</text> {{ cardType() }} <text style="color: #FF5951;">{{ userDiscount }}</text>
</view> </view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view> <view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view> </view>
</view> </view>
<view v-if="typeId == 1" :class="payType == 'storedCard' ? 'item active' : 'item'" @tap="payTypeFunc('storedCard')">
<view class="d-s-c">
<view class="icon-box d-c-c mr10">
<image src="https://xh.stnav.com/uploads/sport/chuzhika.png" mode="heightFix" style="width: 50rpx; height: 50rpx;"></image>
</view>
<text class="key">储值卡支付</text>
</view>
<view class="d-f a-i-c">
<view class="mr10 dis" v-if="payType == 'storedCard' && userAccount > 0">
{{ storedCardName() }} <text style="color: #FF5951;margin-left: 10rpx;">{{ userDiscount }}</text>
</view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view>
</view>
</view> </view>
</view> </view>
@ -377,11 +422,15 @@
loadding: true, loadding: true,
_submitting: false, _submitting: false,
balancePopup: false, balancePopup: false,
storedCardPopup: false,
balance: {}, balance: {},
userBalance: {}, userBalance: {},
currentType: '', // 选择的会员卡类型 currentType: '', // 选择的会员卡类型
storedCardList: [],
currentStoredCardId: '',
userAccount: 0, userAccount: 0,
userDiscount: 0 userDiscount: 0,
storedValueCard: []
}; };
}, },
@ -402,7 +451,7 @@
this.typeId = args.typeId || 1; // 网球场1 篮球场2 this.typeId = args.typeId || 1; // 网球场1 篮球场2
// this.basketballDate = args.date || null; // 篮球场预约时间 // this.basketballDate = args.date || null; // 篮球场预约时间
this.getData(); this.getData();
this.getRecharge() this.getRecharge();
}, },
onUnload() { onUnload() {
@ -604,17 +653,17 @@
payTypeFunc(n) { payTypeFunc(n) {
this.payType = n; this.payType = n;
if (n == 'balance') { if (n == 'balance') {
this.resetPayDiscount();
this.balancePopup = true; this.balancePopup = true;
} else { this.storedCardPopup = false;
// 切换到微信支付时还原价格 } else if (n == 'storedCard') {
this.userAccount = 0; this.resetPayDiscount();
this.userDiscount = 0;
this.currentType = '';
if (typeof this.originalTotal === 'number' && !isNaN(this.originalTotal)) {
this.bill.total = this.originalTotal;
this.bill.dis = 0;
}
this.balancePopup = false; this.balancePopup = false;
this.storedCardPopup = true;
} else {
this.resetPayDiscount();
this.balancePopup = false;
this.storedCardPopup = false;
} }
}, },
@ -656,6 +705,19 @@
}; };
oldBalancePay.call(this); oldBalancePay.call(this);
setTimeout(finish, 3000); setTimeout(finish, 3000);
} else if (this.payType == 'storedCard') {
if (this.currentStoredCardId === '') {
uni.showToast({title: '请选择储值卡', icon: 'none'});
setTimeout(finish, 3000);
return;
}
const oldStoredCardPay = this.storedCardPay;
this.storedCardPay = (...args) => {
oldStoredCardPay.apply(this, args);
this.storedCardPay = oldStoredCardPay;
};
oldStoredCardPay.call(this);
setTimeout(finish, 3000);
} else { } else {
finish(); finish();
} }
@ -814,6 +876,7 @@
}, },
function(res) { function(res) {
self.balance = res.data.lists.balance; self.balance = res.data.lists.balance;
self.storedValueCard = res.data.lists.storedValueCard;
} }
) )
@ -823,11 +886,43 @@
}, function(res) { }, function(res) {
console.log("🚀 ~ res:", res) console.log("🚀 ~ res:", res)
self.userBalance = res.data.userInfo; self.userBalance = res.data.userInfo;
self.storedCardList = [
{ id: 1, payType: 1, name: '储值卡一', discount: self.storedValueCard.discount1, balance: self.userBalance.card_balance1 },
{ id: 2, payType: 2, name: '储值卡二', discount: self.storedValueCard.discount2, balance: self.userBalance.card_balance2 },
{ id: 3, payType: 3, name: '储值卡三', discount: self.storedValueCard.discount3, balance: self.userBalance.card_balance3 },
];
self.loadding = false; self.loadding = false;
uni.hideLoading(); uni.hideLoading();
}); });
}, },
formatMoney(value) {
const amount = Number(value) || 0;
return amount.toFixed(2);
},
getStoredCardInfo() {
return this.storedCardList.find(item => item.id === this.currentStoredCardId);
},
storedCardName() {
const currentCard = this.getStoredCardInfo();
return currentCard ? currentCard.name : '';
},
resetPayDiscount() {
this.userAccount = 0;
this.userDiscount = 0;
this.currentType = '';
this.currentStoredCardId = '';
if (typeof this.originalTotal === 'number' && !isNaN(this.originalTotal)) {
this.bill.total = this.originalTotal;
this.bill.dis = 0;
}
},
cardType() { cardType() {
if (this.currentType == 1) { if (this.currentType == 1) {
return '白银会员卡' return '白银会员卡'
@ -878,12 +973,144 @@
this.balancePopup = false; this.balancePopup = false;
}, },
confirmStoredCard() {
if (this.currentStoredCardId === '') {
uni.showToast({
title: '请选择储值卡',
icon: 'none'
});
return;
}
const currentCard = this.getStoredCardInfo();
if (!currentCard) {
uni.showToast({
title: '储值卡不存在',
icon: 'none'
});
return;
}
this.userAccount = Number(currentCard.balance);
this.userDiscount = Number(currentCard.discount) || 10;
const baseTotal = Number(this.bill.cdf.total) || 0;
const finalPrice = Number((baseTotal * (this.userDiscount / 10)).toFixed(2));
const payableTotal = Number((finalPrice + Number(this.bill.dgf.total)).toFixed(2));
if (this.userAccount < payableTotal) {
uni.showToast({
title: '储值卡余额不足,请选择其他储值卡',
icon: 'none'
});
return;
}
this.bill.dis = Number((baseTotal - finalPrice).toFixed(2));
this.bill.total = payableTotal;
this.storedCardPopup = false;
},
storedCardPay() {
let self = this
const currentCard = self.getStoredCardInfo();
if (!currentCard) {
uni.showToast({
title: '请选择储值卡',
icon: 'none'
});
return;
}
if (Number(currentCard.balance) < Number(self.bill.total)) {
uni.showToast({
title: '储值卡余额不足',
icon: 'none'
});
return;
}
uni.showLoading({
title: '支付中'
});
try {
self._post(
'ground.ground/yuexnPay',
{
app_id: self.getAppId(),
order_id: self.orderId,
pay_type: currentCard.payType // 传储值卡对应的pay_type
},
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);
}
}
)
} catch (error) {
self.result = 'fail'
self.loadding = false;
uni.showToast({
title: '支付失败',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({delta: 1})
}, 500);
}
// setTimeout(() => {
// currentCard.balance = Number((Number(currentCard.balance) - Number(this.bill.total)).toFixed(2));
// this.userAccount = currentCard.balance;
// this.result = 'success';
// this.loadding = false;
// uni.hideLoading();
// uni.showToast({
// title: '储值卡支付成功',
// icon: 'none'
// });
// setTimeout(() => {
// uni.navigateBack({delta: 1});
// }, 500);
// }, 300);
},
// 关闭余额支付弹窗 // 关闭余额支付弹窗
closeBalancePopup() { closeBalancePopup() {
this.resetPayDiscount();
this.payType = 'wxpay'; this.payType = 'wxpay';
this.balancePopup = false; this.balancePopup = false;
}, },
closeStoredCardPopup() {
this.resetPayDiscount();
this.payType = 'wxpay';
this.storedCardPopup = false;
},
}, },
}; };

View File

@ -138,19 +138,32 @@
</view> </view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view> <view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view> </view>
<view :class="payType == 'balance' ? 'item active' : 'item'" @tap="payTypeFunc('balance')"> <view :class="payType == 'balance' ? 'item active' : 'item'" @tap="payTypeFunc('balance')" style="padding-bottom: 10rpx;">
<view class="d-s-c"> <view class="d-s-c">
<view class="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view> <view class="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view>
<text class="key">平台余额</text> <text class="key">平台余额</text>
</view> </view>
<view class="d-f a-i-c"> <view class="d-f a-i-c">
<view class="mr10 dis" v-if="userAccount > 0"> <view class="mr10 dis" v-if="payType == 'balance' && userAccount > 0">
<!-- <text class="key">余额支付(剩余{{balance}})</text> --> {{ cardType() }}
{{ cardType() }}
</view> </view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view> <view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view> </view>
</view> </view>
<view :class="payType == 'storedCard' ? 'item active' : 'item'" @tap="payTypeFunc('storedCard')">
<view class="d-s-c">
<view class="icon-box d-c-c mr10">
<image src="https://xh.stnav.com/uploads/sport/chuzhika.png" mode="heightFix" style="width: 50rpx; height: 50rpx;"></image>
</view>
<text class="key">储值卡支付</text>
</view>
<view class="d-f a-i-c">
<view class="mr10 dis" v-if="payType == 'storedCard' && userAccount > 0">
{{ storedCardName() }}
</view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></view>
</view>
</view>
</view> </view>
<view class="pay-light-btn" @click="getSelectedContent">确定并支付</view> <view class="pay-light-btn" @click="getSelectedContent">确定并支付</view>
@ -200,12 +213,12 @@
<text class="cg-copy" @click="copy(detail.order_sn)">复制</text> <text class="cg-copy" @click="copy(detail.order_sn)">复制</text>
</view> </view>
</view> </view>
<view class="cg-order-info d-b-c mt14" v-if="detail.pay_way > 0"> <view class="cg-order-info d-b-c mt14" v-if="detail.pay_way > 0">
<view class="">交易方式</view> <view class="">交易方式</view>
<view class=""> <view class="">
<text v-if="detail.pay_way == 1">余额支付-{{ cardType(detail.pay_way) }}</text> <text v-if="detail.pay_way == 1">余额支付-{{ cardType(detail.pay_type) }}</text>
<text v-if="detail.pay_way == 2">微信支付</text> <text v-if="detail.pay_way == 2">微信支付</text>
<text v-if="detail.pay_way == 3">储值卡支付-{{ storedCardType(detail.pay_xntype) }}</text>
</view> </view>
</view> </view>
@ -396,6 +409,30 @@
</view> </view>
</view> </view>
</Popup> </Popup>
<!-- 储值卡选择弹窗 -->
<Popup :show="storedCardPopup" :width='750' :padding="0" type="bottom" backgroundColor="#fff" radius="32rpx 32rpx 0 0">
<view class="ww100 box-s-b pop-improt typeof pr">
<image style="width: 64rpx;height: 64rpx;position: absolute; top: 26rpx;right: 30rpx;" src="@/static/icon/close2.png" mode="" @click="closeStoredCardPopup"></image>
<view class="d-c-c pt44">
<text class="f34 fb">储值卡选择</text>
</view>
<view class="bg-white card">
<view class="card-item" v-for="item in storedCardList" :key="item.id" :class="currentStoredCardId == item.id ? 'active' : ''" @click="currentStoredCardId = item.id">
<view class="d-f a-i-c">
<view class="card-title">{{ item.name }}</view>
</view>
<view class="d-f a-i-c">
<view class="card-balance">{{ formatMoney(item.balance) }}</view>
<view class="icon-box d-c-c card-checkout"><span class="icon iconfont icon-xuanze"></span></view>
</view>
</view>
<view class="card-btn" @click="confirmStoredCard">确定</view>
</view>
</view>
</Popup>
</view> </view>
</template> </template>
@ -448,6 +485,10 @@
currentType: '', // 选择的会员卡类型 currentType: '', // 选择的会员卡类型
userAccount: 0, userAccount: 0,
userDiscount: 0, userDiscount: 0,
storedCardPopup: false,
storedCardList: [],
currentStoredCardId: '',
storedValueCard: [],
lightDateTime: '', lightDateTime: '',
lightPrice: 0, lightPrice: 0,
}; };
@ -670,19 +711,31 @@
// 会员卡类型 // 会员卡类型
cardType(type) { cardType(type) {
if (type == 1) { const t = type || this.currentType;
if (t == 1) {
return '白银会员卡' return '白银会员卡'
} else if (type == 2) { } else if (t == 2) {
return '黄金会员卡' return '黄金会员卡'
} else if (type == 3) { } else if (t == 3) {
return '铂金会员卡' return '铂金会员卡'
} else if (type == 4) { } else if (t == 4) {
return '钻石会员卡' return '钻石会员卡'
} else if (type == 5) { } else if (t == 5) {
return '至尊会员卡' return '至尊会员卡'
} }
}, },
// 储值卡类型
storedCardType(type) {
if (type == 1) {
return '储值卡一'
} else if (type == 2) {
return '储值卡二'
} else if (type == 3) {
return '储值卡三'
}
},
/** /**
* 购买灯光前置条件 * 购买灯光前置条件
*/ */
@ -708,13 +761,25 @@
payTypeFunc(n) { payTypeFunc(n) {
this.payType = n; this.payType = n;
if (n == 'balance') { if (n == 'balance') {
this.userAccount = 0;
this.userDiscount = 0;
this.currentStoredCardId = '';
this.balancePopup = true; this.balancePopup = true;
this.storedCardPopup = false;
} else if (n == 'storedCard') {
this.userAccount = 0;
this.userDiscount = 0;
this.currentType = '';
this.balancePopup = false;
this.storedCardPopup = true;
} else { } else {
// 切换到微信支付时还原价格 // 切换到微信支付时还原价格
this.userAccount = 0; this.userAccount = 0;
this.userDiscount = 0; this.userDiscount = 0;
this.currentType = ''; this.currentType = '';
this.currentStoredCardId = '';
this.balancePopup = false; this.balancePopup = false;
this.storedCardPopup = false;
} }
}, },
@ -724,6 +789,49 @@
this.balancePopup = false; this.balancePopup = false;
}, },
closeStoredCardPopup() {
this.payType = 'wxpay';
this.storedCardPopup = false;
},
formatMoney(value) {
const amount = Number(value) || 0;
return amount.toFixed(2);
},
getStoredCardInfo() {
return this.storedCardList.find(item => item.id === this.currentStoredCardId);
},
storedCardName() {
const currentCard = this.getStoredCardInfo();
return currentCard ? currentCard.name : '';
},
confirmStoredCard() {
if (this.currentStoredCardId === '') {
uni.showToast({
title: '请选择储值卡',
icon: 'none'
});
return;
}
const currentCard = this.getStoredCardInfo();
if (!currentCard) {
uni.showToast({
title: '储值卡不存在',
icon: 'none'
});
return;
}
this.userAccount = Number(currentCard.balance);
this.userDiscount = 0;
this.storedCardPopup = false;
},
getRecharge() { getRecharge() {
let self = this; let self = this;
uni.showLoading({ uni.showLoading({
@ -737,6 +845,7 @@
}, },
function(res) { function(res) {
self.balance = res.data.lists.balance; self.balance = res.data.lists.balance;
self.storedValueCard = res.data.lists.storedValueCard;
} }
) )
@ -746,6 +855,13 @@
}, function(res) { }, function(res) {
console.log("🚀 ~ res:", res) console.log("🚀 ~ res:", res)
self.userBalance = res.data.userInfo; self.userBalance = res.data.userInfo;
self.storedCardList = [
{ id: 1, payType: 1, name: '储值卡一', discount: self.storedValueCard.discount1, balance: self.userBalance.card_balance1 },
{ id: 2, payType: 2, name: '储值卡二', discount: self.storedValueCard.discount2, balance: self.userBalance.card_balance2 },
{ id: 3, payType: 3, name: '储值卡三', discount: self.storedValueCard.discount3, balance: self.userBalance.card_balance3 },
];
self.loadding = false; self.loadding = false;
uni.hideLoading(); uni.hideLoading();
}); });
@ -771,27 +887,13 @@
this.userAccount = this.userBalance['balance' + this.currentType]; this.userAccount = this.userBalance['balance' + this.currentType];
this.userDiscount = this.balance['discount' + this.currentType]; this.userDiscount = 0;
// this.payType = this.currentType; // this.payType = this.currentType;
// this.countPrice(); // this.countPrice();
this.balancePopup = false; this.balancePopup = false;
}, },
cardType() {
if (this.currentType == 1) {
return '白银会员卡'
} else if (this.currentType == 2) {
return '黄金会员卡'
} else if (this.currentType == 3) {
return '铂金会员卡'
} else if (this.currentType == 4) {
return '钻石会员卡'
} else if (this.currentType == 5) {
return '至尊会员卡'
}
},
isSelected(groupIdx, idx) { isSelected(groupIdx, idx) {
return this.selectedTimes.some(sel => sel.group === groupIdx && sel.idx === idx); return this.selectedTimes.some(sel => sel.group === groupIdx && sel.idx === idx);
}, },
@ -932,9 +1034,18 @@
return; return;
} }
if (self.payType == 'storedCard' && self.currentStoredCardId === '') {
uni.showToast({
title: '请选择储值卡',
icon: 'none'
});
return;
}
uni.showLoading({ uni.showLoading({
title: '正在处理' title: '正在处理'
}); });
console.log('self.payType=', self.payType)
console.log(123123) console.log(123123)
self._post( self._post(
'order.GroundOrder/addLightStoreOrder', { 'order.GroundOrder/addLightStoreOrder', {
@ -1034,6 +1145,54 @@
self.getRecharge(); self.getRecharge();
}, 1500); }, 1500);
} else {
self.openLightPopup = false;
console.log("🚀 ~ pay error res:", res)
self.result = 'fail'
uni.hideLoading();
setTimeout(() => {
uni.showToast({
title: '支付失败',
icon: 'none'
});
}, 200);
setTimeout(() => {
self.getData();
self.getRecharge();
}, 1500);
}
}
)
} else if (self.payType == 'storedCard') {
const currentCard = self.getStoredCardInfo();
console.log("🚀 ~ getStoredCardInfo:", 12312312321)
self._post(
'ground.ground/yuexnLightPay', {
order_id: payId,
pay_type: currentCard.payType
},
function(pay) {
if (pay.code == 1) {
self.openLightPopup = false;
self.selectedTimes = []
self.content = []
self.result = 'success'
uni.hideLoading();
setTimeout(() => {
uni.showToast({
title: '支付成功',
icon: 'none'
});
}, 200);
setTimeout(() => {
self.getData();
self.getRecharge();
}, 1500);
} else { } else {
self.openLightPopup = false; self.openLightPopup = false;