From 942d2c063451428a524e9bc79730c3d53afb4b57 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Thu, 2 May 2019 20:33:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=EF=BC=8C=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=20sku=20=E7=BC=96=E8=BE=91=E7=9A=84?= =?UTF-8?q?=20bug=20=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Product/ProductSkuAddOrUpdateTable.js | 10 +++++++++- .../models/product/productSpuAddOrUpdate.js | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/admin-web/src/components/Product/ProductSkuAddOrUpdateTable.js b/admin-web/src/components/Product/ProductSkuAddOrUpdateTable.js index 0cc08678e..c4659ebb0 100644 --- a/admin-web/src/components/Product/ProductSkuAddOrUpdateTable.js +++ b/admin-web/src/components/Product/ProductSkuAddOrUpdateTable.js @@ -42,9 +42,17 @@ export default class ProductSkuAddOrUpdateTable extends PureComponent { // debugger; // console.log('ProductSkuAddOrUpdateTable'); const {attrTree, skus, dispatch} = this.props; - let columns = []; + // 排除空选项的规格 + let newAttrTree = []; for (let i in attrTree) { let attr = attrTree[i]; + if (attr && attr.values && attr.values.length > 0) { + newAttrTree.push(attr); + } + } + let columns = []; + for (let i in newAttrTree) { + let attr = newAttrTree[i]; columns.push({ title: attr.name, dataIndex: 'attrs[i]', diff --git a/admin-web/src/models/product/productSpuAddOrUpdate.js b/admin-web/src/models/product/productSpuAddOrUpdate.js index 5cbd7309c..e4468048c 100644 --- a/admin-web/src/models/product/productSpuAddOrUpdate.js +++ b/admin-web/src/models/product/productSpuAddOrUpdate.js @@ -235,12 +235,21 @@ export default { selectAttrValueSuccess(state, {payload}) { // debugger; // console.log(state); + // 设置值。 state.attrTree[payload.attrIndex].values = payload.attrValues; + // 筛选有效的规格选项 + let attrTree = []; + for (let i in state.attrTree) { + let attr = state.attrTree[i]; + if (attr && attr.values && attr.values.length > 0) { + attrTree.push(attr); + } + } // 生成 skus 值 let skus = []; let skuSize = 1; - for (let i in state.attrTree) { // 先计算 sku 数量 - let attr = state.attrTree[i]; + for (let i in attrTree) { // 先计算 sku 数量 + let attr = attrTree[i]; skuSize = skuSize * attr.values.length; } // console.log('skuSize: ' + skuSize); @@ -252,14 +261,14 @@ export default { }); } // let interval = skuSize; // 该间隔,用于下面规格组合 - for (let i = 0; i < state.attrTree.length; i++) { // 初始化 sku 格子里的 attrs + for (let i = 0; i < attrTree.length; i++) { // 初始化 sku 格子里的 attrs if (i === 1) { // debugger; } - let values = state.attrTree[i].values; + let values = attrTree[i].values; let interval = skuSize / values.length; for (let j = 0; j < skuSize; j++) { - // let values = state.attrTree[i].values; + // let values = attrTree[i].values; // let attr = values[j % values.length]; // skus[i].attrs.push({ // id: attr.id,