From 3358e2c5a712e904392d1829c4d3144da8676568 Mon Sep 17 00:00:00 2001 From: ch Date: Tue, 17 May 2022 16:54:08 +0800 Subject: [PATCH] =?UTF-8?q?sku=E9=80=89=E6=8B=A9=E9=97=AE=E9=A2=98,?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AE=A2=E5=8D=95=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/detail/_id.vue | 88 ++++++++++++++++++------------------ pages/order/submit/index.vue | 4 +- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/pages/goods/detail/_id.vue b/pages/goods/detail/_id.vue index 36dd5c7..b53ae9a 100644 --- a/pages/goods/detail/_id.vue +++ b/pages/goods/detail/_id.vue @@ -235,7 +235,10 @@ export default { let res2 = await ApiGetGoodsSkus({ productId: id }); let res3 = await ApiGetRecommendedGoodsList(); vm.detailData = res1.result; - vm.skuData = res2.result; + vm.skuData = res2.result.map(i => { + i.attributeSymbolList = i.attributeSymbolList.split(',') + return i; + }); vm.recommendedData = res3.result; if ( vm.detailData.productActivityVO.isActivity && @@ -266,7 +269,7 @@ export default { curSku() { return ( this.skuData.find( - (i) => i.attributeSymbolList === this.selectedSymbol.join(",") + (i) => i.attributeSymbolList.join(',') === this.selectedSymbol.join(",") ) || {} ); }, @@ -275,9 +278,9 @@ export default { return this.detailData.attributeGroupList .map((item) => { const activeAttr = item.attributes.find((i) => i.active); - return activeAttr ? activeAttr.symbol : "."; + return activeAttr?.symbol; }) - .filter((i) => i); //.sort(); + .filter((i) => i).sort(); }, /** * 最大可购买数量 @@ -378,26 +381,6 @@ export default { vm.activeImg++; } }, - /** - * 设置默认选中规格 - */ - setDefaultAttr() { - let vm = this; - const curSku = vm.skuData.find((i) => i.stock > 0); - if (!curSku) { - return false; - } - vm.detailData.attributeGroupList.forEach((item, index) => { - for (let i of item.attributes) { - if (curSku.attributeSymbolList.includes(i.symbol)) { - this.$set(i, "active", true); - this.setDisabledItem(i, index, true); - break; - } - } - }); - this.$emit("input", this.curSku); - }, /** * 点击属性项,设置选中和禁用项 */ @@ -426,26 +409,43 @@ export default { setDisabledItem(item, groupIndex) { let vm = this; vm.detailData.attributeGroupList.forEach((group, idx) => { - // 拿到已选项数组,这个是按照项组顺序排序好的缓存数组 - let symbolCache = Object.assign([], this.selectedSymbol); - // 跳过当前属性组 - if (groupIndex === idx) return false; - // 遍历其他选项组中的选项 - group.attributes.forEach((item) => { - // 根据选项组下标,补位选项属性 - symbolCache[idx] = item.symbol; - const reg = new RegExp(symbolCache.join(",")); - // 根据补位选项寻找是否有有效SKU,有则可选,没有则禁用 - const res = vm.skuData - .filter((i) => reg.test(i.attributeSymbolList)) - .find((i) => i.stock > 0); - if (res) { - item.disabled = false; - } else { - item.disabled = true; - } - }); - }); + // if(groupIndex === idx) return false; + // 拿到已选项数组 + group.attributes.forEach( item => { + let symbolCache = Object.assign([],vm.selectedSymbol); + symbolCache.push(item.symbol); + symbolCache.sort(); + const res = vm.skuData.filter(item => + symbolCache.map(i => item.attributeSymbolList.includes(i.toString())).every(i => i) + ).find(i => i.stock > 0); + if(res){ + item.disabled = false; + }else{ + item.disabled = true; + } + }); + }) + // vm.detailData.attributeGroupList.forEach((group, idx) => { + // // 拿到已选项数组,这个是按照项组顺序排序好的缓存数组 + // let symbolCache = Object.assign([], this.selectedSymbol); + // // 跳过当前属性组 + // if (groupIndex === idx) return false; + // // 遍历其他选项组中的选项 + // group.attributes.forEach((item) => { + // // 根据选项组下标,补位选项属性 + // symbolCache[idx] = item.symbol; + // const reg = new RegExp(symbolCache.join(",")); + // // 根据补位选项寻找是否有有效SKU,有则可选,没有则禁用 + // const res = vm.skuData + // .filter((i) => reg.test(i.attributeSymbolList)) + // .find((i) => i.stock > 0); + // if (res) { + // item.disabled = false; + // } else { + // item.disabled = true; + // } + // }); + // }); }, buyNow() { if (!this.$isLoginValidate()) { diff --git a/pages/order/submit/index.vue b/pages/order/submit/index.vue index 44f737a..ca5e857 100644 --- a/pages/order/submit/index.vue +++ b/pages/order/submit/index.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-05-04 17:30:58 * @LastEditors: ch - * @LastEditTime: 2022-05-16 16:01:17 + * @LastEditTime: 2022-05-17 16:44:30 * @Description: file content --> @@ -18,7 +18,7 @@

确认商品信息

- +
立即支付