优化结算选择优惠券

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-clipboard3": "^2.0.0",
"vue-i18n": "^11.1.0", "vue-i18n": "^11.1.0",
"vue-router": "^4.5.0", "vue-router": "^4.5.0",
"ysk-utils": "^1.0.74" "ysk-utils": "^1.0.77"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^19.7.1", "@commitlint/cli": "^19.7.1",

View File

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