From 6eedbfd240479575914ac9be547afb8f9018b7fd Mon Sep 17 00:00:00 2001 From: lifizer <913626195@qq.com> Date: Fri, 29 Mar 2024 22:33:01 +0800 Subject: [PATCH] =?UTF-8?q?Fix(=E5=95=86=E5=93=81):[#1015]=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=A7=84=E6=A0=BC=E4=B8=AD=E5=90=AB=E6=9C=89=E5=B0=8F?= =?UTF-8?q?=E6=95=B0=E7=82=B9=E7=9A=84=E5=AD=97=E7=AC=A6=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E9=80=89=E4=B8=AD=E8=B4=AD=E4=B9=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ProductWindow.vue | 47 ++++++++++++++++------------------- pages/shop/GoodsCon/index.vue | 2 +- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/components/ProductWindow.vue b/components/ProductWindow.vue index 4d7f731..acee08f 100644 --- a/components/ProductWindow.vue +++ b/components/ProductWindow.vue @@ -66,18 +66,16 @@ export default { type: Object, default: () => {} }, - productValue: { - type: Object, - default: () => {} + // 使用字符串再转成对象的原因是,当key='2.5g'时,会变成key='2',导致数据丢失 + productValueStr: { + type: String, + default: '{}' }, cartNum: { type: Number, default: () => 1 } }, - data: function() { - return {}; - }, methods: { previewImg:function(imgUrl){ uni.previewImage({ @@ -85,50 +83,49 @@ export default { }) }, closeAttr: function() { - this.$emit("changeFun", { action: "changeattr", value: false }); + this.$emit("changeFun", { action: "changeattr", value: false }) }, CartNumDes: function() { - this.$emit("changeFun", { action: "ChangeCartNum", value: false }); + this.$emit("changeFun", { action: "ChangeCartNum", value: false }) }, CartNumAdd: function() { - this.$emit("changeFun", { action: "ChangeCartNum", value: 1 }); + this.$emit("changeFun", { action: "ChangeCartNum", value: 1 }) }, tapAttr: function(indexw, indexn, itemn) { - if (this.productValue[itemn.attr].stock === 0) { - return + const productValue = JSON.parse(this.productValueStr || '{}') + if (productValue[itemn.attr]) { + if (productValue[itemn.attr].stock === 0) { + return + } } // 修改商品规格不生效的原因: // H5端下面写法,attr更新,但是除H5外其他端不支持, // 尽量避免下面的骚写法,不要在子组件内更新props // 这里修改是为了能获取到被选中的属性 - this.attr.productAttr[indexw].index = indexn; - let that = this; - let value = that - .getCheckedValue() - .sort() - .join(","); - that.$emit("changeFun", { + this.attr.productAttr[indexw].index = indexn + const value = this.getCheckedValue().sort().join(",") + this.$emit("changeFun", { action: "ChangeAttr", value: { value, indexw, indexn } - }); + }) }, - //获取被选中属性; + // 获取被选中属性 getCheckedValue: function() { - let productAttr = this.attr.productAttr; - let value = []; + const productAttr = this.attr.productAttr + const value = [] for (let i = 0; i < productAttr.length; i++) { for (let j = 0; j < productAttr[i].attrValueArr.length; j++) { if (productAttr[i].index === j) { - value.push(productAttr[i].attrValueArr[j]); + value.push(productAttr[i].attrValueArr[j]) } } } - return value; + return value } } -}; +} diff --git a/pages/shop/GoodsCon/index.vue b/pages/shop/GoodsCon/index.vue index 4656fe4..d68156a 100644 --- a/pages/shop/GoodsCon/index.vue +++ b/pages/shop/GoodsCon/index.vue @@ -475,7 +475,7 @@