添加储值卡消费

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

@ -189,6 +189,37 @@
</view>
</view>
</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>
@ -296,19 +327,33 @@
</view>
<view class="icon-box d-c-c"><span class="icon iconfont icon-xuanze"></span></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="icon-box d-c-c mr10"><span class="icon iconfont icon-yue"></span></view>
<text class="key">平台余额</text>
</view>
<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() }} <text style="color: #FF5951;">{{ userDiscount }}</text>
</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 == '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>
@ -377,11 +422,15 @@
loadding: true,
_submitting: false,
balancePopup: false,
storedCardPopup: false,
balance: {},
userBalance: {},
currentType: '', // 选择的会员卡类型
storedCardList: [],
currentStoredCardId: '',
userAccount: 0,
userDiscount: 0
userDiscount: 0,
storedValueCard: []
};
},
@ -402,7 +451,7 @@
this.typeId = args.typeId || 1; // 网球场1 篮球场2
// this.basketballDate = args.date || null; // 篮球场预约时间
this.getData();
this.getRecharge()
this.getRecharge();
},
onUnload() {
@ -604,17 +653,17 @@
payTypeFunc(n) {
this.payType = n;
if (n == 'balance') {
this.resetPayDiscount();
this.balancePopup = true;
} else {
// 切换到微信支付时还原价格
this.userAccount = 0;
this.userDiscount = 0;
this.currentType = '';
if (typeof this.originalTotal === 'number' && !isNaN(this.originalTotal)) {
this.bill.total = this.originalTotal;
this.bill.dis = 0;
}
this.storedCardPopup = false;
} else if (n == 'storedCard') {
this.resetPayDiscount();
this.balancePopup = false;
this.storedCardPopup = true;
} else {
this.resetPayDiscount();
this.balancePopup = false;
this.storedCardPopup = false;
}
},
@ -656,6 +705,19 @@
};
oldBalancePay.call(this);
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 {
finish();
}
@ -814,6 +876,7 @@
},
function(res) {
self.balance = res.data.lists.balance;
self.storedValueCard = res.data.lists.storedValueCard;
}
)
@ -823,11 +886,43 @@
}, function(res) {
console.log("🚀 ~ res:", res)
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;
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() {
if (this.currentType == 1) {
return '白银会员卡'
@ -878,12 +973,144 @@
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() {
this.resetPayDiscount();
this.payType = 'wxpay';
this.balancePopup = false;
},
closeStoredCardPopup() {
this.resetPayDiscount();
this.payType = 'wxpay';
this.storedCardPopup = false;
},
},
};