[improvement] update eslint config (#2288)
This commit is contained in:
@@ -34,7 +34,7 @@ import { UNSELECTED_SKU_VALUE_ID } from '../constants';
|
||||
...
|
||||
}
|
||||
*/
|
||||
export const normalizeSkuTree = (skuTree) => {
|
||||
export const normalizeSkuTree = skuTree => {
|
||||
const normalizedTree = {};
|
||||
skuTree.forEach(treeItem => {
|
||||
normalizedTree[treeItem.k_s] = treeItem.v;
|
||||
@@ -45,17 +45,19 @@ export const normalizeSkuTree = (skuTree) => {
|
||||
// 判断是否所有的sku都已经选中
|
||||
export const isAllSelected = (skuTree, selectedSku) => {
|
||||
// 筛选selectedSku对象中key值不为空的值
|
||||
const selected = Object.keys(selectedSku).filter(skuKeyStr => selectedSku[skuKeyStr] !== UNSELECTED_SKU_VALUE_ID);
|
||||
const selected = Object.keys(selectedSku).filter(
|
||||
skuKeyStr => selectedSku[skuKeyStr] !== UNSELECTED_SKU_VALUE_ID
|
||||
);
|
||||
return skuTree.length === selected.length;
|
||||
};
|
||||
|
||||
// 根据已选择的sku获取skuComb
|
||||
// 根据已选择的 sku 获取 skuComb
|
||||
export const getSkuComb = (skuList, selectedSku) => {
|
||||
const skuComb = skuList.filter(skuComb => {
|
||||
return Object.keys(selectedSku).every(skuKeyStr => {
|
||||
return String(skuComb[skuKeyStr]) === String(selectedSku[skuKeyStr]); // eslint-disable-line
|
||||
});
|
||||
});
|
||||
const skuComb = skuList.filter(item => (
|
||||
Object.keys(selectedSku).every(
|
||||
skuKeyStr => String(item[skuKeyStr]) === String(selectedSku[skuKeyStr])
|
||||
)
|
||||
));
|
||||
return skuComb[0];
|
||||
};
|
||||
|
||||
@@ -67,7 +69,7 @@ export const getSelectedSkuValues = (skuTree, selectedSku) => {
|
||||
const skuValueId = selectedSku[skuKeyStr];
|
||||
|
||||
if (skuValueId !== UNSELECTED_SKU_VALUE_ID) {
|
||||
const skuValue = skuValues.filter(skuValue => skuValue.id === skuValueId)[0];
|
||||
const skuValue = skuValues.filter(value => value.id === skuValueId)[0];
|
||||
skuValue && selectedValues.push(skuValue);
|
||||
}
|
||||
return selectedValues;
|
||||
@@ -77,19 +79,27 @@ export const getSelectedSkuValues = (skuTree, selectedSku) => {
|
||||
// 判断sku是否可选
|
||||
export const isSkuChoosable = (skuList, selectedSku, skuToChoose) => {
|
||||
const { key, valueId } = skuToChoose;
|
||||
|
||||
// 先假设sku已选中,拼入已选中sku对象中
|
||||
const matchedSku = Object.assign({}, selectedSku, {
|
||||
[key]: valueId
|
||||
});
|
||||
// 再判断剩余sku是否全部不可选,若不可选则当前sku不可选中
|
||||
const skusToCheck = Object.keys(matchedSku).filter(skuKey => matchedSku[skuKey] !== UNSELECTED_SKU_VALUE_ID);
|
||||
const filteredSku = skuList.filter(sku => {
|
||||
return skusToCheck.every(skuKey => {
|
||||
return String(matchedSku[skuKey]) === String(sku[skuKey]);
|
||||
});
|
||||
});
|
||||
|
||||
const stock = filteredSku.reduce((total, sku) => (total += sku.stock_num), 0);
|
||||
// 再判断剩余sku是否全部不可选,若不可选则当前sku不可选中
|
||||
const skusToCheck = Object.keys(matchedSku).filter(
|
||||
skuKey => matchedSku[skuKey] !== UNSELECTED_SKU_VALUE_ID
|
||||
);
|
||||
|
||||
const filteredSku = skuList.filter(sku => (
|
||||
skusToCheck.every(
|
||||
skuKey => String(matchedSku[skuKey]) === String(sku[skuKey])
|
||||
)
|
||||
));
|
||||
|
||||
const stock = filteredSku.reduce((total, sku) => {
|
||||
total += sku.stock_num;
|
||||
return total;
|
||||
}, 0);
|
||||
return stock > 0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user