修改SKU选择

msb_beta
ch 3 years ago
parent 810ebd3c8f
commit f20e423efb

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-24 11:30:55 * @Date: 2022-03-24 11:30:55
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-10 11:18:33 * @LastEditTime: 2022-05-17 16:32:32
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -116,14 +116,14 @@ export default {
* 当前选中SKU根据选中规格计算 * 当前选中SKU根据选中规格计算
*/ */
curSku(){ curSku(){
return this.skuInfo.find(i => i.attributeSymbolList === this.selectedSymbol.join(',')) || {}; return this.skuInfo.find(i => i.attributeSymbolList.join(',') === this.selectedSymbol.join(',')) || {};
}, },
// [1,.,3] // [1,.,3]
selectedSymbol(){ selectedSymbol(){
return this.attributeGroupList.map(item => { return this.attributeGroupList.map(item => {
const activeAttr = item.attributes.find(i => i.active); const activeAttr = item.attributes.find(i => i.active);
return activeAttr ? activeAttr.symbol : '.' return activeAttr?.symbol
}).filter(i => i)//.sort(); }).filter(i => i).sort();
}, },
/** /**
* 最大可购买数量 * 最大可购买数量
@ -147,7 +147,7 @@ export default {
} }
this.attributeGroupList.forEach((item, index) => { this.attributeGroupList.forEach((item, index) => {
for(let i of item.attributes){ for(let i of item.attributes){
if(curSku.attributeSymbolList.includes(i.symbol)){ if(curSku.attributeSymbolList.includes((i.symbol).toString())){
this.$set(i,'active', true); this.$set(i,'active', true);
this.setDisabledItem(i, index, true); this.setDisabledItem(i, index, true);
break; break;
@ -183,25 +183,44 @@ export default {
*/ */
setDisabledItem(item, groupIndex){ setDisabledItem(item, groupIndex){
this.attributeGroupList.forEach((group, idx) => { this.attributeGroupList.forEach((group, idx) => {
// // if(groupIndex === idx) return false;
let symbolCache = Object.assign([],this.selectedSymbol); //
//
if(groupIndex === idx) return false;
//
group.attributes.forEach( item => { group.attributes.forEach( item => {
// let symbolCache = Object.assign([],this.selectedSymbol);
symbolCache[idx] = item.symbol; symbolCache.push(item.symbol);
const reg = new RegExp(symbolCache.join(',')); symbolCache.sort();
// SKU const res = this.skuInfo.filter(item =>
const res = this.skuInfo.filter(i => reg.test(i.attributeSymbolList)).find(i => i.stock > 0); symbolCache.map(i => item.attributeSymbolList.includes(i.toString())).every(i => i)
).find(i => i.stock > 0);
if(res){ if(res){
item.disabled = false; item.disabled = false;
}else{ }else{
item.disabled = true; item.disabled = true;
} }
}) });
}) })
// this.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 = this.skuInfo.filter(i => reg.test(i.attributeSymbolList)).find(i => i.stock > 0);
// if(res){
// item.disabled = false;
// }else{
// item.disabled = true;
// }
// })
// })
}, },
/** /**
* 加入购物车 * 加入购物车

Loading…
Cancel
Save