代客下单修改商品抵扣券价格计算逻辑

This commit is contained in:
YeMingfei666 2024-11-18 18:24:28 +08:00
parent 13c473a234
commit 3d287016c0
6 changed files with 870 additions and 164 deletions

View File

@ -17,7 +17,8 @@ export function canTuicai(orderInfo,item){
return orderInfo.status=='unpaid'&&orderInfo.useType!='dine-in-before'&& item.status!='return'
}
export function canTuiKuan(orderInfo,item){
return orderInfo.status!='unpaid'&& item.status!='return'&&item.status!='refund'&&item.status!='refunding'
// return orderInfo.status!='unpaid'&& item.status!='return'&&item.status!='refund'&&item.status!='refunding'
return orderInfo.status=='closed'&& item.status!='return'&&item.status!='refund'&&item.status!='refunding' && !item.userCouponId
}
export function isTui(item){
return item.status=='return'||item.status=='refund'||item.status=='refunding'

View File

@ -0,0 +1,456 @@
<template>
<el-dialog
width="700px"
:title="title"
:visible.sync="show"
top="20px"
@close="reset"
>
<div class="u-p-15">
<div class="">
<el-tabs v-model="activeName" @tab-click="tabClick">
<el-tab-pane label="优惠券(单选)" name="youhui">
<el-table
ref="table"
empty-text="无可用优惠券"
:data="quans.fullReductionCoupon"
@cell-click="fullReductionCouponClick"
>
<el-table-column
type="index"
label=""
v-if="quans.fullReductionCoupon.length > 0"
>
<template v-slot="scope">
<el-checkbox
@change="fullReductionCouponClick(scope.row)"
:value="scope.row.id == fullReductionCouponSel.id"
></el-checkbox>
</template>
</el-table-column>
<el-table-column type="index" label="#"> </el-table-column>
<el-table-column prop="name" label="券名称"> </el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">
{{ scope.row.discountAmount }}
</span>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="限制" width="120">
<template v-slot="scope">
<div class="u-flex">
<span>支付满</span>
<span class="color-red no-wrap">
{{ scope.row.fullAmount }}
</span>
<span>元可用</span>
</div>
</template>
</el-table-column>
<el-table-column prop="useRestrictions" label="描述">
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="商品券(多选)" name="goods">
<el-table
ref="table1"
@cell-click="productCouponClick"
empty-text="无可用商品券"
:data="quans.productCoupon"
tooltip-effect="dark"
style="width: 100%"
@selection-change="productCouponChange"
>
<el-table-column type="selection" width="55" :selectable="goodsCoupSelectableHandle"> </el-table-column>
<el-table-column type="index" width="50" label="#">
</el-table-column>
<el-table-column prop="name" label="券名称"> </el-table-column>
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex">
<div class="u-flex">
<el-image
:src="scope.row.productCover"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
</div>
<div class="u-p-l-10">
<div class="">{{ scope.row.productName }}</div>
<div class="">x{{ scope.row.num || "" }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">
{{ scope.row.discountAmount }}
</span>
</template>
</el-table-column>
<el-table-column label="券类型">
<template v-slot="scope">
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
</template>
</el-table-column>
<el-table-column prop="useRestrictions" label="描述">
</el-table-column>
</el-table>
</el-tab-pane>
</el-tabs>
<div v-if="quansSelArr.length > 0">
<div class="font-bold u-m-b-10">已选优惠券</div>
<el-table empty-text="未选择优惠券" :data="quansSelArr">
<el-table-column type="index" width="50" label="#">
</el-table-column>
<el-table-column prop="name" label="券名称"> </el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
</template>
</el-table-column>
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex">
<div class="u-flex">
<el-image
:src="scope.row.productCover"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
</div>
<div class="u-p-l-10">
<div class="">{{ scope.row.productName }}</div>
<div class="">x{{ scope.row.num || "" }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">
{{ scope.row.discountAmount }}
</span>
</template>
</el-table-column>
<el-table-column prop="useRestrictions" label="描述">
</el-table-column>
<el-table-column prop="useRestrictions" label="">
<template v-slot="scope">
<el-button type="danger" size="mini" @click="delQuan(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<div class="u-flex u-m-t-20">
<span class="">抵扣</span>
<span class="color-red font-bold">{{ AllCouponPrice }}</span>
</div>
</div>
<div class="u-flex u-row-center u-m-t-50">
<el-button size="medium" @click="close">取消</el-button>
<el-button size="medium" type="primary" @click="confirm"
>确定</el-button
>
</div>
</div>
</div>
</el-dialog>
</template>
<script>
import { $activateByOrderId } from "@/api/table";
import {
returnProductCouponAllPrice,returnProductCoupon,
returnProductCouponPrice,
returnFullReductionCouponAllPrice,returnNewGoodsList
} from "../util";
let $originFullReductionCoupon = [];
export default {
props: {
title: {
type: String,
default: "选择优惠券",
},
goodsArr: {
type: Array,
default: [],
},
vipUser: {
type: Object,
default: () => {
return {
isVip: false,
};
},
},
orderPrice: {
type: [Number, String],
default: 0,
},
},
data() {
return {
propSelCoup: [],
fullReductionCouponSel: {
id: "",
},
quansSelArr: [],
quans: {
fullReductionCoupon: [],
productCoupon: [],
},
currentRow: null,
multipleSelection: null,
fullReductionCouponSelId: "",
activeName: "youhui",
form: {},
show: false,
isSetProductCoup: false,
};
},
watch: {
activeName(newval) {
if (newval == "youhui") {
this.filterFullReductionCoupon();
}
},
},
computed: {
goodsDiscount() {
const coupArr = this.quansSelArr.filter((v) => v.type == 2);
return returnProductCouponAllPrice(coupArr, this.goodsArr, this.vipUser);
},
fullReductionCouponDiscount() {
const coupArr = this.quansSelArr.filter((v) => v.type == 1);
return returnFullReductionCouponAllPrice(coupArr);
},
AllCouponPrice() {
return (
this.goodsDiscount * 1 +
this.fullReductionCouponDiscount * 1
).toFixed(2);
},
},
methods: {
goodsCoupSelectableHandle(row,index){
console.log(row,index);
return true
},
delQuan(row) {
if (row.type == 2) {
const index = this.quansSelArr.findIndex((item) => item.id == row.id);
this.quansSelArr.splice(index, 1);
this.$refs.table1.toggleRowSelection(row, false);
} else {
this.fullReductionCouponSel = { id: "" };
this.quansSelArr.splice(0, 1);
}
if (index != -1) {
const row = this.quansSelArr.find;
}
},
reset() {
this.quansSelArr = [];
this.fullReductionCouponSel = { id: "" };
this.$refs.table1.clearSelection();
},
filterFullReductionCoupon() {
this.quans.fullReductionCoupon = $originFullReductionCoupon.filter(
(v) => this.orderPrice - this.goodsDiscount >= v.fullAmount
);
},
productCouponChange(val) {
const oldval=this.quansSelArr;
if (this.isSetProductCoup) {
return;
}
const firstCoup = this.quansSelArr[0];
const firstIsDikouQuan = firstCoup ? firstCoup.type == 1 : false;
if (firstCoup && firstIsDikouQuan) {
if (
this.orderPrice -
this.fullReductionCouponDiscount -
returnProductCouponAllPrice(val, this.goodsArr, this.vipUser) <
firstCoup.fullAmount
) {
this.$confirm(
"所选优惠券不满足最低抵扣" + firstCoup.fullAmount + "元要求",
"提示",
{
distinguishCancelAndClose: true,
confirmButtonText: "放弃选择商品券",
cancelButtonText: "删除优惠券",
type: "warning",
}
)
.then(() => {
val.map((v) => {
this.$refs.table1.toggleRowSelection(v);
});
})
.catch((action) => {
if (action == "cancel") {
this.quansSelArr.splice(0, 1);
this.fullReductionCouponSel = { id: "" };
this.quansSelArr = [...val];
}
if (action == "close") {
val.map((v) => {
this.$refs.table1.toggleRowSelection(v);
});
}
});
} else {
this.quansSelArr.splice(
val.length <= 0 ? 1 : val.length,
this.quansSelArr.length
);
for (let i in val) {
this.$set(this.quansSelArr, i * 1 + 1, { ...val[i] });
}
}
} else {
this.quansSelArr = [...val];
}
},
fullReductionCouponClick(row) {
if (row.id == this.fullReductionCouponSel.id) {
this.fullReductionCouponSel = { id: "" };
this.quansSelArr.splice(0, 1);
return;
}
const dikouQuan = this.quansSelArr[0];
this.fullReductionCouponSel = row;
if (dikouQuan && dikouQuan.type == 1) {
this.$set(this.quansSelArr, 0, row);
} else {
this.quansSelArr.unshift(row);
}
if (!this.fullReductionCouponSel.id) {
return;
}
if (
this.orderPrice -
this.fullReductionCouponDiscount -
this.goodsDiscount <
this.fullReductionCouponSel.fullAmount
) {
this.fullReductionCouponSel = { id: "" };
this.quansSelArr.splice(0, 1);
this.$confirm(
"所选优惠券不满足最低抵扣" +
this.fullReductionCouponSel.fullAmount +
"元要求",
"提示",
{
distinguishCancelAndClose: true,
confirmButtonText: "确定",
type: "warning",
}
).then(() => {});
}
},
productCouponClick(row) {
this.$refs.table1.toggleRowSelection(row);
},
handleCurrentChange(val) {
this.currentRow = val;
},
handleSelectionChange(val) {
this.multipleSelection = val;
},
tabClick() {},
init() {},
changeKey(key, val) {
this[key] = val;
},
confirm() {
this.$emit("confirm", [...this.quansSelArr]);
this.close();
},
setSelectCoupon() {
const dikouQuan = this.propSelCoup.find((v) => v.type == 1);
this.fullReductionCouponSel = dikouQuan ? dikouQuan : { id: "" };
const productCouArr = this.propSelCoup.filter((v) => v.type == 2);
this.quans.productCoupon.map((v) => {
for (let i in productCouArr) {
this.isSetProductCoup = true;
if (v.id == productCouArr[i].id) {
this.$refs.table1.toggleRowSelection(v, true);
}
}
});
this.isSetProductCoup = false;
},
async open(data, propSelCoup) {
this.propSelCoup = [...propSelCoup] || [];
console.log(data);
if (data.memberId) {
let quansRes = await $activateByOrderId({
orderId: data.id,
memberId: data.memberId,
});
quansRes.fullReductionCoupon = quansRes.fullReductionCoupon.filter(
(v) => {
return this.orderPrice >= v.fullAmount && v.use;
}
);
const canDikouGoodsArr = returnNewGoodsList(this.goodsArr|| [])
$originFullReductionCoupon = quansRes.fullReductionCoupon;
this.quans.productCoupon = quansRes.productCoupon.map(v=>{
const coup = returnProductCoupon(v, canDikouGoodsArr,this.vipUser)
return coup
}).filter(v=>v.use)
// this.quans = quans;
this.filterFullReductionCoupon();
this.quansSelArr = this.propSelCoup;
this.$nextTick(() => {
this.setSelectCoupon();
});
}
this.show = true;
this.init();
},
close() {
this.show = false;
},
},
mounted() {
this.number = `${this.value}`;
},
};
</script>
<style lang="scss" scoped>
.codeImg {
width: 160px;
border: 1px solid rgb(220, 223, 230);
height: 160px;
}
::v-deep .el-input .el-input__inner::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
::v-deep .el-input .el-input__inner::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
</style>

View File

@ -63,11 +63,19 @@
@cell-click="productCouponClick"
empty-text="无可用商品券"
:data="quans.productCoupon"
tooltip-effect="dark"
style="width: 100%"
@selection-change="productCouponChange"
>
<el-table-column type="selection" width="55"> </el-table-column>
<el-table-column
label=""
v-if="quans.fullReductionCoupon.length > 0"
>
<template v-slot="scope">
<el-checkbox
@change="productCouponClick(scope.row)"
:value="scope.row.checked"
></el-checkbox>
</template>
</el-table-column>
<el-table-column type="index" width="50" label="#">
</el-table-column>
<el-table-column prop="name" label="券名称"> </el-table-column>
@ -90,13 +98,13 @@
</div>
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣">
<!-- <el-table-column prop="discountAmount" label="抵扣">
<template v-slot="scope">
<span class="color-red">
{{ scope.row.discountAmount }}
</span>
</template>
</el-table-column>
</el-table-column> -->
<el-table-column label="券类型">
<template v-slot="scope">
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
@ -104,6 +112,11 @@
</el-table-column>
<el-table-column prop="useRestrictions" label="描述">
</el-table-column>
<el-table-column prop="useRestrictions" label="是否可用">
<template v-slot="scope">
{{ scope.row.use ? "可以" : "不可用" }}
</template>
</el-table-column>
</el-table>
</el-tab-pane>
</el-tabs>
@ -118,23 +131,32 @@
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
</template>
</el-table-column>
<el-table-column label="商品信息">
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex" v-if="scope.row.type == 2">
<el-image
:src="scope.row.productCover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
<div class="u-m-l-10">{{ scope.row.productName }}</div>
<div class="u-flex">
<el-image
:src="scope.row.productCover"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
</div>
<div class="u-p-l-10">
<div class="">{{ scope.row.productName }}</div>
<div class="">x{{ scope.row.num || "" }}</div>
</div>
</div>
</template>
</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="描述">
@ -147,9 +169,22 @@
</template>
</el-table-column>
</el-table>
<div class="u-flex u-m-t-20">
<span class="">抵扣</span>
<span class="color-red font-bold">{{ AllCouponPrice }}</span>
</div>
<div class="u-flex u-row-between u-m-t-20">
<div class="u-flex">
<span>抵扣金额:</span>
<span class="color-red">{{ AllCouponPrice }}</span>
</div>
<div class="u-flex u-relative">
<span>支付金额:</span>
<span class="color-red">{{ payPrice }}</span>
<div
class="u-absolute u-flex line-th color-999"
style="right: 0; bottom: 100%"
v-if="orderPrice * 1 != payPrice * 1"
>
<span class="">{{ orderPrice }}</span>
</div>
</div>
</div>
<div class="u-flex u-row-center u-m-t-50">
@ -165,11 +200,21 @@
<script>
import { $activateByOrderId } from "@/api/table";
import {
returnProductCouponAllPrice,returnProductCoupon,
returnProductCouponPrice,
returnFullReductionCouponAllPrice,returnNewGoodsList
} from "../util";
returnNewGoodsList,
returnFullReductionCouponAllPrice,
returnCouponAllPrice,
returnProductCoupon,
returnCanUseFullReductionCoupon,
returnCoupCanUse,
returnProductCouponAllPrice,
returnGoodsPayPriceMap,
returnProductCoupAllPrice,
} from "../quan_util.js";
let $originFullReductionCoupon = [];
//
let canDikouGoodsArr = [];
//0n
let $goodsPayPriceMap = {};
export default {
props: {
title: {
@ -187,15 +232,11 @@ export default {
isVip: false,
};
},
},
orderPrice: {
type: Number,
default: 0,
},
}
},
data() {
return {
propSelCoup: [],
orderPrice:0,
fullReductionCouponSel: {
id: "",
},
@ -223,32 +264,58 @@ export default {
computed: {
goodsDiscount() {
const coupArr = this.quansSelArr.filter((v) => v.type == 2);
return returnProductCouponAllPrice(coupArr, this.goodsArr, this.vipUser);
return returnProductCouponAllPrice(
coupArr,
canDikouGoodsArr,
this.vipUser
);
},
fullReductionCouponDiscount() {
const coupArr = this.quansSelArr.filter((v) => v.type == 1);
return returnFullReductionCouponAllPrice(coupArr);
},
AllCouponPrice() {
return (
this.goodsDiscount * 1 +
this.fullReductionCouponDiscount * 1
).toFixed(2);
return returnCouponAllPrice(
this.quansSelArr,
canDikouGoodsArr,
this.vipUser
);
},
payPrice() {
const pay = this.orderPrice - this.AllCouponPrice;
return (pay < 0 ? 0 : pay).toFixed(2);
},
},
methods: {
delQuan(row) {
if (row.type == 2) {
const index = this.quansSelArr.findIndex((item) => item.id == row.id);
this.quansSelArr.splice(index, 1);
this.$refs.table1.toggleRowSelection(row, false);
returnProDiscount(row) {
console.log(row);
//
const arr = this.quans.productCoupon.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
);
} else {
return 0;
}
},
goodsCoupSelectableHandle(row, index) {
console.log(row, index);
return true;
},
delQuan(row) {
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;
}
if (row.type == 1 && index != -1) {
this.fullReductionCouponSel = { id: "" };
this.quansSelArr.splice(0, 1);
}
if (index != -1) {
const row = this.quansSelArr.find;
}
},
reset() {
this.quansSelArr = [];
@ -256,64 +323,12 @@ export default {
this.$refs.table1.clearSelection();
},
filterFullReductionCoupon() {
this.quans.fullReductionCoupon = $originFullReductionCoupon.filter(
(v) => this.orderPrice - this.goodsDiscount >= v.fullAmount
this.quans.fullReductionCoupon = returnCanUseFullReductionCoupon(
$originFullReductionCoupon,
this.payPrice,
this.fullReductionCouponSel
);
},
productCouponChange(val) {
if (this.isSetProductCoup) {
return;
}
const firstCoup = this.quansSelArr[0];
const firstIsDikouQuan = firstCoup ? firstCoup.type == 1 : false;
if (firstCoup && firstIsDikouQuan) {
if (
this.orderPrice -
this.fullReductionCouponDiscount -
returnProductCouponAllPrice(val, this.goodsArr, this.vipUser) <
firstCoup.fullAmount
) {
this.$confirm(
"所选优惠券不满足最低抵扣" + firstCoup.fullAmount + "元要求",
"提示",
{
distinguishCancelAndClose: true,
confirmButtonText: "放弃选择商品券",
cancelButtonText: "删除优惠券",
type: "warning",
}
)
.then(() => {
val.map((v) => {
this.$refs.table1.toggleRowSelection(v);
});
})
.catch((action) => {
if (action == "cancel") {
this.quansSelArr.splice(0, 1);
this.fullReductionCouponSel = { id: "" };
this.quansSelArr = [...val];
}
if (action == "close") {
val.map((v) => {
this.$refs.table1.toggleRowSelection(v);
});
}
});
} else {
this.quansSelArr.splice(
val.length <= 0 ? 1 : val.length,
this.quansSelArr.length
);
for (let i in val) {
this.$set(this.quansSelArr, i * 1 + 1, { ...val[i] });
}
}
} else {
this.quansSelArr = [...val];
}
},
fullReductionCouponClick(row) {
if (row.id == this.fullReductionCouponSel.id) {
this.fullReductionCouponSel = { id: "" };
@ -330,30 +345,51 @@ export default {
if (!this.fullReductionCouponSel.id) {
return;
}
if (
this.orderPrice -
this.fullReductionCouponDiscount -
this.goodsDiscount <
this.fullReductionCouponSel.fullAmount
) {
this.fullReductionCouponSel = { id: "" };
this.quansSelArr.splice(0, 1);
this.$confirm(
"所选优惠券不满足最低抵扣" +
this.fullReductionCouponSel.fullAmount +
"元要求",
"提示",
{
distinguishCancelAndClose: true,
confirmButtonText: "确定",
type: "warning",
}
).then(() => {});
}
},
productCouponClick(row) {
this.$refs.table1.toggleRowSelection(row);
productCouponClick(item) {
if (!item.use) {
return;
}
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];
const payPrice =
this.orderPrice -
returnCouponAllPrice(coupArr, canDikouGoodsArr, this.vipUser);
console.log(payPrice);
if (this.fullReductionCouponSel.fullAmount > payPrice) {
this.$confirm(
"选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券",
"提示",
{
confirmButtonText: "继续选择",
cancelButtonText: "取消",
type: "warning",
}
)
.then(() => {
this.fullReductionCouponSel = {
id: "",
};
})
.catch(() => {});
}
}
item.checked = !item.checked;
const CheckedArr = this.quans.productCoupon.filter((v) => v.checked);
this.quansSelArr = [
...(this.fullReductionCouponSel.id
? [this.fullReductionCouponSel]
: []),
...CheckedArr,
];
const noCheckedArr = this.quans.productCoupon.filter((v) => !v.checked);
noCheckedArr.map((v) => {
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr);
});
},
handleCurrentChange(val) {
this.currentRow = val;
@ -372,46 +408,44 @@ export default {
this.$emit("confirm", [...this.quansSelArr]);
this.close();
},
setSelectCoupon() {
const dikouQuan = this.propSelCoup.find((v) => v.type == 1);
this.fullReductionCouponSel = dikouQuan ? dikouQuan : { id: "" };
const productCouArr = this.propSelCoup.filter((v) => v.type == 2);
this.quans.productCoupon.map((v) => {
for (let i in productCouArr) {
this.isSetProductCoup = true;
if (v.id == productCouArr[i].id) {
this.$refs.table1.toggleRowSelection(v, true);
}
}
});
this.isSetProductCoup = false;
},
async open(data, propSelCoup) {
this.propSelCoup = [...propSelCoup] || [];
console.log(data);
this.orderPrice=data.orderPrice;
this.quansSelArr = [...propSelCoup];
$goodsPayPriceMap = returnGoodsPayPriceMap(this.goodsArr || []);
if (data.memberId) {
let quansRes = await $activateByOrderId({
orderId: data.id,
memberId: data.memberId,
});
quansRes.fullReductionCoupon = quansRes.fullReductionCoupon.filter(
(v) => {
return this.orderPrice >= v.fullAmount && v.use;
}
(v) => v.use && this.orderPrice * 1 >= v.fullAmount * 1
);
const canDikouGoodsArr = returnNewGoodsList(this.goodsArr|| [])
const selFullReductionCoupon = this.quansSelArr.find(
(v) => v.type == 1
);
this.fullReductionCouponSel = selFullReductionCoupon
? selFullReductionCoupon
: { id: "" };
this.quans.fullReductionCoupon = quansRes.fullReductionCoupon;
canDikouGoodsArr = returnNewGoodsList(this.goodsArr || []);
$originFullReductionCoupon = quansRes.fullReductionCoupon;
this.quans.productCoupon = quansRes.productCoupon.map(v=>{
const coup = returnProductCoupon(v, canDikouGoodsArr,this.vipUser)
return coup
}).filter(v=>v.use)
this.quans.productCoupon = quansRes.productCoupon
.map((v) => {
const calcCoup = returnProductCoupon(
v,
canDikouGoodsArr,
this.vipUser
);
return {
...calcCoup,
checked: this.quansSelArr.find((selCoup) => selCoup.id == v.id)
? true
: false,
};
})
.filter((v) => v.use);
// this.quans = quans;
this.filterFullReductionCoupon();
this.quansSelArr = this.propSelCoup;
this.$nextTick(() => {
this.setSelectCoupon();
});
}
this.show = true;
@ -428,6 +462,9 @@ export default {
</script>
<style lang="scss" scoped>
.line-th {
text-decoration: line-through;
}
.codeImg {
width: 160px;
border: 1px solid rgb(220, 223, 230);

View File

@ -962,16 +962,20 @@
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
</template>
</el-table-column>
<el-table-column label="商品信息">
<el-table-column label="商品信息" width="120">
<template v-slot="scope">
<div class="u-flex" v-if="scope.row.type == 2">
<el-image
:src="scope.row.productCover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
<div class="u-m-l-10">
{{ scope.row.productName }}
<div class="u-flex">
<div class="u-flex">
<el-image
:src="scope.row.productCover"
fit="cover"
style="width: 40px; height: 40px"
:preview-src-list="[scope.row.productCover]"
></el-image>
</div>
<div class="u-p-l-10">
<div class="">{{ scope.row.productName }}</div>
<div class="">x{{ scope.row.num || "" }}</div>
</div>
</div>
</template>
@ -1394,7 +1398,7 @@
<quans-pop
ref="refQuans"
:vipUser="vipUser"
:orderPrice="currentPayMoney"
:orderPrice="yinFuJinE"
:goodsArr="createOrder.data.detailList || []"
@confirm="quansConfirm"
>
@ -1414,9 +1418,7 @@
></return-cart>
<!-- 临时菜 -->
<cai-add ref="refPopAddCai"
></cai-add>
<cai-add ref="refPopAddCai"></cai-add>
</div>
</template>
@ -1752,9 +1754,9 @@ export default {
},
yinFuJinE() {
const total = this.currentPayMoney - (this.points.toMoney || 0);
if(this.isCreateOrder){
if (this.isCreateOrder) {
return total.toFixed(2);
}else{
} else {
return this.allPrice;
}
},
@ -2033,6 +2035,9 @@ export default {
// this.masterId = masterId;
console.log("this.createOrder.data");
console.log(this.createOrder.data);
if(this.createOrder.data.memberId==val){
return
}
$setUser({
tableId: this.table.tableId,
masterId: this.masterId,
@ -2223,6 +2228,7 @@ export default {
{
id: this.createOrder.data.id,
memberId: this.createOrder.data.memberId || this.vipUser.id,
orderPrice:(this.yinFuJinE*1+this.coupdiscount*1).toFixed(2)
},
[...this.quansSelArr]
);

View File

@ -0,0 +1,206 @@
export function isTui(item) {
return item.status == 'return' || item.status == 'refund' || item.status == 'refunding'
}
//是否使用会员价
export function isUseVipPrice(vipUser,goods){
return vipUser.id&&vipUser.isVip&&goods.isMember
}
//计算商品券优惠价格
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
const item = goodsArr.find(v => v.productId == coup.proId);
if (!item) {
return 0
}
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
return price * coup.num
}
//返回新的商品列表,过滤掉退菜的,退单的商品
export function returnNewGoodsList(arr) {
let goodsMap = {}
return arr.filter(v => !isTui(v))
}
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
// if(!coup.use){
// return false
// }
const findGoods = goodsArr.filter(v => v.productId == coup.proId)
if (!findGoods.length) {
return false
}
const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
return prve + cur.num * 1
}, 0)
const selCoupNumber = selCoupArr.filter(v => v.proId == coup.proId).reduce((prve, cur) => {
return prve + cur.num * 1
}, 0)
if (selCoupNumber >= findGoodsTotalNumber) {
return false
}
return findGoodsTotalNumber < (coup.num + selCoupNumber) ? false : true
}
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
const newGoodsArr = returnNewGoodsList(goodsArr)
const item = newGoodsArr.find(v => v.productId == coup.proId);
if (!item) {
return {
...coup,
discountAmount: 0,
use: false
}
}
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
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=discountAmount>0
return {
...coup,
discountAmount: discountAmount,
use: canUse
}
}
/**
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
* 1.商品券对应商品数量大于购物车对应商品数量不可用
* 2.未在购物车找到相关商品不可用
* @param {*} coupArr
* @param {*} goodsArr
* @param {*} vipUser
* @returns
*/
export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
return coupArr.map((v) => {
return returnProductCoupon(v, goodsArr, vipUser)
})
}
//返回商品实际支付价格
export function returnProductPayPrice(goods,vipUser){
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
const price = isUseVipPrice(vipUser,goods) ? memberPrice : goods.price;
return price
}
//返回商品券抵扣的商品价格
export function returnProductCoupAllPrice(productPriceArr,startIndex,num){
return productPriceArr.slice(startIndex,startIndex+num).reduce((prve,cur)=>{
let curPrice=0
if(typeof cur==='object'){
curPrice=cur.memberPrice*1
}else{
curPrice=cur*1
}
return prve+curPrice
},0)
}
//返回同类商品券在同类商品价格数组里的开始位置
export function returnProCoupStartIndex(coupArr,index){
return coupArr.slice(0,index).reduce((prve,cur)=>{
return prve+cur.num*1
},0)
}
//返回商品数量从0到n每一个对应的价格对照表
export function returnGoodsPayPriceMap(goodsArr){
return goodsArr.reduce((prve,cur)=>{
if(!prve.hasOwnProperty(cur.productId)){
prve[cur.productId]=[]
}
const arr=new Array(cur.num).fill(cur).map(v=>{
return {
memberPrice:v.memberPrice?v.memberPrice:v.price,
price:v.price
}
})
prve[cur.productId].push(...arr)
return prve
},{})
}
//计算商品券总优惠价格
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
if (coupArr.length == 0) {
return 0;
}
//商品分组
const goodsMap={}
//商品数量从0到n每一个对应的价格
const goodsPayPriceMap={}
//商品券分组
let coupMap={}
for(let i in coupArr){
const coup=coupArr[i]
if(coupMap.hasOwnProperty(coup.proId)){
coupMap[coup.proId].push(coup)
}else{
coupMap[coup.proId]=[coup]
}
}
let total=0
for(let key in coupMap){
const arr=coupMap[key]
for(let i in arr){
const coup=arr[i]
if(!goodsMap.hasOwnProperty(coup.proId)){
goodsMap[coup.proId]=goodsArr.filter(v=>v.productId==coup.proId).map(v=>{
return {
...v,
payPrice:returnProductPayPrice(v,vipUser)
}
}).sort((a,b)=>{
const aPrice=a.payPrice
const bPrice=b.payPrice
return aPrice-bPrice
})
goodsPayPriceMap[coup.proId]=goodsMap[coup.proId].reduce((prve,cur)=>{
const arr=new Array(cur.num).fill(cur.payPrice)
console.log(arr);
prve.push(...arr)
return prve
},[])
}
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
console.log(proCoupStartIndex);
total+=returnProductCoupAllPrice(goodsPayPriceMap[coup.proId],proCoupStartIndex,coup.num)
}
}
return total.toFixed(2);
}
//计算满减券总优惠价格
export function returnFullReductionCouponAllPrice(coupArr) {
if (coupArr.length == 0) {
return 0;
}
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
const price = b.discountAmount
return a + price;
}, 0).toFixed(2);
}
//计算优惠券总价格
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr)
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
}
//返回当前满减券列表可用状态
export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
return coupArr.map(v => {
if (v.id == selCoup.id) {
return v
}
const isfullAmount = payPrice >= v.fullAmount * 1
return {
...v,
use: v.use && isfullAmount
}
})
}

View File

@ -131,7 +131,7 @@ export function returnProductCouponPrice(coup, goodsArr, vipUser) {
}
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
return price
return price*coup.num
}
//返回新的商品列表,过滤掉退菜的,退单的商品