feat: 代客下单优惠券更新,挂账更新
This commit is contained in:
@@ -31,7 +31,15 @@
|
||||
<div class="score">
|
||||
<div class="u-flex u-col-center u-m-t-10">
|
||||
<span class="u-font-14 font-bold u-m-r-20">积分抵扣</span>
|
||||
<el-radio-group v-model="score.sel" size="small" class="">
|
||||
<el-radio-group
|
||||
:disabled="!pointsRes.usable"
|
||||
v-model="score.sel"
|
||||
size="small"
|
||||
class=""
|
||||
>
|
||||
<el-radio :value="-1">
|
||||
<span class="u-font-14">不使用</span>
|
||||
</el-radio>
|
||||
<el-radio :value="0">
|
||||
<span class="u-font-14">全部抵扣</span>
|
||||
</el-radio>
|
||||
@@ -39,10 +47,27 @@
|
||||
<span class="u-font-14">部分抵扣</span>
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
<el-input-number
|
||||
class="u-m-l-10"
|
||||
v-if="score.sel == 1"
|
||||
v-model="usePointsNumber"
|
||||
step-strictly
|
||||
placeholder="请输入积分抵扣数量"
|
||||
:min="pointsRes.minDeductionPoints"
|
||||
:max="pointsRes.maxUsablePoints"
|
||||
@change="pointsToMoney"
|
||||
></el-input-number>
|
||||
</div>
|
||||
<p class="u-font-14 color-666 u-m-t-10">
|
||||
<p
|
||||
class="u-font-14 color-666 u-m-t-10"
|
||||
v-if="pointsRes.unusableReason && !pointsRes.usable"
|
||||
>
|
||||
<span class="color-red">*</span>
|
||||
<span>积分不足或小于最低使用门槛1</span>
|
||||
<span>{{ pointsRes.unusableReason }}</span>
|
||||
</p>
|
||||
<p class="u-font-14 color-666 u-m-t-10" v-else>
|
||||
<span class="color-red">*</span>
|
||||
<span>{{ pointsRes.equivalentPoints }}积分等于1元</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="u-flex u-col-center u-m-t-20 no-wrap">
|
||||
@@ -60,6 +85,51 @@
|
||||
<el-icon><ArrowDown /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-m-t-20" 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" v-if="scope.row.type == 2">
|
||||
<div class="u-flex">
|
||||
<el-image
|
||||
:src="scope.row.productImg"
|
||||
fit="cover"
|
||||
style="width: 40px; height: 40px"
|
||||
:preview-src-list="[scope.row.productImg]"
|
||||
></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" 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="">
|
||||
<template v-slot="scope">
|
||||
<el-button type="danger" size="small" @click="delQuan(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -105,12 +175,16 @@
|
||||
<span class="u-m-l-10 value">¥{{ carts.payMoney }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">优惠券</span>
|
||||
<span class="u-m-l-10 value">¥{{ coupDiscount }}</span>
|
||||
<span class="title">商品优惠券</span>
|
||||
<span class="u-m-l-10 value">¥{{ productCouponDiscountAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">满减优惠券</span>
|
||||
<span class="u-m-l-10 value">¥{{ fullCouponDiscountAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">积分抵扣</span>
|
||||
<span class="u-m-l-10 value">-¥{{ orderInfo.pointsDiscountAmount || 0 }}</span>
|
||||
<span class="u-m-l-10 value">-¥{{ pointsDiscountAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">整单改价</span>
|
||||
@@ -118,7 +192,7 @@
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">抹零</span>
|
||||
<span class="u-m-l-10 value">-¥{{ orderInfo.pointsDiscountAmount || 0 }}</span>
|
||||
<span class="u-m-l-10 value">-¥{{ 0 }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">应付金额</span>
|
||||
@@ -127,20 +201,17 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- 扫码 -->
|
||||
<scanPay
|
||||
ref="refScanPay"
|
||||
:order="orderInfo"
|
||||
@paySuccess="paySuccess"
|
||||
@confirm="refScanPayConfirm"
|
||||
></scanPay>
|
||||
<scanPay ref="refScanPay" :order="orderInfo" @confirm="refScanPayConfirm"></scanPay>
|
||||
<!-- 打折 -->
|
||||
<discount ref="refDiscount" @confirm="discountConfirm"></discount>
|
||||
<!-- 优惠券 -->
|
||||
<popup-coupon ref="refCoupon" @confirm="refCouponConfirm"></popup-coupon>
|
||||
<popup-coupon ref="refCoupon" :user="user" @confirm="refCouponConfirm"></popup-coupon>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import * as quanUtil from "../quan_util.js";
|
||||
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
const carts = useCartsStore();
|
||||
|
||||
@@ -154,10 +225,48 @@ import discount from "./discount.vue";
|
||||
import { ElLoading } from "element-plus";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
|
||||
//商品列表
|
||||
let goodsArr = [];
|
||||
|
||||
//优惠券
|
||||
let $goodsPayPriceMap = {};
|
||||
const refCoupon = ref();
|
||||
let quansSelArr = ref([]);
|
||||
function openCoupon() {
|
||||
refCoupon.value.open();
|
||||
refCoupon.value.open(carts.payMoney, props.orderInfo);
|
||||
}
|
||||
//返回商品券抵扣金额
|
||||
function returnProDiscount(row) {
|
||||
//相同商品抵扣券数组
|
||||
const arr = quansSelArr.value.filter((v) => v.type == 2 && v.proId == row.proId);
|
||||
console.log(arr);
|
||||
const index = arr.findIndex((v) => v.id == row.id);
|
||||
const item = goodsArr.find((v) => v.productId == row.proId);
|
||||
if (index != -1) {
|
||||
const n = quanUtil.returnProductCoupAllPrice(
|
||||
$goodsPayPriceMap[row.proId],
|
||||
index,
|
||||
row.num,
|
||||
props.user.id && props.user.isVip
|
||||
);
|
||||
return n.toFixed(2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
function refCouponConfirm(e, goodsPayPriceMap, goodsList) {
|
||||
goodsArr = goodsList;
|
||||
usePointsNumber.value = 0;
|
||||
pointsDiscountAmount.value = 0;
|
||||
score.sel = -1;
|
||||
quansSelArr.value = e;
|
||||
$goodsPayPriceMap = goodsPayPriceMap;
|
||||
}
|
||||
function delQuan(row) {
|
||||
const index = quansSelArr.value.findIndex((v) => v.id == row.id);
|
||||
if (index != -1) {
|
||||
quansSelArr.value.splice(index, 1);
|
||||
}
|
||||
}
|
||||
function couponChange(data) {}
|
||||
|
||||
@@ -172,7 +281,7 @@ function discountConfirm(e) {
|
||||
Object.assign(checkOrderPay, e);
|
||||
if (e.discount) {
|
||||
checkOrderPay.discountAmount =
|
||||
carts.payMoney - (carts.payMoney * (e.discount / 100).toFixed(2)).toFixed(2);
|
||||
carts.payMoney - ((carts.payMoney * (100 - e.discount)) / 100).toFixed(2);
|
||||
} else {
|
||||
checkOrderPay.discount = 0;
|
||||
}
|
||||
@@ -218,16 +327,43 @@ watch(
|
||||
);
|
||||
|
||||
//002-获取订单可用积分及抵扣金额(支付页面使用)
|
||||
function pointsInit() {
|
||||
if (!props.user.id) {
|
||||
const pointsRes = ref({ usable: false, maxUsablePoints: 0, minDeductionPoints: 0 });
|
||||
const usePointsNumber = ref(0);
|
||||
const orderAmountOrderAmount = computed(() => {
|
||||
return (carts.payMoney - checkOrderPay.discountAmount).toFixed(2);
|
||||
});
|
||||
const pointsDiscountAmount = ref(0);
|
||||
watch(
|
||||
() => orderAmountOrderAmount.value,
|
||||
(newval) => {
|
||||
pointsInit();
|
||||
}
|
||||
);
|
||||
|
||||
async function pointsInit() {
|
||||
if (!props.user.id || score.sel == -1) {
|
||||
return;
|
||||
}
|
||||
PointsApi.calcOrderUsablePoints({
|
||||
const res = await PointsApi.calcOrderUsablePoints({
|
||||
userId: props.user.id,
|
||||
orderAmount: (carts.payMoney - checkOrderPay.discountAmount).toFixed(2),
|
||||
orderAmount: currentpayMoney.value - pointsDiscountAmount.value,
|
||||
});
|
||||
pointsRes.value = res;
|
||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||
if (res.usable) {
|
||||
pointsToMoney();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// 根据积分计算可抵扣金额
|
||||
async function pointsToMoney() {
|
||||
const res = await PointsApi.calcPointsToMoney({
|
||||
userId: props.user.id,
|
||||
orderAmount: currentpayMoney.value - pointsDiscountAmount.value,
|
||||
points: usePointsNumber.value,
|
||||
});
|
||||
pointsDiscountAmount.value = res;
|
||||
}
|
||||
|
||||
const emits = defineEmits(["chooseUser", "paysuccess"]);
|
||||
function chooseUser() {
|
||||
emits("chooseUser");
|
||||
@@ -240,7 +376,7 @@ const coupDiscount = computed(() => {
|
||||
}
|
||||
return total.toFixed(2);
|
||||
});
|
||||
const score = ref({
|
||||
const score = reactive({
|
||||
list: [],
|
||||
sel: 0,
|
||||
});
|
||||
@@ -249,6 +385,18 @@ const payTypes = reactive({
|
||||
list: [],
|
||||
sel: 0,
|
||||
});
|
||||
watch(
|
||||
() => score.sel,
|
||||
(newval) => {
|
||||
console.log(newval);
|
||||
if (newval == -1) {
|
||||
usePointsNumber.value = 0;
|
||||
pointsDiscountAmount.value = 0;
|
||||
} else {
|
||||
pointsInit();
|
||||
}
|
||||
}
|
||||
);
|
||||
function canUsePayType(item) {
|
||||
if (currentpayMoney.value * 1 == 0) {
|
||||
return item.payType == "cash" ? false : true;
|
||||
@@ -278,16 +426,16 @@ function returnPayParams() {
|
||||
vipPrice: props.user.id && props.user.isVip ? 1 : 0,
|
||||
orderId: props.orderInfo.id,
|
||||
// discountRatio: (checkOrderPay.discount / 100).toFixed(2),
|
||||
discountRatio: 0,
|
||||
discountRatio: checkOrderPay.discount ? checkOrderPay.discount : 0,
|
||||
seatNum: props.orderInfo.seatNum,
|
||||
originAmount: carts.payMoney * 1,
|
||||
discountAmount: checkOrderPay.discountAmount * 1,
|
||||
productCouponDiscountAmount: props.orderInfo.productCouponDiscountAmount || 0,
|
||||
discountAmount: !checkOrderPay.discount ? checkOrderPay.discountAmount * 1 : 0,
|
||||
productCouponDiscountAmount: 0,
|
||||
orderAmount: currentpayMoney.value * 1,
|
||||
roundAmount: props.orderInfo.roundAmount,
|
||||
pointsDiscountAmount: props.orderInfo.pointsDiscountAmount || 0,
|
||||
pointsNum: props.orderInfo.pointsNum,
|
||||
fullCouponDiscountAmount: props.orderInfo.fullCouponDiscountAmount || 0,
|
||||
pointsDiscountAmount: pointsDiscountAmount.value * 1,
|
||||
pointsNum: usePointsNumber.value * 1,
|
||||
fullCouponDiscountAmount: 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -387,13 +535,34 @@ async function payOrder(payType, isScan) {
|
||||
loading.close();
|
||||
}
|
||||
}
|
||||
|
||||
//满减优惠券
|
||||
const fullCouponDiscountAmount = computed(() => {
|
||||
return quansSelArr.value
|
||||
.reduce((pre, cur) => {
|
||||
return pre + cur.discountAmount;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
});
|
||||
//商品券抵扣金额
|
||||
const productCouponDiscountAmount = computed(() => {
|
||||
let index = -1;
|
||||
return quansSelArr.value.reduce((pre, cur) => {
|
||||
index++;
|
||||
return pre + returnProDiscount(cur, index) * 1;
|
||||
}, 0);
|
||||
});
|
||||
//应付金额
|
||||
const currentpayMoney = computed(() => {
|
||||
if (checkOrderPay.discount) {
|
||||
return (carts.payMoney * (checkOrderPay.discount / 100)).toFixed(2);
|
||||
}
|
||||
return (carts.payMoney - checkOrderPay.discountAmount).toFixed(2);
|
||||
return (
|
||||
carts.payMoney -
|
||||
productCouponDiscountAmount.value -
|
||||
fullCouponDiscountAmount.value -
|
||||
checkOrderPay.discountAmount -
|
||||
pointsDiscountAmount.value
|
||||
).toFixed(2);
|
||||
});
|
||||
watch(
|
||||
() => currentpayMoney.value,
|
||||
@@ -405,7 +574,6 @@ watch(
|
||||
);
|
||||
onMounted(() => {
|
||||
getPaytype();
|
||||
pointsInit();
|
||||
});
|
||||
defineExpose({
|
||||
nowPayClick,
|
||||
|
||||
Reference in New Issue
Block a user