diff --git a/pages/goods/detail/_id.vue b/pages/goods/detail/_id.vue index 467365a..b4e478a 100644 --- a/pages/goods/detail/_id.vue +++ b/pages/goods/detail/_id.vue @@ -279,10 +279,8 @@ export default { order: "", }); vm.detailData = res1.result; - vm.skuData = res2.result.map(i => { - i.attributeSymbolList = i.attributeSymbolList.split(',') - return i; - }); + vm.skuData = res2.result; + vm.recommendedData = res3.result.records; vm.pageLoading = false; if ( @@ -314,7 +312,7 @@ export default { curSku() { return ( this.skuData.find( - (i) => i.attributeSymbolList.join(',') === this.selectedSymbol.join(",") + (i) => i.attributeSymbolList === this.selectedSymbol.join(",") ) || {} ); }, @@ -323,9 +321,9 @@ export default { return this.detailData.attributeGroupList .map((item) => { const activeAttr = item.attributes.find((i) => i.active); - return activeAttr?.symbol; + return activeAttr ? activeAttr.symbol : "."; }) - .filter((i) => i).sort(); + .filter((i) => i)//.sort(); }, /** * 最大可购买数量 @@ -456,43 +454,26 @@ export default { setDisabledItem(item, groupIndex) { let vm = this; vm.detailData.attributeGroupList.forEach((group, idx) => { - // 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; - // } - // }); - // }); + // 拿到已选项数组,这个是按照项组顺序排序好的缓存数组 + 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()) {