...
|
...
|
@@ -165,6 +165,7 @@ |
|
|
const selection = {};
|
|
|
const colorSizes = {};
|
|
|
const stocks = {};
|
|
|
const self = this;
|
|
|
|
|
|
// 更新颜色
|
|
|
this.colors = this.entity.goodsList.filter((goods)=> {
|
...
|
...
|
@@ -174,7 +175,7 @@ |
|
|
// 缩略图
|
|
|
thumbnails[goods.colorId] = goods.colorImage;
|
|
|
|
|
|
// 更新颜色对应尺码
|
|
|
// 更新颜色对应尺码 生成colorId 与 size的 映射
|
|
|
colorSizes[goods.colorId] = goods.goodsSizeBoList.map((size)=> {
|
|
|
if (!stocks[goods.colorId]) {
|
|
|
stocks[goods.colorId] = 0;
|
...
|
...
|
@@ -183,11 +184,21 @@ |
|
|
// 默认选中有库存的第一个颜色尺码
|
|
|
if (size.goodsSizeStorageNum > 0) {
|
|
|
if (!selection.color) {
|
|
|
selection.color = goods.colorId;
|
|
|
self.selection.color = selection.color = {
|
|
|
text: goods.colorName,
|
|
|
value: goods.colorId,
|
|
|
disabled: false
|
|
|
};
|
|
|
}
|
|
|
|
|
|
if (!selection.size && size.goodsSizeStorageNum > 0) {
|
|
|
selection.size = size.goodsSizeSkuId;
|
|
|
self.selection.size = selection.size = {
|
|
|
text: size.sizeName,
|
|
|
value: size.goodsSizeSkuId,
|
|
|
goodsId: size.goodsId,
|
|
|
disabled: false
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
// 计算所有尺码的库存
|
...
|
...
|
@@ -209,7 +220,7 @@ |
|
|
};
|
|
|
});
|
|
|
|
|
|
this.sizes = colorSizes[selection.color];
|
|
|
this.sizes = colorSizes[selection.color.value];
|
|
|
this.colorSizes = colorSizes;
|
|
|
this.thumbnails = thumbnails;
|
|
|
|
...
|
...
|
@@ -258,24 +269,24 @@ |
|
|
});
|
|
|
|
|
|
if (oldSizes && oldSizes.length > 0) {
|
|
|
const newSizes = this.colorSizes[opt];
|
|
|
const newSizes = this.colorSizes[opt.value];
|
|
|
|
|
|
const matchedSize = newSizes.filter((item)=> {
|
|
|
return !item.disabled && item.text === oldSizes[0].text;
|
|
|
});
|
|
|
|
|
|
if (matchedSize && matchedSize.length > 0) {
|
|
|
return matchedSize[0].value;
|
|
|
return matchedSize[0];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
})(this.selection.color, this.selection.size),
|
|
|
})(self.selection.color.value, self.selection.size.value),
|
|
|
thumbnail: this.thumbnails[opt]
|
|
|
};
|
|
|
|
|
|
this.sizes = this.colorSizes[opt];
|
|
|
this.sizes = this.colorSizes[opt.value];
|
|
|
Object.assign(this.selection, selection);
|
|
|
});
|
|
|
|
...
|
...
|
@@ -305,32 +316,9 @@ |
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.onAddToCart(this.selection, this.entity.pid);
|
|
|
},
|
|
|
|
|
|
|
|
|
getFullSelection() {
|
|
|
let size;
|
|
|
|
|
|
this.sizes.forEach((item)=> {
|
|
|
if (item.value === this.selection.size) {
|
|
|
size = item;
|
|
|
}
|
|
|
});
|
|
|
const param = Object.assign({goodsId: this.entity.id}, this.selection);
|
|
|
|
|
|
let color;
|
|
|
|
|
|
this.colors.indexOf((item)=> {
|
|
|
if (item.value === this.selection.color) {
|
|
|
color = item;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
size: size,
|
|
|
color: color,
|
|
|
productId: this.entity.id
|
|
|
};
|
|
|
this.onAddToCart(param);
|
|
|
}
|
|
|
}
|
|
|
};
|
...
|
...
|
|