优化积分使用
This commit is contained in:
@@ -656,7 +656,8 @@ const pointOptions = ref({
|
|||||||
consumeAmount: 0, // 每消费xx元赠送1积分
|
consumeAmount: 0, // 每消费xx元赠送1积分
|
||||||
minPaymentAmount: 0, // 下单实付抵扣门槛(元)
|
minPaymentAmount: 0, // 下单实付抵扣门槛(元)
|
||||||
maxDeductionRatio: 0, // 下单最高抵扣比例(如 0.2 表示最多抵扣 20%)
|
maxDeductionRatio: 0, // 下单最高抵扣比例(如 0.2 表示最多抵扣 20%)
|
||||||
equivalentPoints: 0, // 1元 = ? 积分
|
equivalentPoints: 0, // 兼容字段:1元 = ? 积分(保留)
|
||||||
|
pointsPerYuan: 0, // 积分数/元,例如 20 表示 20 积分 = 1 元
|
||||||
enablePointsMall: 0, // 是否开启积分商城
|
enablePointsMall: 0, // 是否开启积分商城
|
||||||
|
|
||||||
// 派生字段(页面使用)
|
// 派生字段(页面使用)
|
||||||
@@ -743,12 +744,12 @@ function cancelAllDiscount() {
|
|||||||
function updateCartCalc() {
|
function updateCartCalc() {
|
||||||
// 计算最大抵扣金额(按订单金额 * 最大抵扣比例)
|
// 计算最大抵扣金额(按订单金额 * 最大抵扣比例)
|
||||||
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
||||||
const maxDeductionAmount = (pointOptions.value.maxDeductionRatio && pointOptions.value.equivalentPoints !== undefined)
|
const maxDeductionAmount = (pointOptions.value.maxDeductionRatio && pointOptions.value.pointsPerYuan)
|
||||||
? orderAmount * pointOptions.value.maxDeductionRatio
|
? orderAmount * pointOptions.value.maxDeductionRatio
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
goodsStore.calcCartInfo({
|
goodsStore.calcCartInfo({
|
||||||
pointsPerYuan: pointOptions.value.equivalentPoints,
|
pointsPerYuan: pointOptions.value.pointsPerYuan,
|
||||||
maxDeductionAmount: maxDeductionAmount,
|
maxDeductionAmount: maxDeductionAmount,
|
||||||
userPoints: couponForm.value.pointsNum,
|
userPoints: couponForm.value.pointsNum,
|
||||||
backendCoupons: couponResList1.value,
|
backendCoupons: couponResList1.value,
|
||||||
@@ -773,8 +774,8 @@ const pointInput = _.debounce(function (e) {
|
|||||||
console.log('inputFilterInt===', couponForm.value.pointsNum);
|
console.log('inputFilterInt===', couponForm.value.pointsNum);
|
||||||
|
|
||||||
// 未登录用户或无可用积分时直接归0并返回
|
// 未登录用户或无可用积分时直接归0并返回
|
||||||
const userAvailablePoints = Number(couponFormUser.accountPoints || 0)
|
const userAvailablePoints = Number(couponFormUser.value && couponFormUser.value.accountPoints ? couponFormUser.value.accountPoints : 0)
|
||||||
if (!couponFormUser.id || userAvailablePoints <= 0) {
|
if (!couponFormUser.value || !couponFormUser.value.id || userAvailablePoints <= 0) {
|
||||||
couponForm.value.pointsNum = 0
|
couponForm.value.pointsNum = 0
|
||||||
pointOptions.value.amount = 0
|
pointOptions.value.amount = 0
|
||||||
updateCartCalc()
|
updateCartCalc()
|
||||||
@@ -817,11 +818,11 @@ const pointInput = _.debounce(function (e) {
|
|||||||
// 根据积分计算可抵扣金额(前端计算,不依赖后端)
|
// 根据积分计算可抵扣金额(前端计算,不依赖后端)
|
||||||
const calcPointMoney = async () => {
|
const calcPointMoney = async () => {
|
||||||
try {
|
try {
|
||||||
const eq = Number(pointOptions.value.equivalentPoints || 0) // 积分与元的换算:1元 = eq 积分
|
const pointsPerYuan = Number(pointOptions.value.pointsPerYuan || 0) // 积分数/元,例如 20 表示 20 积分 = 1 元
|
||||||
const points = Number(couponForm.value.pointsNum || 0)
|
const points = Number(couponForm.value.pointsNum || 0)
|
||||||
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
||||||
|
|
||||||
if (!eq || points <= 0) {
|
if (!pointsPerYuan || points <= 0) {
|
||||||
pointOptions.value.amount = 0
|
pointOptions.value.amount = 0
|
||||||
// 若未初始化 couponForm.value.amount,则用订单原价
|
// 若未初始化 couponForm.value.amount,则用订单原价
|
||||||
couponForm.value.amount = couponForm.value.amount || originOrderAmount.value || orderAmount
|
couponForm.value.amount = couponForm.value.amount || originOrderAmount.value || orderAmount
|
||||||
@@ -829,8 +830,8 @@ const calcPointMoney = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 积分可抵扣的金额(元)
|
// 积分可抵扣的金额(元) => 积分 / (积分数/元)
|
||||||
let deductionFromPoints = points / eq
|
let deductionFromPoints = points / pointsPerYuan
|
||||||
|
|
||||||
// 最大可抵扣金额基于订单金额和最大抵扣比例
|
// 最大可抵扣金额基于订单金额和最大抵扣比例
|
||||||
const maxDeductionAmount = orderAmount * (pointOptions.value.maxDeductionRatio || 0)
|
const maxDeductionAmount = orderAmount * (pointOptions.value.maxDeductionRatio || 0)
|
||||||
@@ -930,7 +931,7 @@ async function selectUserHandle(row) {
|
|||||||
pointOptionsAjax()
|
pointOptionsAjax()
|
||||||
|
|
||||||
// 已存在选择的用户,并且切换了不通用户
|
// 已存在选择的用户,并且切换了不通用户
|
||||||
if (couponFormUser.id && row.userId != couponFormUser.value.userId) {
|
if (couponFormUser.value && couponFormUser.value.id && row.userId != couponFormUser.value.userId) {
|
||||||
resetCoupon()
|
resetCoupon()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -973,15 +974,18 @@ async function pointOptionsAjax() {
|
|||||||
pointOptions.value.equivalentPoints = Number(res.equivalentPoints || 0)
|
pointOptions.value.equivalentPoints = Number(res.equivalentPoints || 0)
|
||||||
pointOptions.value.enablePointsMall = Number(res.enablePointsMall || 0)
|
pointOptions.value.enablePointsMall = Number(res.enablePointsMall || 0)
|
||||||
|
|
||||||
|
// 后端的 equivalentPoints 表示 积分数/元(例如 20 表示 20 积分 = 1 元)
|
||||||
|
pointOptions.value.pointsPerYuan = pointOptions.value.equivalentPoints
|
||||||
|
|
||||||
// 计算页面需要的最小/最大可用积分(按接口返回的金额阈值与比例换算为积分)
|
// 计算页面需要的最小/最大可用积分(按接口返回的金额阈值与比例换算为积分)
|
||||||
const eq = pointOptions.value.equivalentPoints || 0
|
const pointsPerYuan = pointOptions.value.pointsPerYuan || 0
|
||||||
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
const orderAmount = Number(goodsStore.cartInfo.costSummary.finalPayAmount || 0)
|
||||||
|
|
||||||
// 最少使用积分:基于最小抵扣金额换算(若无则为0)
|
// 最少使用积分:基于最小抵扣金额换算(若无则为0),minPaymentAmount 单位为元
|
||||||
pointOptions.value.minPoints = pointOptions.value.minPaymentAmount && eq ? Math.ceil(pointOptions.value.minPaymentAmount * eq) : 0
|
pointOptions.value.minPoints = pointOptions.value.minPaymentAmount && pointsPerYuan ? Math.ceil(pointOptions.value.minPaymentAmount * pointsPerYuan) : 0
|
||||||
|
|
||||||
// 最大可用积分:基于订单金额与最大抵扣比例换算
|
// 最大可用积分:基于订单金额与最大抵扣比例换算
|
||||||
pointOptions.value.maxPoints = (pointOptions.value.maxDeductionRatio && eq) ? Math.floor(orderAmount * pointOptions.value.maxDeductionRatio * eq) : 0
|
pointOptions.value.maxPoints = (pointOptions.value.maxDeductionRatio && pointsPerYuan) ? Math.floor(orderAmount * pointOptions.value.maxDeductionRatio * pointsPerYuan) : 0
|
||||||
|
|
||||||
// 可用性
|
// 可用性
|
||||||
pointOptions.value.usable = pointOptions.value.enableRewards === 1 && pointOptions.value.maxPoints > 0
|
pointOptions.value.usable = pointOptions.value.enableRewards === 1 && pointOptions.value.maxPoints > 0
|
||||||
|
|||||||
Reference in New Issue
Block a user