商品券相关优化更新

This commit is contained in:
GaoHao
2024-11-21 09:46:04 +08:00
parent 8c5e03d6c4
commit f7a2f588ef
11 changed files with 613 additions and 578 deletions

View File

@@ -139,7 +139,9 @@
</view>
<!-- 充值免单 -->
<rechargeFree v-if="freeDingConfig.enable == 1&&storeInfo.registerType == 'munchies'" ref="rechargeFree" :freeDisabled="freeDisabled" :payAmount="listinfo.payAmount" :freeDingConfig="freeDingConfig" :shopUserInfo="amountVIP" @changeFree="changeFree"></rechargeFree>
<view style="padding: 0 20rpx;">
<rechargeFree v-if="freeDingConfig.enable == 1&&storeInfo.registerType == 'munchies'" ref="rechargeFree" :freeDisabled="freeDisabled" :payAmount="listinfo.payAmount" :freeDingConfig="freeDingConfig" :shopUserInfo="amountVIP" @changeFree="changeFree"></rechargeFree>
</view>
<!-- 充值活动 -->
<topUpActivity v-if="storeInfo.registerType == 'munchies'" ref="topUpActivity" :shopUserInfo="amountVIP" ></topUpActivity>
<!-- 支付方式 -->
@@ -224,6 +226,7 @@
phone: "",
},
userCouponInfos: [],
selectCouponData: [],
shopTableInfo: null,
freeDingConfig: null,
cartLists: [],
@@ -250,6 +253,7 @@
storeInfo: {},
tableCode: null,
packFee: null,
isShow: false,
}
},
computed: {
@@ -288,9 +292,9 @@
}
this.getProductqueryShop();
this.getchoseEatModel('index',0);
uni.cache.set('selectCouponData',[])
},
onShow() {
let _this = this;
if (this.listinfoid) {
uni.$on('message', this.getMessage)
this.orderorderInfo()
@@ -302,7 +306,12 @@
item.show = true;
}
})
uni.$on('couponItem',this.changeCoupon)
this.userCouponInfos = [];
this.favorable[0].value = ""
this.favorable[1].value = []
this.selectCouponData = uni.cache.get('selectCouponData') || []
},
methods: {
/**
@@ -310,40 +319,36 @@
* @param {Object} data
*/
changeCoupon ( data ) {
let _this = this;
// uni.$off('couponItem')
let couponData = JSON.parse(data)
console.log('监听到事件来自返回的参数:' , couponData);
if ( couponData.type == 1 ) { //满减优惠券
let couponList = _this.userCouponInfos.filter(v => v.type == 1);
// 优惠券数据
let couponList = this.selectCouponData.filter(v => v.type == 1);
// 商品券列表
let productList = this.selectCouponData.filter(v => v.type == 2);
// 优惠券处理
if ( couponList.length > 0 ) {
let couponData = couponList[0]
//不包含优惠券的金额
let currentPayAmount = (couponList.length > 0 ? _this.listinfo.payAmount + couponList[0].discountAmount : _this.listinfo.payAmount)
let currentPayAmount = (this.userCouponInfos.filter(v => v.type == 1).length > 0 ? Number(this.listinfo.payAmount) + couponData.discountAmount : this.listinfo.payAmount)
// 判断优惠金额不能大于支付金额
if ( couponData.discountAmount < currentPayAmount) {
_this.listinfo.payAmount = ( currentPayAmount - couponData.discountAmount).toFixed(2)
_this.favorable[0].value = ('-¥'+couponData.discountAmount)
if ( couponList.length > 0) {
_this.userCouponInfos.map(item => {
if ( item.type == 1 ) {
item.userCouponId = couponData.id
item.type = couponData.type
item.discountAmount = couponData.discountAmount
item.num = couponData.type == 1 ? 1 : couponData.num
}
})
if ( this.isPointsChecked ) {
this.listinfo.payAmount = (this.listinfo.payAmount-(this.calcUsablePointsData.pointsNum/this.calcUsablePointsData.equivalentPoints)).toFixed(2);
} else {
_this.favorable[0].value = ('-¥'+couponData.discountAmount)
_this.userCouponInfos.push({
userCouponId: couponData.id,
type: couponData.type,
discountAmount: couponData.discountAmount,
num: couponData.type == 1 ? 1 : couponData.num,
})
}
if ( _this.isPointsChecked) {
_this.pointsChange()
_this.getCalcUsablePoints()
this.listinfo.payAmount = (Number(this.listinfo.payAmount)+(this.calcUsablePointsData.pointsNum/this.calcUsablePointsData.equivalentPoints)).toFixed(2);
}
this.listinfo.payAmount = ( currentPayAmount - couponData.discountAmount).toFixed(2)
this.favorable[0].value = ('-¥'+couponData.discountAmount)
this.userCouponInfos.push({
userCouponId: couponData.id,
type: couponData.type,
discountAmount: couponData.discountAmount,
num: couponData.type == 1 ? 1 : couponData.num,
})
} else {
uni.showToast({
@@ -351,55 +356,76 @@
icon: "none",
})
}
} else { //商品券
// this.listinfo.details
// 筛选选中商品券商品列表
let couponList = _this.listinfo.details.filter(v => v.productId == couponData.proId);
//金额从小到大排序
let minCouponList = couponList.sort((a, b) => (a.memberPrice > 0 ? a.memberPrice : a.salePrice) - (b.memberPrice > 0 ? b.memberPrice : b.salePrice))
let productTicketList = _this.userCouponInfos.filter(v => v.productId == couponData.proId);
//商品券抵扣的数量
let productNum = couponData.num;
let productPayAmount = 0;
let productTicketNum = 0;
let productNumber = 0;
productTicketList.map((item,index) => {
productTicketNum += item.num
})
console.log(productTicketNum)
minCouponList.map((item,index) => {
productNumber += item.number
if ( productNum > 0 && productNumber > productTicketNum) {
let num = productNum >= item.number ? item.number : productNum
productNum = (productNum - item.number) >= 0 ? (productNum - item.number) : 0;
console.log(num)
console.log(item.salePrice)
productPayAmount = productPayAmount + (num*(item.memberPrice > 0 ? item.memberPrice : item.salePrice))
}
})
console.log(minCouponList)
_this.userCouponInfos.push({
userCouponId: couponData.id,
type: couponData.type,
productId: couponData.proId,
discountAmount: productPayAmount,
num: productNum == 0 ? couponData.num : (couponData.num - productNum),
})
_this.favorable[1].value.push({
userCouponId: couponData.id,
name: couponData.name,
type: couponData.type,
productId: couponData.proId,
discountAmount: productPayAmount,
num: productNum == 0 ? couponData.num : (couponData.num - productNum),
})
if ( _this.isPointsChecked) {
_this.pointsChange()
_this.getCalcUsablePoints()
}
// 商品券处理
if ( productList.length > 0 ) {
//商品券使用数量
// 商品数量
let productAllNum = 0;
productList.map((item,index)=>{
// 筛选选中商品券商品列表
let productDetails = this.listinfo.details.filter(v => v.productId == item.proId);
//金额从小到大排序
let minCouponList = productDetails.sort((a, b) => (a.memberPrice > 0 ? a.memberPrice : a.salePrice) - (b.memberPrice > 0 ? b.memberPrice : b.salePrice))
let productNum = 0;
let productPayAmount = 0;
let productDetailsNum = 0;
productDetails.map((v,indexs) => {
productDetailsNum += v.number;
})
minCouponList.map((v,indexs) => {
for (let i = 0; i < v.number; i++){
if ( productAllNum < productDetailsNum && productNum < item.num && ((v.memberPrice > 0 ? v.memberPrice : v.salePrice) < (this.listinfo.payAmount - productPayAmount) )) {
productNum++
productAllNum++
productPayAmount += v.memberPrice > 0 ? v.memberPrice : v.salePrice
}
}
})
if ( productNum > 0 ) {
this.userCouponInfos.push({
userCouponId: item.id,
type: item.type,
productId: item.proId,
discountAmount: productPayAmount,
num: productNum ,
})
this.favorable[1].value.push({
userCouponId: item.id,
name: item.name,
type: item.type,
productId: item.proId,
discountAmount: productPayAmount,
num: productNum,
})
}
})
if ( this.userCouponInfos.length > 0 ) {
console.log(this.userCouponInfos)
this.userCouponInfos.forEach(item => {
if ( item.type == 1 ) {
if ( item.discountAmount && item.discountAmount > 0 ) {
this.listinfo.payAmount = ( this.listinfo.payAmount - item.discountAmount).toFixed(2)
}
}
if ( item.type == 2 ) {
if ( item.discountAmount && item.discountAmount > 0 ) {
// this.listinfo.payAmount = (this.listinfo.payAmount - item.discountAmount).toFixed(2)
}
}
})
}
}
uni.$off('couponItem')
}
},
setPayAmount ( cartLists ) {
let tableFee;
@@ -412,24 +438,28 @@
if ( this.amountVIP.isVip == 1 && cartLists.memberAmount > 0 ) {
this.listinfo.payAmount = (cartLists.memberAmount+tableFee).toFixed(2)
} else {
this.listinfo.payAmount = (cartLists.amount+tableFee).toFixed(2)
this.listinfo.payAmount = (Number(cartLists.amount)+tableFee).toFixed(2)
}
if ( this.userCouponInfos.length > 0 ) {
console.log(this.userCouponInfos)
this.userCouponInfos.forEach(item => {
if ( item.type == 1 ) {
if ( item.discountAmount && item.discountAmount > 0 ) {
this.listinfo.payAmount = (this.listinfo.payAmount - item.discountAmount).toFixed(2)
this.listinfo.payAmount = ( this.listinfo.payAmount - item.discountAmount).toFixed(2)
}
} else {
}
if ( item.type == 2 ) {
if ( item.discountAmount && item.discountAmount > 0 ) {
this.listinfo.payAmount = (this.listinfo.payAmount - item.discountAmount).toFixed(2)
}
}
})
}
if ( this.freeDingConfig && this.listinfo.payAmount < this.freeDingConfig.rechargeThreshold ) {
this.freeDisabled = true
}
this.changeCoupon()
this.isPointsChecked = false;
this.getCalcUsablePoints()
},
@@ -439,7 +469,6 @@
*/
changeFree ( val ) {
this.freeCheck = val;
if ( val ) {
this.listinfo.payAmount = (this.listinfo.payAmount*this.freeDingConfig.rechargeTimes).toFixed(2)
} else {
@@ -464,6 +493,7 @@
this.listinfo.payAmount = (Number(this.listinfo.payAmount)+(this.calcUsablePointsData.pointsNum/this.calcUsablePointsData.equivalentPoints)).toFixed(2);
}
},
goUrl(item){
switch (item.type){
case 'coupon':
@@ -505,7 +535,7 @@
}
let res = await this.api.calcUsablePoints(params)
this.calcUsablePointsData = res.data;
if ( this.calcUsablePointsData.usable && this.listinfo.payAmount >= this.calcUsablePointsData.minPaymentAmount) {
if ( this.calcUsablePointsData && this.calcUsablePointsData.usable && this.listinfo.payAmount >= this.calcUsablePointsData.minPaymentAmount) {
this.calcUsablePointsData.pointsNum = this.calcUsablePointsData.accountPoints >= this.calcUsablePointsData.maxUsablePoints ? this.calcUsablePointsData.maxUsablePoints : this.calcUsablePointsData.accountPoints
}
},