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

This commit is contained in:
YeMingfei666 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);

View File

@ -982,9 +982,14 @@
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">
<span class="color-red" v-if="scope.row.type == 1">
{{ scope.row.discountAmount }}
</span>
<span class="color-red" v-if="scope.row.type == 2">
{{
returnProDiscount(scope.row, scope.row.index)
}}
</span>
</template>
</el-table-column>
<el-table-column prop="useRestrictions" label="">
@ -1011,6 +1016,7 @@
ref="refPayType"
v-model="order.payType"
@itemClick="payTypeItemClick"
:disabledPayType="disabledPayType"
>
</pay-type>
<div style="margin-top: 20px">
@ -1094,13 +1100,7 @@
</div>
<div class="detail_form_item">
<div class="left">应付金额</div>
<div class="right redfont">
{{
currentPayMoney - points.toMoney <= 0
? 0
: (currentPayMoney - points.toMoney) | to2
}}
</div>
<div class="right redfont">{{ yinFuJinE }}</div>
</div>
<div class="line"></div>
</div>
@ -1481,6 +1481,11 @@ import {
returnVipDiscountPrice,
returnCouponAllPrice,
} from "./util.js";
import {
returnProductCoupAllPrice
} from "./quan_util.js";
//0n
let $goodsPayPriceMap = {};
import { $status } from "@/utils/table.js";
let $originTableList = [];
@ -1501,6 +1506,7 @@ export default {
},
data() {
return {
disabledPayType: [],
//
points: {
res: {
@ -1609,7 +1615,7 @@ export default {
total: 0,
},
order: {
status:'',
status: "",
packFee: {
totalNumber: 0,
status: "",
@ -1715,8 +1721,8 @@ export default {
},
computed: {
isShowVipPrice() {
if(!this.shopInfo.isMemberPrice){
return false
if (!this.shopInfo.isMemberPrice) {
return false;
}
return this.vipUser.isVip ? true : false;
},
@ -1972,6 +1978,13 @@ export default {
},
},
watch: {
yinFuJinE: function (newval) {
if (newval <= 0) {
this.disabledPayType = ["scanCode", "deposit"];
} else {
this.disabledPayType = [];
}
},
"goods.query.categoryId": function (newval) {
this.goods.query.page = 1;
this.goods.list = [];
@ -2039,9 +2052,9 @@ export default {
// this.masterId = masterId;
console.log("this.createOrder.data");
console.log(this.createOrder.data);
if(this.order.status=='finish'){
return
}
if (this.order.status == "finish") {
return;
}
$setUser({
tableId: this.table.tableId,
masterId: this.masterId,
@ -2054,8 +2067,8 @@ export default {
this.getOrderData().then(() => {
this.pointsValueChange(this.points.value);
});
}else{
this.getCart()
} else {
this.getCart();
}
});
},
@ -2174,6 +2187,21 @@ export default {
this.open(this.$route.query);
},
methods: {
returnProDiscount(row) {
console.log(row);
//
const arr = this.quansSelArr.filter((v) => v.proId == row.proId);
const index = arr.findIndex((v) => v.id == row.id);
if (index != -1) {
return returnProductCoupAllPrice(
$goodsPayPriceMap[row.proId],
index,
row.num
).toFixed(2);
} else {
return 0;
}
},
lingshicaiShow() {
this.$refs.refPopAddCai.open();
},
@ -2234,14 +2262,15 @@ export default {
{
id: this.createOrder.data.id,
memberId: this.createOrder.data.memberId || this.vipUser.id,
orderPrice:(this.yinFuJinE*1+this.coupdiscount*1).toFixed(2)
orderPrice: (this.yinFuJinE * 1 + this.coupdiscount * 1).toFixed(2),
},
[...this.quansSelArr]
);
},
quansConfirm(e) {
quansConfirm(e,goodsPayPriceMap) {
console.log(e);
this.quansSelArr = [...e];
$goodsPayPriceMap=goodsPayPriceMap
},
searchInput(e) {
console.log(e);
@ -2837,7 +2866,7 @@ export default {
title: "支付成功",
type: "success",
});
this.order.status='finish'
this.order.status = "finish";
this.close();
// this.reset();
},
@ -3069,11 +3098,14 @@ export default {
}
if (key === "returnCart") {
console.log(this.order);
let selGoods=undefined
if(this.order.selPlaceNum==-10){
selGoods = {...this.order.seatFee,num:this.order.seatFee.number}
}else{
selGoods = this.order.old.list[this.order.selPlaceNum-1].info[this.order.old.selIndex];
let selGoods = undefined;
if (this.order.selPlaceNum == -10) {
selGoods = { ...this.order.seatFee, num: this.order.seatFee.number };
} else {
selGoods =
this.order.old.list[this.order.selPlaceNum - 1].info[
this.order.old.selIndex
];
}
console.log(selGoods);
this.refToggle("refReturnCart", true, selGoods);

View File

@ -2,7 +2,7 @@ export function isTui(item) {
return item.status == 'return' || item.status == 'refund' || item.status == 'refunding'
}
//是否使用会员价
export function isUseMemberPrice(vipUser,goods){
export function isUseVipPrice(vipUser,goods){
return vipUser.id&&vipUser.isVip&&goods.isMember
}
@ -13,7 +13,7 @@ export function returnProductCouponPrice(coup, goodsArr, vipUser) {
return 0
}
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (isUseMemberPrice(vipUser,item) ? memberPrice : item.price) : 0;
const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
return price * coup.num
}
@ -40,7 +40,8 @@ export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
if (selCoupNumber >= findGoodsTotalNumber) {
return false
}
return findGoodsTotalNumber < (coup.num + selCoupNumber) ? false : true
console.log(selCoupNumber,findGoodsTotalNumber);
return findGoodsTotalNumber < selCoupNumber ? false : true
}
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
@ -54,12 +55,13 @@ export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
}
}
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (isUseMemberPrice(vipUser,item) ? memberPrice : item.price) : 0;
const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
const discountAmount = (price * coup.num).toFixed(2)
console.log(discountAmount);
const canUse = !coup.use ? false : (discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr))
// const canUse = !coup.use ? false : (discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr))
// const canUse=discountAmount>0
const canUse=coup.use
return {
...coup,
discountAmount: discountAmount,
@ -85,7 +87,7 @@ export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
//返回商品实际支付价格
export function returnProductPayPrice(goods,vipUser){
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
const price = isUseMemberPrice(vipUser,goods) ? memberPrice : goods.price;
const price = isUseVipPrice(vipUser,goods) ? memberPrice : goods.price;
return price
}
//返回商品券抵扣的商品价格
@ -100,6 +102,23 @@ export function returnProductCoupAllPrice(productPriceArr,startIndex,num){
return prve+curPrice
},0)
}
//返回商品券可抵扣的商品数量
export function returnProductCanUseNum(productPriceArr,startIndex,num){
console.log(productPriceArr);
console.log(num);
let n=0;
for(let i=0;i<num;i++){
if(productPriceArr[startIndex*1+i]){
n+=1
console.log(n);
}else{
break
}
}
return n
}
//返回同类商品券在同类商品价格数组里的开始位置
export function returnProCoupStartIndex(coupArr,index){
return coupArr.slice(0,index).reduce((prve,cur)=>{
@ -166,7 +185,9 @@ export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
}
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
console.log(proCoupStartIndex);
total+=returnProductCoupAllPrice(goodsPayPriceMap[coup.proId],proCoupStartIndex,coup.num)
const coupNum=Math.min(goodsPayPriceMap[coup.proId].length,coup.num)
console.log(coupNum);
total+=returnProductCoupAllPrice(goodsPayPriceMap[coup.proId],proCoupStartIndex,coupNum)
}
}
@ -198,6 +219,12 @@ export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
return v
}
const isfullAmount = payPrice >= v.fullAmount * 1
if(payPrice<=0){
return {
...v,
use: false
}
}
return {
...v,
use: v.use && isfullAmount