Fix(商品):[#1015]商品规格中含有小数点的字符,无法选中购买

This commit is contained in:
lifizer
2024-03-29 22:33:01 +08:00
parent 209295c581
commit 6eedbfd240
2 changed files with 23 additions and 26 deletions
+22 -25
View File
@@ -66,18 +66,16 @@ export default {
type: Object, type: Object,
default: () => {} default: () => {}
}, },
productValue: { // 使用字符串再转成对象的原因是,当key='2.5g'时,会变成key='2',导致数据丢失
type: Object, productValueStr: {
default: () => {} type: String,
default: '{}'
}, },
cartNum: { cartNum: {
type: Number, type: Number,
default: () => 1 default: () => 1
} }
}, },
data: function() {
return {};
},
methods: { methods: {
previewImg:function(imgUrl){ previewImg:function(imgUrl){
uni.previewImage({ uni.previewImage({
@@ -85,50 +83,49 @@ export default {
}) })
}, },
closeAttr: function() { closeAttr: function() {
this.$emit("changeFun", { action: "changeattr", value: false }); this.$emit("changeFun", { action: "changeattr", value: false })
}, },
CartNumDes: function() { CartNumDes: function() {
this.$emit("changeFun", { action: "ChangeCartNum", value: false }); this.$emit("changeFun", { action: "ChangeCartNum", value: false })
}, },
CartNumAdd: function() { CartNumAdd: function() {
this.$emit("changeFun", { action: "ChangeCartNum", value: 1 }); this.$emit("changeFun", { action: "ChangeCartNum", value: 1 })
}, },
tapAttr: function(indexw, indexn, itemn) { tapAttr: function(indexw, indexn, itemn) {
if (this.productValue[itemn.attr].stock === 0) { const productValue = JSON.parse(this.productValueStr || '{}')
return if (productValue[itemn.attr]) {
if (productValue[itemn.attr].stock === 0) {
return
}
} }
// 修改商品规格不生效的原因: // 修改商品规格不生效的原因:
// H5端下面写法,attr更新,但是除H5外其他端不支持, // H5端下面写法,attr更新,但是除H5外其他端不支持,
// 尽量避免下面的骚写法,不要在子组件内更新props // 尽量避免下面的骚写法,不要在子组件内更新props
// 这里修改是为了能获取到被选中的属性 // 这里修改是为了能获取到被选中的属性
this.attr.productAttr[indexw].index = indexn; this.attr.productAttr[indexw].index = indexn
let that = this; const value = this.getCheckedValue().sort().join(",")
let value = that this.$emit("changeFun", {
.getCheckedValue()
.sort()
.join(",");
that.$emit("changeFun", {
action: "ChangeAttr", action: "ChangeAttr",
value: { value: {
value, value,
indexw, indexw,
indexn indexn
} }
}); })
}, },
//获取被选中属性; // 获取被选中属性
getCheckedValue: function() { getCheckedValue: function() {
let productAttr = this.attr.productAttr; const productAttr = this.attr.productAttr
let value = []; const value = []
for (let i = 0; i < productAttr.length; i++) { for (let i = 0; i < productAttr.length; i++) {
for (let j = 0; j < productAttr[i].attrValueArr.length; j++) { for (let j = 0; j < productAttr[i].attrValueArr.length; j++) {
if (productAttr[i].index === j) { if (productAttr[i].index === j) {
value.push(productAttr[i].attrValueArr[j]); value.push(productAttr[i].attrValueArr[j])
} }
} }
} }
return value; return value
} }
} }
}; }
</script> </script>
+1 -1
View File
@@ -475,7 +475,7 @@
<ProductWindow <ProductWindow
v-on:changeFun="changeFun" v-on:changeFun="changeFun"
:attr="attr" :attr="attr"
:product-value="productValue" :product-value-str="JSON.stringify(productValue)"
:cartNum="cart_num" :cartNum="cart_num"
/> />
<StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus" <StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus"