前端:商品编辑,部分逻辑,解决 sku 编辑的 bug 。

This commit is contained in:
YunaiV 2019-05-02 20:33:03 +08:00
parent 91d475034c
commit 942d2c0634
2 changed files with 23 additions and 6 deletions

View File

@ -42,9 +42,17 @@ export default class ProductSkuAddOrUpdateTable extends PureComponent {
// debugger; // debugger;
// console.log('ProductSkuAddOrUpdateTable'); // console.log('ProductSkuAddOrUpdateTable');
const {attrTree, skus, dispatch} = this.props; const {attrTree, skus, dispatch} = this.props;
let columns = []; // 排除空选项的规格
let newAttrTree = [];
for (let i in attrTree) { for (let i in attrTree) {
let attr = attrTree[i]; 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({ columns.push({
title: attr.name, title: attr.name,
dataIndex: 'attrs[i]', dataIndex: 'attrs[i]',

View File

@ -235,12 +235,21 @@ export default {
selectAttrValueSuccess(state, {payload}) { selectAttrValueSuccess(state, {payload}) {
// debugger; // debugger;
// console.log(state); // console.log(state);
// 设置值。
state.attrTree[payload.attrIndex].values = payload.attrValues; 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 值 // 生成 skus 值
let skus = []; let skus = [];
let skuSize = 1; let skuSize = 1;
for (let i in state.attrTree) { // 先计算 sku 数量 for (let i in attrTree) { // 先计算 sku 数量
let attr = state.attrTree[i]; let attr = attrTree[i];
skuSize = skuSize * attr.values.length; skuSize = skuSize * attr.values.length;
} }
// console.log('skuSize: ' + skuSize); // console.log('skuSize: ' + skuSize);
@ -252,14 +261,14 @@ export default {
}); });
} }
// let interval = skuSize; // 该间隔,用于下面规格组合 // 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) { if (i === 1) {
// debugger; // debugger;
} }
let values = state.attrTree[i].values; let values = attrTree[i].values;
let interval = skuSize / values.length; let interval = skuSize / values.length;
for (let j = 0; j < skuSize; j++) { for (let j = 0; j < skuSize; j++) {
// let values = state.attrTree[i].values; // let values = attrTree[i].values;
// let attr = values[j % values.length]; // let attr = values[j % values.length];
// skus[i].attrs.push({ // skus[i].attrs.push({
// id: attr.id, // id: attr.id,