优惠券相关更新

This commit is contained in:
GaoHao
2024-11-23 10:05:04 +08:00
parent ecb615e9c8
commit 28950f0ad1
5 changed files with 146 additions and 42 deletions

View File

@@ -234,6 +234,57 @@
this.payAmount = this.listinfo.payAmount;
uni.cache.set('selectCouponData',[])
this.isShow = true;
console.log(this.listinfo.orderInfo.couponInfoList)
if ( this.listinfo.orderInfo.couponInfoList ) {
if ( this.listinfo.orderInfo.couponInfoList.fullReductionCoupon.length > 0) {
let couponData = this.listinfo.orderInfo.couponInfoList.fullReductionCoupon[0]
this.favorable[0].value = '-¥'+couponData.discountAmount
this.payAmount = this.payAmount + couponData.discountAmount
this.userCouponInfos.push({
userCouponId: couponData.id,
type: couponData.type,
discountAmount: couponData.discountAmount,
num: couponData.num,
})
let selectCouponData = uni.cache.get('selectCouponData') || [];
selectCouponData.push(couponData)
uni.cache.set('selectCouponData',selectCouponData)
}
if ( this.listinfo.orderInfo.couponInfoList.productCoupon.length > 0) {
this.listinfo.orderInfo.couponInfoList.productCoupon.map(item=>{
this.userCouponInfos.push({
userCouponId: item.id,
type: item.type,
productId: item.proId,
discountAmount: item.finalDiscountAmount,
num: item.finalUseNum,
})
this.favorable[1].value.push({
userCouponId: item.id,
name: item.name,
type: item.type,
productId: item.proId,
discountAmount: item.finalDiscountAmount,
num: item.finalUseNum,
})
this.payAmount = this.payAmount + item.finalDiscountAmount
let selectCouponData = uni.cache.get('selectCouponData') || [];
selectCouponData.push(item)
uni.cache.set('selectCouponData',selectCouponData)
})
}
}
if ( this.listinfo.orderInfo.pointsDiscountAmount ) {
this.payAmount = this.payAmount + this.listinfo.orderInfo.pointsDiscountAmount
this.isPointsChecked = true;
}
this.$emit("setPayAmount",{
payAmount: this.listinfo.payAmount,
userCouponInfos: this.userCouponInfos,
freeCheck: this.freeCheck,
isPointsChecked: this.isPointsChecked,
})
},
methods: {
childOnShow() {
@@ -248,6 +299,8 @@
this.listinfo.payAmount = this.payAmount
this.selectCouponData = uni.cache.get('selectCouponData') || []
this.changeCoupon();
},
/**
* 监听优惠券/商品券选择
@@ -259,7 +312,6 @@
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]
@@ -302,22 +354,24 @@
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.num;
})
// 商品数量
let productAllNum = 0;
let productNum = 0
let productPayAmount = 0
minCouponList.map((v,indexs) => {
productNum = 0;
productPayAmount = 0;
let productDetailsNum = 0;
productDetails.map((v,indexs) => {
productDetailsNum += v.num;
})
console.log(minCouponList)
for (let i = 0; i < v.num; i++){
if ( productAllNum < productDetailsNum && productNum < item.num && ((v.memberPrice > 0 ? v.memberPrice : v.price) <= (this.listinfo.payAmount - productPayAmount) )) {
productNum++
@@ -357,7 +411,6 @@
let tableFee;
// this.storeInfo.registerType == 'munchies'
if ( this.userCouponInfos.length > 0 ) {
console.log(this.userCouponInfos)
this.userCouponInfos.forEach(item => {
@@ -368,8 +421,6 @@
}
})
}
this.isPointsChecked = false;
this.getCalcUsablePoints()
this.$emit("setPayAmount",{
@@ -393,7 +444,6 @@
} else {
this.listinfo.payAmount = (Number(this.listinfo.payAmount)+(this.calcUsablePointsData.pointsNum/this.calcUsablePointsData.equivalentPoints)).toFixed(2);
}
console.log(this.listinfo.payAmount)
this.$emit("setPayAmount",{
payAmount: this.listinfo.payAmount,
userCouponInfos: this.userCouponInfos,
@@ -444,7 +494,11 @@
async getCalcUsablePoints() {
let params = {
memberId: this.listinfo.orderInfo.memberId,
orderAmount: this.listinfo.payAmount,
}
if ( this.listinfo.orderInfo.pointsDiscountAmount ) {
params.orderAmount = this.listinfo.payAmount + this.listinfo.orderInfo.pointsDiscountAmount
} else {
params.orderAmount = this.listinfo.payAmount
}
let res = await this.api.calcUsablePoints(params)
this.calcUsablePointsData = res.data;

View File

@@ -91,8 +91,8 @@
<view>{{listinfo.orderInfo.seatAmount}}</view>
</view>
</view>
<block v-for="(item,index) in listinfo.orderInfo.couponInfoList.fullReductionCoupon" :key="index">
<view class="cell-item" v-if="item.type == 1">
<block v-if="listinfo.orderInfo&&listinfo.orderInfo.couponInfoList && listinfo.orderInfo.couponInfoList.fullReductionCoupon">
<view class="cell-item" v-for="(item,index) in listinfo.orderInfo.couponInfoList.fullReductionCoupon" :key="index">
<view class="label">优惠券</view>
<view class="val">
<view></view>
@@ -101,7 +101,7 @@
</view>
</view>
</block>
<view class="cell-item column" v-if="listinfo.orderInfo&&listinfo.orderInfo.couponInfoList && listinfo.orderInfo.couponInfoList.productCoupon.length > 0">
<view class="cell-item column" v-if="listinfo.orderInfo&&listinfo.orderInfo.couponInfoList && listinfo.orderInfo.couponInfoList.productCoupon">
<view class="label">商品券</view>
<view class="val column">
<view class="productCoupon" v-for="(item,index) in listinfo.orderInfo.couponInfoList.productCoupon" :key="index">