shish vor 5 Tagen
Ursprung
Commit
006138b01d

+ 97 - 29
hdApp/src/mixins/cgProduct.js

@@ -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);
 					}
 				}

+ 77 - 26
hdApp/src/mixins/cgProduct2.js

@@ -52,9 +52,10 @@ export default {
 	onUnload() {},
 	computed: {
 		...mapGetters(["getSelectInfo"]),
-		//当前页面选中的商品列表
+		// 当前页面选中的商品列表(区分供货商 ghsId,避免不同供货商商品在 Vuex 中串线)
 		selectList() {
-			return this.getSelectInfo[this.pageType] || [];
+			const key = this.getGlobalUniqueKey();
+			return this.getSelectInfo[key] || [];
 		},
 		scrollClassId() {
 			const curClass = this.productInfo[this.classIndex];
@@ -184,8 +185,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) })
@@ -193,7 +201,57 @@ export default {
 		}
 	},
 	methods: {
-		...mapActions(["setSelectInfoByType", "resetSelectInfoByType"]),
+		...mapActions({
+			_setSelectInfoByType: "setSelectInfoByType",
+			_resetSelectInfoByType: "resetSelectInfoByType"
+		}),
+		/**
+		 * 获取当前供货商 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页面取的是opt.id
+			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);
+		},
 		// ----------- 购物车价格同步(ghsProduct2 / bookProduct2 与 cgProduct 对齐)-----------
 		/** 安全转数字,NaN 时返回 0,供价格同步逻辑使用 */
 		toSafeNumber(value) {
@@ -295,17 +353,9 @@ export default {
 		},
 		// 记忆已选的花材到 localStorage
 		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)
 				}
@@ -313,18 +363,19 @@ 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);
 		},
-		//大小单位切换
+		// 大小单位切换
 		switchGlobalUnitType(){
 			if(this.globalUnitType == 0){
 				this.globalUnitType = 1
@@ -343,7 +394,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)){
 						// 进入采购页:合并记忆购物车并用最新目录刷新价格
@@ -352,7 +403,7 @@ export default {
 						this.setSelectInfoByType({ type: this.pageType, info: syncedInfo });
 						this.rememberProduct();
 					}else{
-						//临时解决方案
+						// 对应供货商缓存为空时重置 Vuex 中该供货商的购物车
 						this.resetSelectInfoByType(this.pageType);
 					}
 				}
@@ -366,13 +417,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)){
 						// V1 花材列表恢复记忆时同样同步价格
@@ -381,7 +432,7 @@ export default {
 						this.setSelectInfoByType({ type: this.pageType, info: syncedInfo });
 						this.rememberProduct();
 					}else{
-						//临时解决方案
+						// 对应供货商缓存为空时重置 Vuex 中该供货商的购物车
 						this.resetSelectInfoByType(this.pageType);
 					}
 				}

+ 1 - 1
hdApp/src/pagesPurchase/bookProduct.vue

@@ -441,7 +441,7 @@ export default {
 			}
 
 			// 立即同步恢复或重置当前供货商的购物车,防止上一个供货商的购物车数据残留导致串线
-			let initialGhsId = this.option && this.option.id ? Number(this.option.id) : 0;
+			let initialGhsId = this.getGhsId();
 			if (initialGhsId > 0) {
 				let currentInfo = uni.getStorageSync('selectList' + this.pageType + '_ghs_' + initialGhsId);
 				if (!this.$util.isEmpty(currentInfo)) {

+ 3 - 3
hdApp/src/pagesPurchase/ghsProduct.vue

@@ -601,7 +601,7 @@ export default {
 			}
 
 			// 立即同步恢复或重置当前供货商的购物车,防止上一个供货商的购物车数据残留导致串线
-			let initialGhsId = this.option && this.option.id ? Number(this.option.id) : 0;
+			let initialGhsId = this.getGhsId();
 			if (initialGhsId > 0) {
 				let currentInfo = uni.getStorageSync('selectList' + this.pageType + '_ghs_' + initialGhsId);
 				if (!this.$util.isEmpty(currentInfo)) {
@@ -797,10 +797,10 @@ export default {
 		},
 		goNext(){
 			let id = this.options.id||0
-			if(this.ghsInfo.pfLevel == 1){
+			if(this.ghsInfo && this.ghsInfo.pfLevel == 1){
 				this.pageTo({url: '/admin/billing/affirmDn?id='+id,type: 2})
 			}else{
-				if(this.ghsInfo.useNewShMethod == 1){
+				if(this.ghsInfo && this.ghsInfo.useNewShMethod == 1){
 					this.pageTo({url: '/admin/billing/affirmSh?id='+id,type: 2})
 				}else{
 					this.pageTo({url: '/admin/billing/affirmGhs?id='+id,type: 2})