优化结算选择优惠券

This commit is contained in:
gyq
2025-11-18 14:32:09 +08:00
parent 9441a3c6d8
commit 156af8beeb
2 changed files with 44 additions and 45 deletions

View File

@@ -69,7 +69,7 @@
"vue-clipboard3": "^2.0.0",
"vue-i18n": "^11.1.0",
"vue-router": "^4.5.0",
"ysk-utils": "^1.0.74"
"ysk-utils": "^1.0.77"
},
"devDependencies": {
"@commitlint/cli": "^19.7.1",

View File

@@ -4,25 +4,18 @@
<div class="">
<el-tabs v-model="activeName" @tab-click="tabClick">
<el-tab-pane label="优惠券(单选)" name="youhui">
<el-table
ref="refTable"
empty-text="无可用优惠券"
:data="quans.coupon"
max-height="40vh"
>
<el-table ref="refTable" empty-text="无可用优惠券" :data="quans.coupon" max-height="40vh">
<el-table-column type="index" label="">
<template v-slot="scope">
<el-checkbox
@change="couponClick($event, scope.row)"
:model-value="scope.row.id == couponSel.id"
></el-checkbox>
<el-checkbox @change="couponClick($event, scope.row)"
:model-value="scope.row.id == couponSel.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">
{{ UTILS.returnCoupType(scope.row) }}
{{ couponUtils.returnCoupType(scope.row) }}
</template>
</el-table-column>
<el-table-column prop="discountAmount" label="抵扣" align="center">
@@ -54,19 +47,12 @@
</el-table>
</el-tab-pane>
<el-tab-pane label="商品券(单选)" name="goods">
<el-table
ref="refTable1"
empty-text="无可用商品券"
:data="quans.productCoupon"
style="width: 100%"
max-height="40vh"
>
<el-table ref="refTable1" empty-text="无可用商品券" :data="quans.productCoupon" style="width: 100%"
max-height="40vh">
<el-table-column width="80">
<template v-slot="scope">
<el-checkbox
@change="productCouponClick($event, scope.row)"
:model-value="goodsCouponSel.id == scope.row.id"
></el-checkbox>
<el-checkbox @change="productCouponClick($event, scope.row)"
:model-value="goodsCouponSel.id == scope.row.id"></el-checkbox>
</template>
</el-table-column>
<el-table-column prop="id" width="100" label="ID">
@@ -112,7 +98,7 @@
<el-table-column prop="name" label="券名称"></el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ UTILS.returnCoupType(scope.row) }}
{{ couponUtils.returnCoupType(scope.row) }}
</template>
</el-table-column>
<el-table-column label="商品信息" width="120">
@@ -142,7 +128,7 @@
<el-table-column prop="name" label="券名称"></el-table-column>
<el-table-column label="券类型" width="80">
<template v-slot="scope">
{{ UTILS.returnCoupType(scope.row) }}
{{ couponUtils.returnCoupType(scope.row) }}
</template>
</el-table-column>
<el-table-column label="商品信息" width="120">
@@ -173,11 +159,8 @@
<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"
>
<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>
@@ -193,9 +176,13 @@
<script setup>
import couponApi from "@/api/account/coupon";
import { BigNumber } from "bignumber.js";
import * as UTILS from "@/utils/coupon-utils.js";
import { couponUtils } from "ysk-utils";
import { ElMessageBox } from "element-plus";
import { useUserStoreHook } from "@/store/modules/user";
import { useCartsStore } from '@/store/modules/carts'
const cartStore = useCartsStore()
const shopUser = useUserStoreHook();
const props = defineProps({
@@ -216,7 +203,7 @@ const props = defineProps({
},
},
});
function tabClick() {}
function tabClick() { }
const state = reactive({
discount: 1,
@@ -270,7 +257,7 @@ function open(money, orderInfo) {
arr.push(...orderInfo.detailMap[i]);
}
goodsArr = arr;
canDikouGoodsArr = UTILS.returnCanDikouGoods(arr, props.user);
canDikouGoodsArr = couponUtils.returnCanDikouGoods(arr, props.user, cartStore.shopInfo);
console.log("canDikouGoodsArr", canDikouGoodsArr);
getcoup();
orderPrice.value = money;
@@ -279,6 +266,10 @@ function open(money, orderInfo) {
let couponList = [];
async function getcoup() {
console.log(cartStore.limitDiscountRes);
const res = await couponApi.findCoupon({ shopUserId: props.user.id });
couponList = res || [];
let canUseGoodsCoupon = [];
@@ -293,13 +284,14 @@ async function getcoup() {
activeName.value == "goods"
? quansSelArr.value.filter((v) => v.type != 2)
: quansSelArr.value.filter((v) => v.type == 2);
const canuseResult = UTILS.returnCouponCanUse({
const canuseResult = couponUtils.returnCouponCanUse({
canDikouGoodsArr,
coupon,
goodsOrderPrice: orderPrice.value,
user: props.user,
selCoupon,
shopInfo: shopUser.userInfo,
limitTimeDiscount: cartStore.limitDiscountRes
});
const { canUse, reason } = canuseResult;
if (coupon.type == 2) {
@@ -325,13 +317,14 @@ async function getcoup() {
//商品券
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
const discount = couponUtils.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value.filter((v) => v.type != 2),
shopUser.userInfo
shopUser.userInfo,
cartStore.limitDiscountRes
);
return {
...v,
@@ -341,13 +334,14 @@ async function getcoup() {
});
//非商品券
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
const discount = couponUtils.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
quansSelArr.value.filter((v) => v.type == 2),
shopUser.userInfo
shopUser.userInfo,
cartStore.limitDiscountRes
);
return {
...v,
@@ -418,13 +412,14 @@ function updateSelCoupon() {
let goodsCoupon = newval.filter((v) => v.type == 2);
let otherCoupon = newval.filter((v) => v.type != 2);
goodsCoupon = goodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(
const discount = couponUtils.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
[],
shopUser.userInfo
shopUser.userInfo,
cartStore.limitDiscountRes
);
return {
...v,
@@ -433,22 +428,24 @@ function updateSelCoupon() {
};
});
otherCoupon = otherCoupon.map((v) => {
const canuseResult = UTILS.returnCouponCanUse({
const canuseResult = couponUtils.returnCouponCanUse({
canDikouGoodsArr,
coupon: v,
orderPrice: orderPrice.value,
user: props.user,
selCoupon: goodsCoupon,
shopInfo: shopUser.userInfo,
limitTimeDiscount: cartStore.limitDiscountRes
});
const discount = UTILS.returnCouponDiscount(
const discount = couponUtils.returnCouponDiscount(
canDikouGoodsArr,
v,
props.user,
orderPrice.value,
goodsCoupon,
shopUser.userInfo
shopUser.userInfo,
cartStore.limitDiscountRes
);
return {
...v,
@@ -493,16 +490,18 @@ watch(
}
);
</script>
<style lang="scss" scoped>
<style lang="scss" scoped>
.line-th {
text-decoration: line-through;
}
.codeImg {
width: 160px;
border: 1px solid rgb(220, 223, 230);
height: 160px;
}
:deep(.el-input .el-input__inner::-webkit-inner-spin-button) {
-webkit-appearance: none;
margin: 0;