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