From 2fde80fc1deec44630f093b276aed7e017fa1aa0 Mon Sep 17 00:00:00 2001 From: lifizer <913626195@qq.com> Date: Mon, 8 Apr 2024 20:54:36 +0800 Subject: [PATCH] =?UTF-8?q?Fix(=E8=B4=AD=E7=89=A9=E8=BD=A6):=E8=A7=84?= =?UTF-8?q?=E6=A0=BC=E6=94=B9=E4=B8=BA=E5=8C=85=E5=90=AB=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E5=90=8D=E7=A7=B0=E5=90=8E=EF=BC=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/cart.vue | 74 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/pages/cart.vue b/pages/cart.vue index 518428a..557e08c 100644 --- a/pages/cart.vue +++ b/pages/cart.vue @@ -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 }} + 缺货 @@ -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; } } }