|
|
@@ -58,6 +58,10 @@ export default {
|
|
|
selectList() {
|
|
|
return this.getSelectInfo[this.pageType] || [];
|
|
|
},
|
|
|
+ //当前页面限购信息列表
|
|
|
+ limitBuyList() {
|
|
|
+ return this.getLimitBuyInfo[this.pageType] || [];
|
|
|
+ },
|
|
|
scrollClassId() {
|
|
|
const curClass = this.productInfo[this.classIndex];
|
|
|
if (curClass) {
|
|
|
@@ -88,17 +92,16 @@ export default {
|
|
|
},
|
|
|
allPriceFun() {
|
|
|
let price = 0;
|
|
|
+ if (this.selectList) {
|
|
|
+ // 唯一性处理,通过 id 去除重复商品 ---- 防止统计金额时因同一商品多次出现而重复计算
|
|
|
+ const newSelectList = this.selectList.filter(
|
|
|
+ (item, index, self) => index === self.findIndex(t => t.id === item.id)
|
|
|
+ );
|
|
|
|
|
|
- if (this.list) {
|
|
|
- for (const item of this.list) {
|
|
|
- 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);
|
|
|
- }
|
|
|
+ for (const item of newSelectList) {
|
|
|
+ price += this.getLimitBuyPriceInfo(item).total;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return Math.round(price * 100) / 100;
|
|
|
},
|
|
|
//选择商品总数和总重要
|
|
|
@@ -130,13 +133,27 @@ export default {
|
|
|
allCountFun() {
|
|
|
let bigLength = 0;
|
|
|
let smallLength = 0;
|
|
|
- if (this.list) {
|
|
|
- for (const item of this.list) {
|
|
|
- bigLength += item.bigCount
|
|
|
- smallLength += item.smallCount
|
|
|
+ let weight = 0;
|
|
|
+ if (this.selectList) {
|
|
|
+ for (const item of this.selectList) {
|
|
|
+ bigLength += item.bigCount;
|
|
|
+ smallLength += item.smallCount;
|
|
|
+ if (item.weight) {
|
|
|
+ if (Number(item.bigCount) > 0) {
|
|
|
+ let bigAdd = Number(item.weight) * Number(item.bigCount);
|
|
|
+ weight = Number(weight) + Number(bigAdd);
|
|
|
+ } else {
|
|
|
+ let ratio = item.ratio || 20;
|
|
|
+ let unitWeight = item.weight / ratio;
|
|
|
+ let smallAdd = Number(unitWeight) * Number(item.smallCount);
|
|
|
+ weight = Number(weight) + Number(smallAdd);
|
|
|
+ }
|
|
|
+ weight = weight.toFixed(2);
|
|
|
+ weight = parseFloat(weight);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return {bigLength:bigLength,smallLength:smallLength,};
|
|
|
+ return { bigLength, smallLength, weight };
|
|
|
},
|
|
|
//描点-定位分类
|
|
|
suitScrollClassId() {
|
|
|
@@ -214,6 +231,156 @@ export default {
|
|
|
"setLimitBuyInfoByType",
|
|
|
"resetLimitBuyInfoByType"
|
|
|
]),
|
|
|
+ isTrueValue(value) {
|
|
|
+ return value === true || value === 1 || value === "1";
|
|
|
+ },
|
|
|
+ toSafeNumber(value) {
|
|
|
+ const num = Number(value);
|
|
|
+ return isNaN(num) ? 0 : num;
|
|
|
+ },
|
|
|
+ /** 供货商--采购 / 预订:列表里同一花材可能在不同分类下 classId 不同,购物车应按 id 合并为一行 */
|
|
|
+ _shouldMergeSelectByProductId() {
|
|
|
+ return this.pageType === "cg" || this.pageType === "bookCg";
|
|
|
+ },
|
|
|
+ _mergeDuplicateSelectRows(list) {
|
|
|
+ if (!Array.isArray(list) || list.length === 0) {
|
|
|
+ return Array.isArray(list) ? [...list] : [];
|
|
|
+ }
|
|
|
+ const map = new Map();
|
|
|
+ const order = [];
|
|
|
+ list.forEach(ele => {
|
|
|
+ const key = String(ele.id);
|
|
|
+ if (!map.has(key)) {
|
|
|
+ const copy = { ...ele };
|
|
|
+ copy.bigCount = Number(copy.bigCount) || 0;
|
|
|
+ copy.smallCount = Number(copy.smallCount) || 0;
|
|
|
+ map.set(key, copy);
|
|
|
+ order.push(key);
|
|
|
+ } else {
|
|
|
+ const prev = map.get(key);
|
|
|
+ prev.bigCount = Number(prev.bigCount) + (Number(ele.bigCount) || 0);
|
|
|
+ prev.smallCount = Number(prev.smallCount) + (Number(ele.smallCount) || 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return order.map(k => map.get(k));
|
|
|
+ },
|
|
|
+ _syncMergedSelectListIfNeeded() {
|
|
|
+ if (!this._shouldMergeSelectByProductId()) return;
|
|
|
+ const list = this.selectList;
|
|
|
+ if (!list || !list.length) return;
|
|
|
+ const merged = this._mergeDuplicateSelectRows(list);
|
|
|
+ if (merged.length !== list.length) {
|
|
|
+ this.setSelectInfoByType({ type: this.pageType, info: merged });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ _selectRowMatches(element, item) {
|
|
|
+ if (!element || !item) return false;
|
|
|
+ if (this._shouldMergeSelectByProductId()) {
|
|
|
+ return String(element.id) === String(item.id);
|
|
|
+ }
|
|
|
+ return element.id == item.id && element.classId == item.classId;
|
|
|
+ },
|
|
|
+ getLimitBuyItemById(id) {
|
|
|
+ if (!Array.isArray(this.limitBuyList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return this.limitBuyList.find(item => String(item.id) === String(id)) || null;
|
|
|
+ },
|
|
|
+ isLimitSpecialItem(item) {
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
+ return !!(limitItem && this.isTrueValue(limitItem.isLimit) && this.isTrueValue(limitItem.specialPrice));
|
|
|
+ },
|
|
|
+ getLimitBuyPriceInfo(item) {
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
+
|
|
|
+ const specialPrice = this.toSafeNumber(item.price);
|
|
|
+ const originalPrice = this.toSafeNumber(item.prePrice);
|
|
|
+ const result = {
|
|
|
+ total: 0,
|
|
|
+ specialPrice: specialPrice,
|
|
|
+ originalPrice: originalPrice,
|
|
|
+ exceedNum: 0,
|
|
|
+ limitBuy: 0,
|
|
|
+ hasBuyNum: 0,
|
|
|
+ currentBuyNum: 0,
|
|
|
+ isLimitSpecial: false
|
|
|
+ };
|
|
|
+
|
|
|
+ result.total = itemInfo.bigCount * specialPrice + itemInfo.smallCount * originalPrice;
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id);
|
|
|
+ if (!limitItem || !this.isLimitSpecialItem(item)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ const exceedNum = this.toSafeNumber(limitItem.exceedNum) + this.toSafeNumber(limitItem.currentBuyNum);
|
|
|
+ result.exceedNum = exceedNum;
|
|
|
+ result.limitBuy = this.toSafeNumber(limitItem.limitBuy);
|
|
|
+ result.hasBuyNum = this.toSafeNumber(limitItem.hasBuyNum);
|
|
|
+ result.currentBuyNum = this.toSafeNumber(limitItem.currentBuyNum);
|
|
|
+ result.isLimitSpecial = true;
|
|
|
+
|
|
|
+ if (result.exceedNum <= 0) {
|
|
|
+ result.total = result.currentBuyNum * specialPrice;
|
|
|
+ } else if (result.exceedNum > 0 && result.hasBuyNum > result.limitBuy) {
|
|
|
+ result.total = result.currentBuyNum * originalPrice;
|
|
|
+ } else {
|
|
|
+ result.total =
|
|
|
+ (result.currentBuyNum - result.exceedNum) * specialPrice + result.exceedNum * originalPrice;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ getLimitBuyPriceDisplayParts(item) {
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item);
|
|
|
+ const fmt = n => parseFloat(Number(n) || 0);
|
|
|
+ if (!priceInfo.isLimitSpecial) {
|
|
|
+ const big = Number(item.bigCount) > 0;
|
|
|
+ const p = big ? this.toSafeNumber(item.bigPrice) : this.toSafeNumber(item.smallPrice);
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(p)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum <= 0) {
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(priceInfo.specialPrice)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum > 0 && priceInfo.hasBuyNum > priceInfo.limitBuy) {
|
|
|
+ return {
|
|
|
+ showStrike: false,
|
|
|
+ main: `¥${fmt(priceInfo.originalPrice)}`,
|
|
|
+ strike: ""
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ showStrike: true,
|
|
|
+ main: `¥${fmt(priceInfo.specialPrice)}`,
|
|
|
+ strike: `¥${fmt(priceInfo.originalPrice)}`
|
|
|
+ };
|
|
|
+ },
|
|
|
+ getLimitBuyPriceText(item) {
|
|
|
+ const parts = this.getLimitBuyPriceDisplayParts(item);
|
|
|
+ if (parts.showStrike) {
|
|
|
+ return `${parts.main} ${parts.strike}`;
|
|
|
+ }
|
|
|
+ return parts.main;
|
|
|
+ },
|
|
|
+ getLimitBuyPriceTip(item) {
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item);
|
|
|
+ if (!priceInfo.isLimitSpecial) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum <= 0) {
|
|
|
+ return `限购 ${priceInfo.limitBuy},未超限购,按特价计算`;
|
|
|
+ }
|
|
|
+ if (priceInfo.exceedNum > 0 && priceInfo.hasBuyNum > priceInfo.limitBuy) {
|
|
|
+ return `限购 ${priceInfo.limitBuy},已超出,按原价计算`;
|
|
|
+ }
|
|
|
+ return `限购 ${priceInfo.limitBuy},${priceInfo.currentBuyNum - priceInfo.exceedNum} 扎按特价,超出 ${priceInfo.exceedNum} 扎按原价`;
|
|
|
+ },
|
|
|
//记忆已选的花材
|
|
|
rememberProduct(){
|
|
|
//采购或预订的记忆花材
|
|
|
@@ -403,21 +570,27 @@ export default {
|
|
|
autoPrice: 0, //调价价格
|
|
|
itemPrice: 0 //调价价格
|
|
|
};
|
|
|
- const item =
|
|
|
- this.selectList &&
|
|
|
- this.selectList.find(ele => {
|
|
|
- return ele.id == id && ele.classId == classId;
|
|
|
- });
|
|
|
- if (item) {
|
|
|
- info = {
|
|
|
- ...item,
|
|
|
- bigCount: Number(item.bigCount),
|
|
|
- smallCount: Number(item.smallCount),
|
|
|
- autoPrice: Number(item.autoPrice),
|
|
|
- itemPrice: Number(item.itemPrice),
|
|
|
- };
|
|
|
+ if (!this.selectList || !this.selectList.length) {
|
|
|
+ return info;
|
|
|
}
|
|
|
- return info;
|
|
|
+ const matches = this.selectList.filter(ele => this._selectRowMatches(ele, { id, classId }));
|
|
|
+ if (!matches.length) {
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+ const base = { ...matches[0] };
|
|
|
+ let bigCount = 0;
|
|
|
+ let smallCount = 0;
|
|
|
+ matches.forEach(m => {
|
|
|
+ bigCount += Number(m.bigCount) || 0;
|
|
|
+ smallCount += Number(m.smallCount) || 0;
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ ...base,
|
|
|
+ bigCount,
|
|
|
+ smallCount,
|
|
|
+ autoPrice: Number(base.autoPrice),
|
|
|
+ itemPrice: Number(base.itemPrice)
|
|
|
+ };
|
|
|
},
|
|
|
//通过id获取当前选中的商品类别信息 左边菜单角标 当前选中该类别商品多少件
|
|
|
getSelectClassById(classId) {
|