fix: 问题修复

This commit is contained in:
2025-10-13 11:19:26 +08:00
parent b4b87218d1
commit cd351be6d0
7 changed files with 80 additions and 65 deletions

View File

@@ -36,15 +36,15 @@
<span class="u-font-14">不使用</span>
</el-radio>
<el-radio :value="0" :disabled="!pointsRes.usable">
<span class="u-font-14">全部抵扣</span>
<span class="u-font-14">使用</span>
</el-radio>
<el-radio :value="1" :disabled="!pointsRes.usable">
<!-- <el-radio :value="1" :disabled="!pointsRes.usable">
<span class="u-font-14">部分抵扣</span>
</el-radio>
</el-radio> -->
</el-radio-group>
<el-input-number
class="u-m-l-10"
v-if="score.sel == 1"
v-if="score.sel != -1"
v-model="usePointsNumber"
step-strictly
:step="pointsRes.equivalentPoints"
@@ -277,9 +277,6 @@ function refCouponConfirm(e, goodsList) {
};
});
goodsArr = goodsList;
usePointsNumber.value = 0;
pointsDiscountAmount.value = 0;
score.sel = -1;
console.log("refCouponConfirm", e);
carts.setCoupons(e);
@@ -399,29 +396,24 @@ const pointsRes = ref({ usable: true, maxUsablePoints: 0, minDeductionPoints: 0
const usePointsNumber = ref(0);
//积分可抵扣最大金额
const scoreMaxMoney = computed(() => {
return carts.orderCostSummary.finalPayAmount - carts.orderCostSummary.pointDeductionAmount;
return carts.orderCostSummary.finalPayAmount + carts.orderCostSummary.pointDeductionAmount;
});
const pointsDiscountAmount = ref(0);
watch(
() => scoreMaxMoney.value,
(newval) => {
pointsInit();
(newval, oldval) => {
if (newval != oldval) {
pointsInit();
}
}
);
// 返回积分抵扣前金额
function returnPointsDiscountAmount() {
const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1;
return total <= 0 ? 0 : total;
}
async function pointsInit() {
if (!props.user.id) {
return;
}
const res = await PointsApi.calcOrderUsablePoints({
shopUserId: props.user.id,
orderAmount: returnPointsDiscountAmount(),
orderAmount: scoreMaxMoney.value,
});
pointsRes.value = res;
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
@@ -431,29 +423,12 @@ async function pointsInit() {
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
if (res.usable) {
pointsToMoney();
} else {
score.sel = -1;
}
return res;
}
// 根据积分计算可抵扣金额
async function pointsToMoney() {
try {
const res = await PointsApi.calcPointsToMoney({
shopUserId: props.user.id,
orderAmount: returnPointsDiscountAmount(),
points: usePointsNumber.value,
});
if (!res) {
score.sel = -1;
return;
}
pointsDiscountAmount.value = res;
} catch (e) {
score.sel = -1;
}
}
const emits = defineEmits(["chooseUser", "paysuccess"]);
function chooseUser() {
emits("chooseUser");
@@ -480,7 +455,6 @@ watch(
(newval) => {
console.log(newval);
usePointsNumber.value = 0;
pointsDiscountAmount.value = 0;
pointsInit();
}
);
@@ -667,16 +641,6 @@ const productCouponDiscountAmount = computed(() => {
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
return carts.orderCostSummary.productCouponDeduction;
});
//除开客座费,打包费总金额
const totalMoney = computed(() => {
return (
carts.goodsTotal -
productCouponDiscountAmount.value -
discountAmount.value -
fullCouponDiscountAmount.value -
pointsDiscountAmount.value
).toFixed(2);
});
const totalPrice = computed(() => {
// 使用bignumber.js处理高精度计算
@@ -693,7 +657,10 @@ const totalPrice = computed(() => {
.minus(merchantReduction)
.minus(pointDeduction)
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
const n = total.toNumber();
if (n <= 0) {
return 0;
}
return total.toNumber();
});

View File

@@ -1,5 +1,5 @@
<template>
<el-dialog width="900px" :title="title" v-model="show" top="20px" @close="reset">
<el-dialog width="1000px" :title="title" v-model="show" top="20px" @close="reset">
<div class="u-p-15">
<div class="">
<el-tabs v-model="activeName" @tab-click="tabClick">
@@ -69,6 +69,12 @@
></el-checkbox>
</template>
</el-table-column>
<el-table-column prop="id" width="100" label="ID">
<template v-slot="scope">
{{ scope.row.id }}
</template>
</el-table-column>
<el-table-column type="index" width="50" label="#"></el-table-column>
<el-table-column prop="name" label="券名称"></el-table-column>
@@ -280,6 +286,7 @@ async function getcoup() {
let noUseGoodsCoupon = [];
let noUseDiscountCoupon = [];
console.log("orderPrice", orderPrice.value);
for (let i = 0; i < couponList.length; i++) {
const coupon = couponList[i];
const selCoupon =
@@ -289,7 +296,7 @@ async function getcoup() {
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
orderPrice: orderPrice.value,
goodsOrderPrice: orderPrice.value,
user: props.user,
selCoupon,
shopInfo: shopUser.userInfo,
@@ -323,7 +330,7 @@ async function getcoup() {
v,
props.user,
orderPrice.value,
quansSelArr.value,
quansSelArr.value.filter((v) => v.type != 2),
shopUser.userInfo
);
return {
@@ -339,7 +346,7 @@ async function getcoup() {
v,
props.user,
orderPrice.value,
quansSelArr.value,
quansSelArr.value.filter((v) => v.type == 2),
shopUser.userInfo
);
return {
@@ -426,6 +433,15 @@ function updateSelCoupon() {
};
});
otherCoupon = otherCoupon.map((v) => {
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon: v,
orderPrice: orderPrice.value,
user: props.user,
selCoupon: goodsCoupon,
shopInfo: shopUser.userInfo,
});
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
@@ -436,12 +452,35 @@ function updateSelCoupon() {
);
return {
...v,
canuseResult,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
couponSel.value = otherCoupon[0];
if (!otherCoupon[0].canuseResult.canUse) {
couponSel.value = { id: "" };
ElMessageBox.confirm(
`选择该券后优惠券${otherCoupon[0].name}不可用,不可用原因:${otherCoupon[0].canuseResult.reason}`,
"提示",
{
type: "warning",
showCancelButton: true,
cancelButtonText: "取消当前券的选择",
confirmButtonText: "剔除不可用的优惠券",
}
)
.then(() => {
couponSel.value = { id: "" };
goodsCouponSel.value = goodsCoupon[0];
})
.catch(() => {
goodsCouponSel.value = { id: "" };
couponSel.value = otherCoupon[0];
});
return;
}
goodsCouponSel.value = goodsCoupon[0];
couponSel.value = otherCoupon[0];
}
}