|
|
@@ -52,13 +52,15 @@ export default {
|
|
|
onUnload() {},
|
|
|
computed: {
|
|
|
...mapGetters(["getSelectInfo", "getLimitBuyInfo"]),
|
|
|
- //当前页面选中的商品列表
|
|
|
+ // 当前页面选中的商品列表(区分供货商 ghsId,避免不同供货商商品在 Vuex 中串线)
|
|
|
selectList() {
|
|
|
- return this.getSelectInfo[this.pageType] || [];
|
|
|
+ const key = this.getGlobalUniqueKey();
|
|
|
+ return this.getSelectInfo[key] || [];
|
|
|
},
|
|
|
- //当前页面限购信息列表
|
|
|
+ // 当前页面限购信息列表(区分供货商 ghsId)
|
|
|
limitBuyList() {
|
|
|
- return this.getLimitBuyInfo[this.pageType] || [];
|
|
|
+ const key = this.getGlobalUniqueKey();
|
|
|
+ return this.getLimitBuyInfo[key] || [];
|
|
|
},
|
|
|
scrollClassId() {
|
|
|
const curClass = this.productInfo[this.classIndex];
|
|
|
@@ -192,8 +194,15 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
onShow(){
|
|
|
- if(this.pageType == 'cg' && !this.$util.isEmpty(this.option.id)){
|
|
|
- //在initGhsData()获取记忆的花材,保证价格有变时取到最新价格
|
|
|
+ if(this.pageType == 'cg' || this.pageType == 'bookCg'){
|
|
|
+ let ghsId = this.getGhsId();
|
|
|
+ if(ghsId > 0 && this.$util.isEmpty(this.selectList)){
|
|
|
+ let currentInfo = uni.getStorageSync('selectList' + this.pageType + '_ghs_' + ghsId);
|
|
|
+ if(!this.$util.isEmpty(currentInfo)){
|
|
|
+ const mergedInfo = this._mergeDuplicateSelectRows ? this._mergeDuplicateSelectRows(currentInfo) : currentInfo;
|
|
|
+ this.setSelectInfoByType({ type: this.pageType, info: mergedInfo });
|
|
|
+ }
|
|
|
+ }
|
|
|
}else{
|
|
|
if(uni.getStorageSync('selectList'+this.pageType)){
|
|
|
this.setSelectInfoByType({ type: this.pageType, info: uni.getStorageSync('selectList'+this.pageType) })
|
|
|
@@ -201,7 +210,73 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapActions(["setSelectInfoByType", "resetSelectInfoByType", "setLimitBuyInfoByType", "resetLimitBuyInfoByType"]),
|
|
|
+ ...mapActions({
|
|
|
+ _setSelectInfoByType: "setSelectInfoByType",
|
|
|
+ _resetSelectInfoByType: "resetSelectInfoByType",
|
|
|
+ _setLimitBuyInfoByType: "setLimitBuyInfoByType",
|
|
|
+ _resetLimitBuyInfoByType: "resetLimitBuyInfoByType"
|
|
|
+ }),
|
|
|
+ /**
|
|
|
+ * 获取当前供货商 ID
|
|
|
+ * @returns {number} 供货商 ID
|
|
|
+ */
|
|
|
+ getGhsId() {
|
|
|
+ if (this.ghsId && Number(this.ghsId) > 0) {
|
|
|
+ return Number(this.ghsId);
|
|
|
+ }
|
|
|
+ const opt = this.option || this.options || {};
|
|
|
+ if (opt.ghsId && Number(opt.ghsId) > 0) {
|
|
|
+ return Number(opt.ghsId);
|
|
|
+ }
|
|
|
+ //这条有用,不能删除。ghsProduct.vue里使用到
|
|
|
+ if (opt.id && Number(opt.id) > 0) {
|
|
|
+ return Number(opt.id);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 获取带 ghsId 区分的页面类型 Key,防止不同供货商购物车数据在 Vuex 中混淆
|
|
|
+ * @param {string} [type] 页面类型
|
|
|
+ * @returns {string} 包含 ghsId 的唯一 Key
|
|
|
+ */
|
|
|
+ getGlobalUniqueKey(type) {
|
|
|
+ const curType = type || this.pageType;
|
|
|
+ if (curType === 'cg' || curType === 'bookCg') {
|
|
|
+ const ghsId = this.getGhsId();
|
|
|
+ if (ghsId > 0) {
|
|
|
+ return `${curType}_ghs_${ghsId}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return curType;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 设置指定页面类型的选中商品列表(按 ghsId 隔离)
|
|
|
+ */
|
|
|
+ setSelectInfoByType({ type, info }) {
|
|
|
+ const key = this.getGlobalUniqueKey(type);
|
|
|
+ return this._setSelectInfoByType({ type: key, info });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 重置指定页面类型的选中商品列表(按 ghsId 隔离)
|
|
|
+ */
|
|
|
+ resetSelectInfoByType(type) {
|
|
|
+ const key = this.getGlobalUniqueKey(type);
|
|
|
+ return this._resetSelectInfoByType(key);
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 设置指定页面类型的限购列表(按 ghsId 隔离)
|
|
|
+ */
|
|
|
+ setLimitBuyInfoByType({ type, info }) {
|
|
|
+ const key = this.getGlobalUniqueKey(type);
|
|
|
+ return this._setLimitBuyInfoByType({ type: key, info });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 重置指定页面类型的限购列表(按 ghsId 隔离)
|
|
|
+ */
|
|
|
+ resetLimitBuyInfoByType(type) {
|
|
|
+ const key = this.getGlobalUniqueKey(type);
|
|
|
+ return this._resetLimitBuyInfoByType(key);
|
|
|
+ },
|
|
|
isTrueValue(value) {
|
|
|
return value === true || value === 1 || value === "1";
|
|
|
},
|
|
|
@@ -525,19 +600,11 @@ export default {
|
|
|
}
|
|
|
return `限购 ${priceInfo.limitBuy},${priceInfo.currentBuyNum - priceInfo.exceedNum} 扎按特价,超出 ${priceInfo.exceedNum} 扎按原价`;
|
|
|
},
|
|
|
- //记忆已选的花材
|
|
|
+ // 记忆已选的花材
|
|
|
rememberProduct(){
|
|
|
- //采购或预订的记忆花材
|
|
|
+ // 采购或预订的记忆花材
|
|
|
if(this.pageType == 'cg' || this.pageType == 'bookCg' ){
|
|
|
- let ghsId = 0
|
|
|
- if(this.option.ghsId && Number(this.option.ghsId)>0){
|
|
|
- ghsId = Number(this.option.ghsId)
|
|
|
- }
|
|
|
- if(ghsId == 0){
|
|
|
- if(this.option.id && Number(this.option.id)>0){
|
|
|
- ghsId = Number(this.option.id)
|
|
|
- }
|
|
|
- }
|
|
|
+ let ghsId = this.getGhsId();
|
|
|
if(Number(ghsId)>0){
|
|
|
uni.setStorageSync('selectList'+this.pageType+'_ghs_'+ghsId, this.selectList)
|
|
|
}
|
|
|
@@ -545,19 +612,20 @@ export default {
|
|
|
uni.setStorageSync('selectList'+this.pageType, this.selectList)
|
|
|
}
|
|
|
},
|
|
|
- //清除已记忆花材
|
|
|
+ // 清除已记忆花材
|
|
|
removeMemory(ghsId){
|
|
|
- if(ghsId){
|
|
|
- uni.removeStorageSync('selectList'+this.pageType+'_ghs_'+ghsId);
|
|
|
- //删除多颜色花材记忆
|
|
|
- uni.removeStorageSync("ghsColorItem"+ghsId)
|
|
|
+ let targetId = ghsId || this.getGhsId();
|
|
|
+ if(targetId){
|
|
|
+ uni.removeStorageSync('selectList'+this.pageType+'_ghs_'+targetId);
|
|
|
+ // 删除多颜色花材记忆
|
|
|
+ uni.removeStorageSync("ghsColorItem"+targetId)
|
|
|
}else{
|
|
|
uni.removeStorageSync('selectList'+this.pageType);
|
|
|
}
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
this.resetLimitBuyInfoByType(this.pageType);
|
|
|
},
|
|
|
- //大小单位切换
|
|
|
+ // 大小单位切换
|
|
|
switchGlobalUnitType(){
|
|
|
if(this.globalUnitType == 0){
|
|
|
this.globalUnitType = 1
|
|
|
@@ -576,7 +644,7 @@ export default {
|
|
|
this.productInfo = data.classItem||[];
|
|
|
this.globalItemList = data.itemList || []
|
|
|
if(this.pageType == 'cg' || this.pageType == 'bookCg'){
|
|
|
- let targetId = this.option.id ? this.option.id : 0
|
|
|
+ let targetId = id || this.getGhsId();
|
|
|
let currentInfo = uni.getStorageSync('selectList'+this.pageType+'_ghs_'+targetId)
|
|
|
if(!this.$util.isEmpty(currentInfo)){
|
|
|
// 恢复记忆购物车:合并重复行 → 用最新目录补价格 → 写回 storage 修复旧缓存
|
|
|
@@ -585,7 +653,7 @@ export default {
|
|
|
this.setSelectInfoByType({ type: this.pageType, info: syncedInfo });
|
|
|
this.rememberProduct();
|
|
|
}else{
|
|
|
- //临时解决方案
|
|
|
+ // 对应供货商缓存为空时重置 Vuex 中该供货商的购物车
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
}
|
|
|
}
|
|
|
@@ -599,13 +667,13 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
async initGhsData(id,shopId,showAll) {
|
|
|
- //extendInfo调用时的扩展参数,如shopId
|
|
|
+ // extendInfo调用时的扩展参数,如shopId
|
|
|
try {
|
|
|
let params = { py: this.py, id:id, shopId:shopId, showAll:showAll }
|
|
|
const { data } = await getGhsProductList(params);
|
|
|
this.productInfo = data;
|
|
|
if(this.pageType == 'cg' || this.pageType == 'bookCg'){
|
|
|
- let targetId = this.option.id ? this.option.id : 0
|
|
|
+ let targetId = id || this.getGhsId();
|
|
|
let currentInfo = uni.getStorageSync('selectList'+this.pageType+'_ghs_'+targetId)
|
|
|
if(!this.$util.isEmpty(currentInfo)){
|
|
|
// 与 initGhsDataV2 相同:恢复时同步最新价格字段
|
|
|
@@ -614,7 +682,7 @@ export default {
|
|
|
this.setSelectInfoByType({ type: this.pageType, info: syncedInfo });
|
|
|
this.rememberProduct();
|
|
|
}else{
|
|
|
- //临时解决方案
|
|
|
+ // 对应供货商缓存为空时重置 Vuex 中该供货商的购物车
|
|
|
this.resetSelectInfoByType(this.pageType);
|
|
|
}
|
|
|
}
|