优化标签logo无法更换的问题
This commit is contained in:
@@ -439,11 +439,17 @@ async function pointsInit() {
|
||||
|
||||
// 保险取值
|
||||
const eq = pointsConfig?.equivalentPoints || 0;
|
||||
const maxRatio = pointsConfig?.maxDeductionRatio || 0;
|
||||
const rawMaxRatio = pointsConfig?.maxDeductionRatio || 0;
|
||||
// 兼容后端返回的百分比或小数两种形式:如果大于1,则视为百分比(如100表示100%),需除以100
|
||||
const maxRatio = rawMaxRatio > 1 ? rawMaxRatio / 100 : rawMaxRatio;
|
||||
const minPay = pointsConfig?.minPaymentAmount || 0;
|
||||
|
||||
// 计算当前订单可抵扣金额上限(元)
|
||||
// 使用“抵扣前实付金额”作为门槛判断(即把当前已应用的积分抵扣金额加回),
|
||||
// 避免在已经抵扣导致 finalPay 变小后错误地判定为不可用。
|
||||
let finalPay = Number(carts.orderCostSummary.finalPayAmount) || 0;
|
||||
const currentPointDeduction = Number(carts.orderCostSummary.pointDeductionAmount) || 0;
|
||||
const basePay = finalPay + currentPointDeduction;
|
||||
|
||||
const res = {
|
||||
usable: true,
|
||||
@@ -455,8 +461,9 @@ async function pointsInit() {
|
||||
unusableReason: "",
|
||||
};
|
||||
|
||||
// 如果订单实付低于最小使用门槛,则不可用
|
||||
if (finalPay <= 0 || (minPay > 0 && finalPay < minPay)) {
|
||||
// 如果订单实付低于最小使用门槛,则不可用(门槛仅作为启用条件)
|
||||
// 这里使用 basePay(抵扣前实付)进行判断,确保已填写积分后不会回退为不可用
|
||||
if (basePay <= 0 || (minPay > 0 && basePay < minPay)) {
|
||||
res.usable = false;
|
||||
res.unusableReason = `订单实付金额低于 ${minPay} 元,无法使用积分抵扣`;
|
||||
} else if (eq <= 0) {
|
||||
@@ -464,23 +471,22 @@ async function pointsInit() {
|
||||
res.unusableReason = `积分换算比例配置错误,无法使用积分抵扣`;
|
||||
} else {
|
||||
// 计算基于比例限制的最大抵扣金额(元)
|
||||
let maxByRatio = finalPay * maxRatio;
|
||||
// 保证抵扣后剩余金额 >= minPaymentAmount
|
||||
if (minPay > 0) {
|
||||
const allowed = finalPay - minPay;
|
||||
if (allowed <= 0) {
|
||||
res.usable = false;
|
||||
res.unusableReason = `抵扣后实付金额必须大于等于 ${minPay} 元,当前不可使用积分`;
|
||||
} else {
|
||||
maxByRatio = Math.min(maxByRatio, allowed);
|
||||
}
|
||||
}
|
||||
// 注意:此处不再减少 minPaymentAmount,minPaymentAmount 仅用作是否可用的门槛;
|
||||
// 真正的最大抵扣由 maxRatio(抵扣比例)与用户积分数量共同决定。
|
||||
// 计算基于比例限制的最大抵扣金额(元),基于抵扣前实付金额
|
||||
let maxByRatio = basePay * maxRatio;
|
||||
|
||||
if (res.usable) {
|
||||
// 可用积分上限(向下取整为 eq 的倍数)
|
||||
// 可用积分上限(按等价积分步长对齐到 eq 的倍数)
|
||||
const maxByMoney = Math.floor(maxByRatio * eq);
|
||||
const userPoints = carts.vipUser.pointBalance || 0;
|
||||
res.maxUsablePoints = Math.min(userPoints, maxByMoney);
|
||||
let computedMax = Math.min(userPoints, maxByMoney);
|
||||
// 对齐到等价积分步长,保证输入步长生效
|
||||
if (eq > 0) {
|
||||
computedMax = Math.floor(computedMax / eq) * eq;
|
||||
}
|
||||
res.maxUsablePoints = computedMax;
|
||||
console.debug("pointsInit debug:", { finalPay: finalPay, basePay: basePay, eq, rawMaxRatio, maxRatio, maxByMoney, userPoints, computedMax });
|
||||
// 最小抵扣积分为配置值或等于换算比
|
||||
res.minDeductionPoints = pointsConfig?.minDeductionPoints || eq;
|
||||
if (res.maxUsablePoints < res.minDeductionPoints) {
|
||||
@@ -498,8 +504,20 @@ async function pointsInit() {
|
||||
return res;
|
||||
}
|
||||
|
||||
// 如果可用则默认填充可用最大值,否则清零
|
||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||
// 如果可用则默认填充可用最大值(对齐步长),否则清零
|
||||
if (res.usable) {
|
||||
// 计算默认填充值:基于抵扣前实付的比例上限与等价比计算需要的积分数
|
||||
const defaultMaxByMoney = Math.floor(basePay * res.maxDeductionRatio * res.equivalentPoints);
|
||||
let defaultPts = Math.min(res.maxUsablePoints || 0, defaultMaxByMoney || 0);
|
||||
if (res.equivalentPoints > 0) {
|
||||
defaultPts = Math.floor(defaultPts / res.equivalentPoints) * res.equivalentPoints;
|
||||
}
|
||||
// 最终确保不超过用户积分
|
||||
const userPts = carts.vipUser.pointBalance || 0;
|
||||
usePointsNumber.value = Math.min(defaultPts, userPts);
|
||||
} else {
|
||||
usePointsNumber.value = 0;
|
||||
}
|
||||
if (!res.usable) score.sel = -1;
|
||||
|
||||
return res;
|
||||
@@ -532,17 +550,15 @@ function pointsToMoney(val) {
|
||||
// 再次校验不超过允许的最大抵扣金额(基于比例或门槛)
|
||||
let finalPay = Number(carts.orderCostSummary.finalPayAmount) || 0;
|
||||
let maxByRatio = finalPay * cfg.maxDeductionRatio;
|
||||
if (cfg.minPaymentAmount > 0) {
|
||||
const allowed = finalPay - cfg.minPaymentAmount;
|
||||
if (allowed <= 0) {
|
||||
usePointsNumber.value = 0;
|
||||
carts.orderCostSummary.pointUsed = 0;
|
||||
carts.orderCostSummary.pointDeductionAmount = 0;
|
||||
return;
|
||||
}
|
||||
maxByRatio = Math.min(maxByRatio, allowed);
|
||||
// 对于单笔抵扣:若订单实付低于配置的最小门槛,则不可使用(作为启用条件)
|
||||
if (cfg.minPaymentAmount > 0 && finalPay < cfg.minPaymentAmount) {
|
||||
usePointsNumber.value = 0;
|
||||
carts.orderCostSummary.pointUsed = 0;
|
||||
carts.orderCostSummary.pointDeductionAmount = 0;
|
||||
return;
|
||||
}
|
||||
const maxAllowedMoney = new BigNumber(maxByRatio).decimalPlaces(2, BigNumber.ROUND_DOWN).toNumber();
|
||||
console.debug("pointsToMoney debug:", { finalPay, cfg, pts, money, maxByRatio, maxAllowedMoney });
|
||||
if (money > maxAllowedMoney) {
|
||||
// 调整积分到允许的最大金额对应的积分
|
||||
const allowedPts = Math.floor(maxAllowedMoney * cfg.equivalentPoints);
|
||||
@@ -858,9 +874,13 @@ defineExpose({
|
||||
.order-info {
|
||||
font-size: 14px;
|
||||
|
||||
.title {}
|
||||
.title {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.value {}
|
||||
.value {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.price {
|
||||
color: #fa5555;
|
||||
|
||||
Reference in New Issue
Block a user