feat(Sku): add properties support (#5525)

This commit is contained in:
Waiter
2020-01-09 16:49:55 +08:00
committed by neverland
parent c6489f4006
commit 589d66d68a
9 changed files with 261 additions and 28 deletions
+24 -1
View File
@@ -42,6 +42,18 @@ export const normalizeSkuTree = skuTree => {
return normalizedTree;
};
export const normalizePropList = propList => {
const normalizedProp = {};
propList.forEach(item => {
const itemObj = {};
item.v.forEach(it => {
itemObj[it.id] = it;
});
normalizedProp[item.k_id] = itemObj;
});
return normalizedProp;
};
// 判断是否所有的sku都已经选中
export const isAllSelected = (skuTree, selectedSku) => {
// 筛选selectedSku对象中key值不为空的值
@@ -104,10 +116,21 @@ export const isSkuChoosable = (skuList, selectedSku, skuToChoose) => {
return stock > 0;
};
export const getSelectedPropValues = (propList, selectedProp) => {
const normalizeProp = normalizePropList(propList);
return Object.keys(selectedProp).reduce((acc, cur) => {
selectedProp[cur].forEach(it => {
acc.push(normalizeProp[cur][it]);
});
return acc;
}, []);
};
export default {
normalizeSkuTree,
getSkuComb,
getSelectedSkuValues,
isAllSelected,
isSkuChoosable
isSkuChoosable,
getSelectedPropValues,
};