Fix(购物车):规格改为包含小数点的名称后,无法操作
This commit is contained in:
+52
-22
@@ -178,12 +178,17 @@
|
|||||||
v-for="(attr, attrIndex) in item.attrValue"
|
v-for="(attr, attrIndex) in item.attrValue"
|
||||||
:key="attr"
|
:key="attr"
|
||||||
:class="{
|
:class="{
|
||||||
'on': attr.check
|
'on': attr.check,
|
||||||
|
'disabled': getAttrItemData(attr.attr).stock === 0
|
||||||
}"
|
}"
|
||||||
class="attr"
|
class="attr"
|
||||||
@click="attrItemClick(attr, attrIndex, index)"
|
@click="attrItemClick(attr, attrIndex, index)"
|
||||||
>
|
>
|
||||||
{{ attr.attr }}
|
{{ attr.attr }}
|
||||||
|
<text
|
||||||
|
v-if="getAttrItemData(attr.attr).stock === 0"
|
||||||
|
class="tag"
|
||||||
|
>缺货</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -228,7 +233,7 @@ export default {
|
|||||||
currGoodAttr: {},
|
currGoodAttr: {},
|
||||||
goodAttr: {
|
goodAttr: {
|
||||||
productAttr: [],
|
productAttr: [],
|
||||||
productValue: {}
|
productValueArr: []
|
||||||
},
|
},
|
||||||
showAttr: false
|
showAttr: false
|
||||||
}
|
}
|
||||||
@@ -385,7 +390,13 @@ export default {
|
|||||||
const { success, data } = res
|
const { success, data } = res
|
||||||
if (success) {
|
if (success) {
|
||||||
this.currGood = good
|
this.currGood = good
|
||||||
this.goodAttr = data
|
this.goodAttr.productAttr = data.productAttr
|
||||||
|
for (const key in data.productValue) {
|
||||||
|
this.goodAttr.productValueArr.push({
|
||||||
|
attrItemkey: key,
|
||||||
|
...data.productValue[key]
|
||||||
|
})
|
||||||
|
}
|
||||||
this.goodAttr.productAttr.map((item, index) => {
|
this.goodAttr.productAttr.map((item, index) => {
|
||||||
item.attrValue.map((attr, attrIndex) => {
|
item.attrValue.map((attr, attrIndex) => {
|
||||||
attr.check = data.defaultSkuIndex[index] === attrIndex
|
attr.check = data.defaultSkuIndex[index] === attrIndex
|
||||||
@@ -399,12 +410,19 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
getAttrItemData(attr) {
|
getAttrItemData(attr) {
|
||||||
let result = {}
|
let result = {
|
||||||
this.goodAttr.productAttr.map(item => {
|
stock: 0
|
||||||
if (item.attrItemkey === attr) {
|
}
|
||||||
result = item
|
// 只有一组规格
|
||||||
}
|
if (this.goodAttr.productAttr.length === 1) {
|
||||||
})
|
this.goodAttr.productValueArr.map(item => {
|
||||||
|
if (item.attrItemkey === attr) {
|
||||||
|
result = item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result.stock = 1
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
// 规格切换
|
// 规格切换
|
||||||
@@ -426,9 +444,15 @@ export default {
|
|||||||
})
|
})
|
||||||
if (arr.length > 0) {
|
if (arr.length > 0) {
|
||||||
const attrStr = arr.sort().join(',')
|
const attrStr = arr.sort().join(',')
|
||||||
if (this.goodAttr.productValue[attrStr]) {
|
let targat = null
|
||||||
const stock = this.goodAttr.productValue[attrStr].stock
|
this.goodAttr.productValueArr.map(item => {
|
||||||
this.currGoodAttr = this.goodAttr.productValue[attrStr]
|
if (item.attrItemkey === attrStr) {
|
||||||
|
targat = item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (targat) {
|
||||||
|
const stock = targat.stock
|
||||||
|
this.currGoodAttr = targat
|
||||||
this.goodAttr.productAttr[index].attrValue.map(attrItem => {
|
this.goodAttr.productAttr[index].attrValue.map(attrItem => {
|
||||||
attrItem.check = false
|
attrItem.check = false
|
||||||
})
|
})
|
||||||
@@ -440,16 +464,13 @@ export default {
|
|||||||
duration: 3000
|
duration: 3000
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// if (stock > 0) {
|
|
||||||
// this.currGoodAttr = this.goodAttr.productValue[attrStr]
|
|
||||||
// this.goodAttr.productAttr[index].attrValue.map(attrItem => {
|
|
||||||
// attrItem.check = false
|
|
||||||
// })
|
|
||||||
// this.goodAttr.productAttr[index].attrValue[attrIndex].check = true
|
|
||||||
// } else {
|
|
||||||
|
|
||||||
// }
|
|
||||||
this.$forceUpdate()
|
this.$forceUpdate()
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '库存不足',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -675,7 +696,16 @@ view {
|
|||||||
border-color: #f1f1f1;
|
border-color: #f1f1f1;
|
||||||
background-color: #f1f1f1;
|
background-color: #f1f1f1;
|
||||||
.tag {
|
.tag {
|
||||||
|
position: absolute;
|
||||||
|
top: -18upx;
|
||||||
|
right: -18upx;
|
||||||
|
height: 28upx;
|
||||||
|
padding: 0 6upx;
|
||||||
|
border-radius: 6upx;
|
||||||
|
color: #fff;
|
||||||
|
line-height: 28upx;
|
||||||
|
font-size: 10px;
|
||||||
|
background-color: #FD5749;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user