|
|
|
@ -2,7 +2,7 @@
|
|
|
|
|
* @Author: ch
|
|
|
|
|
* @Date: 2022-03-24 11:30:55
|
|
|
|
|
* @LastEditors: ch
|
|
|
|
|
* @LastEditTime: 2022-05-10 11:18:33
|
|
|
|
|
* @LastEditTime: 2022-05-17 16:32:32
|
|
|
|
|
* @Description: file content
|
|
|
|
|
-->
|
|
|
|
|
<template>
|
|
|
|
@ -116,14 +116,14 @@ export default {
|
|
|
|
|
* 当前选中SKU,根据选中规格计算
|
|
|
|
|
*/
|
|
|
|
|
curSku(){
|
|
|
|
|
return this.skuInfo.find(i => i.attributeSymbolList === this.selectedSymbol.join(',')) || {};
|
|
|
|
|
return this.skuInfo.find(i => i.attributeSymbolList.join(',') === this.selectedSymbol.join(',')) || {};
|
|
|
|
|
},
|
|
|
|
|
// [1,.,3]
|
|
|
|
|
selectedSymbol(){
|
|
|
|
|
return this.attributeGroupList.map(item => {
|
|
|
|
|
const activeAttr = item.attributes.find(i => i.active);
|
|
|
|
|
return activeAttr ? activeAttr.symbol : '.'
|
|
|
|
|
}).filter(i => i)//.sort();
|
|
|
|
|
return activeAttr?.symbol
|
|
|
|
|
}).filter(i => i).sort();
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 最大可购买数量
|
|
|
|
@ -147,7 +147,7 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
this.attributeGroupList.forEach((item, index) => {
|
|
|
|
|
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.setDisabledItem(i, index, true);
|
|
|
|
|
break;
|
|
|
|
@ -183,25 +183,44 @@ export default {
|
|
|
|
|
*/
|
|
|
|
|
setDisabledItem(item, groupIndex){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.attributeGroupList.forEach((group, idx) => {
|
|
|
|
|
// 拿到已选项数组,这个是按照项组顺序排序好的缓存数组
|
|
|
|
|
let symbolCache = Object.assign([],this.selectedSymbol);
|
|
|
|
|
// 跳过当前属性组
|
|
|
|
|
if(groupIndex === idx) return false;
|
|
|
|
|
// 遍历其他选项组中的选项
|
|
|
|
|
// 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);
|
|
|
|
|
let symbolCache = Object.assign([],this.selectedSymbol);
|
|
|
|
|
symbolCache.push(item.symbol);
|
|
|
|
|
symbolCache.sort();
|
|
|
|
|
const res = this.skuInfo.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;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// })
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 加入购物车
|
|
|
|
|