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();
});