|
|
@@ -84,7 +84,13 @@ export default {
|
|
|
allPriceFun() {
|
|
|
let price = 0;
|
|
|
if (this.selectList) {
|
|
|
- for (const item of this.selectList) {
|
|
|
+ // 唯一性处理,通过 id 去除重复商品 ---- 防止统计金额时因同一商品多次出现而重复计算
|
|
|
+ const newSelectList = this.selectList
|
|
|
+ .filter((item, index, self) =>
|
|
|
+ index === self.findIndex((t) => t.id === item.id)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (const item of newSelectList) {
|
|
|
price += this.getLimitBuyPriceInfo(item).total;
|
|
|
}
|
|
|
}
|
|
|
@@ -197,6 +203,52 @@ export default {
|
|
|
const num = Number(value);
|
|
|
return isNaN(num) ? 0 : num;
|
|
|
},
|
|
|
+
|
|
|
+ /** 供货商--采购 / 预订:列表里同一花材可能在不同分类下 classId 不同,购物车应按 id 合并为一行 */
|
|
|
+ // -----------start----------
|
|
|
+ _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;
|
|
|
+ },
|
|
|
+ // ------------end---------
|
|
|
+
|
|
|
getLimitBuyItemById(id) {
|
|
|
if (!Array.isArray(this.limitBuyList)) {
|
|
|
return null;
|
|
|
@@ -357,7 +409,8 @@ export default {
|
|
|
let targetId = this.option.id ? this.option.id : 0
|
|
|
let currentInfo = uni.getStorageSync('selectList'+this.pageType+'_ghs_'+targetId)
|
|
|
if(!this.$util.isEmpty(currentInfo)){
|
|
|
- this.setSelectInfoByType({ type: this.pageType, info: currentInfo })
|
|
|
+ const mergedInfo = this._mergeDuplicateSelectRows(currentInfo);
|
|
|
+ this.setSelectInfoByType({ type: this.pageType, info: mergedInfo })
|
|
|
}else{
|
|
|
//临时解决方案
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
@@ -382,7 +435,8 @@ export default {
|
|
|
let targetId = this.option.id ? this.option.id : 0
|
|
|
let currentInfo = uni.getStorageSync('selectList'+this.pageType+'_ghs_'+targetId)
|
|
|
if(!this.$util.isEmpty(currentInfo)){
|
|
|
- this.setSelectInfoByType({ type: this.pageType, info: currentInfo })
|
|
|
+ const mergedInfo = this._mergeDuplicateSelectRows(currentInfo);
|
|
|
+ this.setSelectInfoByType({ type: this.pageType, info: mergedInfo })
|
|
|
}else{
|
|
|
//临时解决方案
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
@@ -561,21 +615,29 @@ 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) {
|
|
|
@@ -592,7 +654,10 @@ export default {
|
|
|
if (productItem && productItem.child) {
|
|
|
for (const item of productItem.child) {
|
|
|
for (const selectItem of this.selectList) {
|
|
|
- if (item.id == selectItem.id && item.classId == selectItem.classId) {
|
|
|
+ const matched = this._shouldMergeSelectByProductId()
|
|
|
+ ? item.id == selectItem.id
|
|
|
+ : item.id == selectItem.id && item.classId == selectItem.classId;
|
|
|
+ if (matched) {
|
|
|
info.bigCount += Number(selectItem.bigCount);
|
|
|
info.smallCount += Number(selectItem.smallCount);
|
|
|
info.itemPrice += selectItem.itemPrice?Number(selectItem.itemPrice):'';
|
|
|
@@ -604,6 +669,7 @@ export default {
|
|
|
},
|
|
|
//添加商品
|
|
|
addEvent(item) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = this.selectList;
|
|
|
let has = false;
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
@@ -613,7 +679,7 @@ export default {
|
|
|
}else{
|
|
|
this.isSmallCount = false
|
|
|
}
|
|
|
- if (element.id == item.id && element.classId == item.classId) {
|
|
|
+ if (this._selectRowMatches(element, item)) {
|
|
|
has = true;
|
|
|
if(this.offVerifyRepertory){//去除库存验证
|
|
|
if(this.isSmallCount){
|
|
|
@@ -684,14 +750,27 @@ export default {
|
|
|
|
|
|
},
|
|
|
|
|
|
- addCustomNumEvent(item,params1,type) {
|
|
|
+ addCustomNumEvent(item, params1, type) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = this.selectList;
|
|
|
+ const existed = list.find(ele => this._selectRowMatches(ele, item));
|
|
|
+ if (existed) {
|
|
|
+ if (type != "noAdd") {
|
|
|
+ this.setSelectInfoByType({ type: this.pageType, info: list });
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.customNum(params1);
|
|
|
+ });
|
|
|
+ this.rememberProduct();
|
|
|
+ return;
|
|
|
+ }
|
|
|
let info = { classId: item.classId, id: item.id };
|
|
|
const classInfo =
|
|
|
this.productInfo &&
|
|
|
this.productInfo.find(element => {
|
|
|
return element.classId == item.classId && element.child;
|
|
|
});
|
|
|
+
|
|
|
if (classInfo) {
|
|
|
info = classInfo.child.find(ele => {
|
|
|
return ele.id == item.id;
|
|
|
@@ -717,6 +796,7 @@ export default {
|
|
|
},
|
|
|
//减去商品
|
|
|
delEvent(item) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = copyObject(this.selectList);
|
|
|
let has = false;
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
@@ -726,7 +806,7 @@ export default {
|
|
|
}else{
|
|
|
this.isSmallCount = false
|
|
|
}
|
|
|
- if (element.id == item.id && element.classId == item.classId) {
|
|
|
+ if (this._selectRowMatches(element, item)) {
|
|
|
has = true;
|
|
|
if (element.bigCount > 0) {
|
|
|
if (!this.isSmallCount) {
|
|
|
@@ -749,6 +829,7 @@ export default {
|
|
|
this.rememberProduct()
|
|
|
},
|
|
|
delAllEvent(item) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = this.selectList;
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
const element = list[index];
|
|
|
@@ -881,12 +962,13 @@ export default {
|
|
|
this.setSelectInfoByType({ type: this.pageType, info: list });
|
|
|
},
|
|
|
addItemEvent(item) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = this.selectList;
|
|
|
if(!this.$util.isEmpty(list)){
|
|
|
let hasItem = false
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
const element = list[index];
|
|
|
- if (element.id == item.id && element.classId == item.classId) {
|
|
|
+ if (this._selectRowMatches(element, item)) {
|
|
|
hasItem = true
|
|
|
const { bigCount, smallCount } = list[index];
|
|
|
const ratio = Number(item.ratio);
|
|
|
@@ -918,10 +1000,11 @@ export default {
|
|
|
},
|
|
|
//更新商品
|
|
|
updateItemEvent(item) {
|
|
|
+ this._syncMergedSelectListIfNeeded();
|
|
|
const list = this.selectList;
|
|
|
for (let index = 0; index < list.length; index++) {
|
|
|
const element = list[index];
|
|
|
- if (element.id == item.id && element.classId == item.classId) {
|
|
|
+ if (this._selectRowMatches(element, item)) {
|
|
|
const { bigCount, smallCount } = list[index];
|
|
|
const ratio = Number(item.ratio);
|
|
|
if (this.isLimit) {
|