|
|
@@ -72,15 +72,21 @@ export default {
|
|
|
let price = 0;
|
|
|
if (this.selectList) {
|
|
|
for (const item of this.selectList) {
|
|
|
- const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
- if ( itemInfo && !this.$util.isEmpty(itemInfo.bigPrice) && !this.$util.isEmpty(itemInfo.smallPrice) ) {
|
|
|
- price += item.bigCount * Number(itemInfo.bigPrice);
|
|
|
- price += item.smallCount * Number(itemInfo.smallPrice);
|
|
|
- }
|
|
|
+ price += this.getSelectItemTotalPrice(item);
|
|
|
}
|
|
|
}
|
|
|
return Math.round(price * 100) / 100;
|
|
|
},
|
|
|
+ // 满减优惠总额
|
|
|
+ allReachDiscountAmount() {
|
|
|
+ let discount = 0;
|
|
|
+ if (this.selectList) {
|
|
|
+ for (const item of this.selectList) {
|
|
|
+ discount += this.getReachDiscountAmount(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Math.round(discount * 100) / 100;
|
|
|
+ },
|
|
|
allPriceFun() {
|
|
|
let price = 0;
|
|
|
if (this.selectList) {
|
|
|
@@ -91,7 +97,7 @@ export default {
|
|
|
);
|
|
|
|
|
|
for (const item of newSelectList) {
|
|
|
- price += this.getLimitBuyPriceInfo(item).total;
|
|
|
+ price += this.getSelectItemTotalPrice(item);
|
|
|
}
|
|
|
}
|
|
|
return Math.round(price * 100) / 100;
|
|
|
@@ -259,6 +265,52 @@ export default {
|
|
|
const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
return !!(limitItem && this.isTrueValue(limitItem.isLimit) && this.isTrueValue(limitItem.specialPrice));
|
|
|
},
|
|
|
+ isReachDiscountReached(item) {
|
|
|
+ const reachNum = Number(item.reachNum) || 0;
|
|
|
+ if (reachNum <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+ return Number(itemInfo.bigCount) >= reachNum;
|
|
|
+ },
|
|
|
+ getReachDiscountAmount(item) {
|
|
|
+ if (!this.isReachDiscountReached(item)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+ const bigCount = Number(itemInfo.bigCount) || 0;
|
|
|
+ const originalBig = this.toSafeNumber(item.bigPrice || item.price);
|
|
|
+ const reachPrice = this.toSafeNumber(item.reachPrice);
|
|
|
+ return Math.round(Math.max(0, bigCount * (originalBig - reachPrice)) * 100) / 100;
|
|
|
+ },
|
|
|
+ getCartItemUnitPrice(item) {
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+ if (Number(itemInfo.bigCount) > 0 && this.isReachDiscountReached(item)) {
|
|
|
+ return parseFloat(this.toSafeNumber(item.reachPrice));
|
|
|
+ }
|
|
|
+ return parseFloat(this.toSafeNumber(item.bigPrice || item.price));
|
|
|
+ },
|
|
|
+ getSelectItemTotalPrice(item) {
|
|
|
+ return this.getLimitBuyPriceInfo(item).total;
|
|
|
+ },
|
|
|
+ _applyReachDiscountToPriceInfo(item, itemInfo, result) {
|
|
|
+ if (!this.isReachDiscountReached(item)) {
|
|
|
+ result.reachDiscountActive = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const bigCount = Number(itemInfo.bigCount) || 0;
|
|
|
+ const smallCount = Number(itemInfo.smallCount) || 0;
|
|
|
+ if (!result.isLimitSpecial) {
|
|
|
+ const reachPrice = this.toSafeNumber(item.reachPrice);
|
|
|
+ const smallPrice = this.toSafeNumber(item.smallPrice);
|
|
|
+ result.total = bigCount * reachPrice + smallCount * smallPrice;
|
|
|
+ } else {
|
|
|
+ const reachNumDiscount = Number(item.reachNumDiscount) || 0;
|
|
|
+ result.total = Math.max(0.01, result.total - reachNumDiscount * bigCount);
|
|
|
+ }
|
|
|
+ result.total = Math.round(result.total * 100) / 100;
|
|
|
+ result.reachDiscountActive = true;
|
|
|
+ },
|
|
|
getLimitBuyPriceInfo(item) {
|
|
|
const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
|
|
|
@@ -278,6 +330,7 @@ export default {
|
|
|
result.total = itemInfo.bigCount * specialPrice + itemInfo.smallCount * originalPrice;
|
|
|
const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
if (!limitItem || !this.isLimitSpecialItem(item)) {
|
|
|
+ this._applyReachDiscountToPriceInfo(item, itemInfo, result);
|
|
|
return result;
|
|
|
}
|
|
|
const exceedNum = this.toSafeNumber(limitItem.exceedNum) + this.toSafeNumber(limitItem.currentBuyNum);
|
|
|
@@ -295,6 +348,7 @@ export default {
|
|
|
result.total = (result.currentBuyNum - result.exceedNum) * specialPrice + result.exceedNum * originalPrice;
|
|
|
}
|
|
|
|
|
|
+ this._applyReachDiscountToPriceInfo(item, itemInfo, result);
|
|
|
return result;
|
|
|
},
|
|
|
/**
|
|
|
@@ -304,8 +358,18 @@ export default {
|
|
|
getLimitBuyPriceDisplayParts(item) {
|
|
|
const priceInfo = this.getLimitBuyPriceInfo(item);
|
|
|
const fmt = (n) => parseFloat(Number(n) || 0);
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+ if (priceInfo.reachDiscountActive && !priceInfo.isLimitSpecial && Number(itemInfo.bigCount) > 0) {
|
|
|
+ const reachPrice = fmt(item.reachPrice);
|
|
|
+ const originalBig = fmt(item.bigPrice || item.price);
|
|
|
+ return {
|
|
|
+ showStrike: reachPrice < originalBig,
|
|
|
+ main: `¥${reachPrice}`,
|
|
|
+ strike: reachPrice < originalBig ? `¥${originalBig}` : ""
|
|
|
+ };
|
|
|
+ }
|
|
|
if (!priceInfo.isLimitSpecial) {
|
|
|
- const big = Number(item.bigCount) > 0;
|
|
|
+ const big = Number(itemInfo.bigCount) > 0;
|
|
|
const p = big
|
|
|
? this.toSafeNumber(item.bigPrice)
|
|
|
: this.toSafeNumber(item.smallPrice);
|
|
|
@@ -548,13 +612,7 @@ export default {
|
|
|
},
|
|
|
//获取当前选中商品总价
|
|
|
getSelectItemPrice(item) {
|
|
|
- let price = 0;
|
|
|
- const { bigCount, smallCount, bigPrice, smallPrice } = item;
|
|
|
- let sum =
|
|
|
- Number(bigCount) * Number(bigPrice) +
|
|
|
- Number(smallCount) * Number(smallPrice);
|
|
|
- price = Math.round(sum * 100) / 100;
|
|
|
- return price;
|
|
|
+ return this.getSelectItemTotalPrice(item);
|
|
|
},
|
|
|
//商品-请求商品数据
|
|
|
async initGoodsData(extendInfo) {
|