[bugfix] 修复sku默认选中逻辑与sku是否选中的判断逻辑 (#752)

This commit is contained in:
wny
2018-03-22 15:59:52 +08:00
committed by GitHub
parent ddbe338919
commit 347989bcc5
4 changed files with 49 additions and 24 deletions

View File

@@ -13,6 +13,7 @@
<script>
import create from '../../utils/create';
import { isSkuChoosable } from '../utils/skuHelper';
export default create({
name: 'sku-row-item',
@@ -31,19 +32,10 @@ export default create({
},
isChoosable() {
const matchedSku = Object.assign({}, this.selectedSku, {
[this.skuKeyStr]: this.skuValue.id
return isSkuChoosable(this.skuList, this.selectedSku, {
key: this.skuKeyStr,
valueId: this.skuValue.id
});
const skusToCheck = Object.keys(matchedSku).filter(skuKey => matchedSku[skuKey] !== '');
const filteredSku = this.skuList.filter(sku => {
return skusToCheck.every(skuKey => {
// 后端给的skuValue.id有时候是数字有时候是字符串全等会匹配不上
return matchedSku[skuKey] == sku[skuKey]; // eslint-disable-line
});
});
const stock = filteredSku.reduce((total, sku) => (total += sku.stock_num), 0);
return stock > 0;
}
},