修改代客下单优惠券,积分抵扣逻辑

This commit is contained in:
2024-11-20 15:55:31 +08:00
parent 8a8de80321
commit d9c789da8f
4 changed files with 153 additions and 56 deletions

View File

@@ -10,6 +10,7 @@
v-for="(item, index) in list"
:key="index"
:type="sel === item.payType ? 'primary' : ''"
:disabled="disabledPayType.includes(item.payType)"
>
{{ item.payName }}
</el-button>
@@ -30,6 +31,10 @@ export default {
type: [String, Number],
default: '',
},
disabledPayType:{
type:Array,
default:()=>[]
}
},
data() {
return {
@@ -38,6 +43,10 @@ export default {
};
},
watch: {
disabledPayType(){
const item = this.list.find(v=>!this.disabledPayType.includes(v.payType))
this.sel=item.payType
},
sel(newval) {
console.log(newval);
this.$emit("input", newval);

View File

@@ -16,11 +16,7 @@
:data="quans.fullReductionCoupon"
@cell-click="fullReductionCouponClick"
>
<el-table-column
type="index"
label=""
v-if="quans.fullReductionCoupon.length > 0"
>
<el-table-column type="index" label="">
<template v-slot="scope">
<el-checkbox
@change="fullReductionCouponClick(scope.row)"
@@ -65,10 +61,7 @@
:data="quans.productCoupon"
style="width: 100%"
>
<el-table-column
label=""
v-if="quans.fullReductionCoupon.length > 0"
>
<el-table-column>
<template v-slot="scope">
<el-checkbox
@change="productCouponClick(scope.row)"
@@ -112,11 +105,11 @@
</el-table-column>
<el-table-column prop="useRestrictions" label="描述">
</el-table-column>
<el-table-column prop="useRestrictions" label="是否可用">
<!-- <el-table-column prop="useRestrictions" label="是否可用">
<template v-slot="scope">
{{ scope.row.use ? "可以" : "不可用" }}
</template>
</el-table-column>
</el-table-column> -->
</el-table>
</el-tab-pane>
</el-tabs>
@@ -232,11 +225,11 @@ export default {
isVip: false,
};
},
}
},
},
data() {
return {
orderPrice:0,
orderPrice: 0,
fullReductionCouponSel: {
id: "",
},
@@ -297,7 +290,7 @@ export default {
$goodsPayPriceMap[row.proId],
index,
row.num
);
).toFixed(2);
} else {
return 0;
}
@@ -310,7 +303,8 @@ export default {
const index = this.quansSelArr.findIndex((item) => item.id == row.id);
if (row.type == 2 && index != -1) {
this.quansSelArr.splice(index, 1);
this.quans.productCoupon[index].checked = false;
const proIndex=this.quans.productCoupon.findIndex((v) => v.id == row.id);
this.quans.productCoupon[proIndex].checked = false;
}
if (row.type == 1 && index != -1) {
this.fullReductionCouponSel = { id: "" };
@@ -350,16 +344,44 @@ export default {
if (!item.use) {
return;
}
const hasSelNum = this.quansSelArr
.filter((v) => v.type == 2 && v.proId == item.proId)
.reduce((a, b) => {
return a + b.num;
}, 0);
const maxSelNum = $goodsPayPriceMap[item.proId].length;
const coupMaxUseNum = Math.min(item.num, maxSelNum - hasSelNum);
const canUseNum = Math.min(maxSelNum, coupMaxUseNum);
if (this.fullReductionCouponSel.id && !item.checked) {
const goodsQuan = this.quans.productCoupon.filter((v) => v.checked);
const fullReductionCoupon = this.fullReductionCouponSel.id
? [this.fullReductionCouponSel]
: [];
let coupArr = [...goodsQuan, item];
let coupArr = [...goodsQuan, { ...item, num: canUseNum }];
const payPrice =
this.orderPrice -
returnCouponAllPrice(coupArr, canDikouGoodsArr, this.vipUser);
console.log(payPrice);
if (payPrice <= 0) {
return this.$confirm(
"选择该商品券后支付金额将为0继续选择将取消选择的满减券",
"提示",
{
confirmButtonText: "继续选择",
cancelButtonText: "取消",
type: "warning",
}
)
.then(() => {
this.fullReductionCouponSel = {
id: "",
};
this.quansSelArr.splice(0, 1);
})
.catch(() => {});
}
if (this.fullReductionCouponSel.fullAmount > payPrice) {
this.$confirm(
"选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券",
@@ -379,13 +401,19 @@ export default {
}
}
item.checked = !item.checked;
if (!item.checked) {
console.log(index);
const index = this.quansSelArr.findIndex((v) => v.id == item.id);
this.quansSelArr.splice(index, 1);
} else {
this.quansSelArr.push({ ...item, num: canUseNum });
}
const CheckedArr = this.quans.productCoupon.filter((v) => v.checked);
this.quansSelArr = [
...(this.fullReductionCouponSel.id
? [this.fullReductionCouponSel]
: []),
...CheckedArr,
];
if (CheckedArr.length <= 0) {
return this.quans.productCoupon.map((v) => {
v.use = true;
});
}
const noCheckedArr = this.quans.productCoupon.filter((v) => !v.checked);
noCheckedArr.map((v) => {
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr);
@@ -405,12 +433,12 @@ export default {
},
confirm() {
this.$emit("confirm", [...this.quansSelArr]);
this.$emit("confirm", [...this.quansSelArr], $goodsPayPriceMap);
this.close();
},
async open(data, propSelCoup) {
console.log(data);
this.orderPrice=data.orderPrice;
this.orderPrice = data.orderPrice;
this.quansSelArr = [...propSelCoup];
$goodsPayPriceMap = returnGoodsPayPriceMap(this.goodsArr || []);
if (data.memberId) {
@@ -419,7 +447,7 @@ export default {
memberId: data.memberId,
});
quansRes.fullReductionCoupon = quansRes.fullReductionCoupon.filter(
(v) => v.use && this.orderPrice * 1 >= v.fullAmount * 1
(v) =>this.orderPrice<=0?false:(v.use && this.orderPrice * 1 >= v.fullAmount * 1)
);
const selFullReductionCoupon = this.quansSelArr.find(
(v) => v.type == 1
@@ -442,6 +470,7 @@ export default {
checked: this.quansSelArr.find((selCoup) => selCoup.id == v.id)
? true
: false,
use:this.orderPrice<=0?false:calcCoup.use
};
})
.filter((v) => v.use);