Commit 32b90c6e authored by 武广's avatar 武广

fix: 修改商品驳回规格多行合并一行的问题

parent 0165fab1
...@@ -298,7 +298,6 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -298,7 +298,6 @@ const FormPriceOrStock = forwardRef((props, ref) => {
const { inIdList: secndInIdList, noIdList: secndNoIdList } = filterSkuNotIdList( const { inIdList: secndInIdList, noIdList: secndNoIdList } = filterSkuNotIdList(
cleanValues.secondValues, cleanValues.secondValues,
); );
const createSkuList = createProductData( const createSkuList = createProductData(
{ {
firstSpecId: cleanValues.firstSpecId, firstSpecId: cleanValues.firstSpecId,
...@@ -309,14 +308,17 @@ const FormPriceOrStock = forwardRef((props, ref) => { ...@@ -309,14 +308,17 @@ const FormPriceOrStock = forwardRef((props, ref) => {
secndNoIdList, secndNoIdList,
}, },
customer.isEdit, customer.isEdit,
skuList,
); );
CreateColumnsEvent(values); CreateColumnsEvent(values);
// 没有规格默认创建一条数据
if (!cleanValues.firstSpecId && !createSkuList.secondSpecId) { if (!cleanValues.firstSpecId && !createSkuList.secondSpecId) {
setTableData([...createSkuList]); setTableData([...createSkuList]);
return; return;
} }
// 是否合并单元格
setMergeTable(Boolean(cleanValues.secondValues.length)); setMergeTable(Boolean(cleanValues.secondValues.length));
setTableData(fliterSkuListSortData([...skuList, ...createSkuList])); setTableData(fliterSkuListSortData([...createSkuList]));
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
......
...@@ -182,29 +182,38 @@ const createInitSkuItems = () => ({ ...@@ -182,29 +182,38 @@ const createInitSkuItems = () => ({
name: null, name: null,
}); });
export const createSkuListData = (first, second, firstSpecId, secondSpecId) => { const getSecordValue = (firstSpecValue, sec, skuList) =>
skuList.find(
sku =>
sku.firstSpecValue === firstSpecValue &&
(!sku.secondSpecValue || sku.secondSpecValue === sec.secondSpecValue),
);
export const createSkuListData = (first, second, firstSpecId, secondSpecId, skuList) => {
const list = []; const list = [];
const skuItem = createInitSkuItems(); const skuItem = createInitSkuItems();
console.log(first, second, firstSpecId, secondSpecId);
if (first && first.length) { if (first && first.length) {
// 一级规格有值时,生成的编辑表格 // 一级规格有值时,生成的编辑表格
first.forEach(fir => { first.forEach(fir => {
const copy = { ...skuItem }; let copy = { ...skuItem };
copy.firstSpecId = firstSpecId; copy.firstSpecId = firstSpecId;
copy.firstSpecValue = fir.firstSpecValue; copy.firstSpecValue = fir.firstSpecValue;
// console.log(copy);
if (second.length) { if (second.length) {
second.forEach(sec => { second.forEach(sec => {
const copySec = { ...copy }; const v = getSecordValue(fir.firstSpecValue, sec, skuList);
const copySec = v || { ...copy };
copySec.secondSpecId = secondSpecId; copySec.secondSpecId = secondSpecId;
copySec.secondSpecValue = sec.secondSpecValue; copySec.secondSpecValue = sec.secondSpecValue;
delete copySec.rowSpanCount;
list.push(copySec); list.push(copySec);
}); });
return; return;
} }
const v = getSecordValue(`${fir.firstSpecValue}`, {}, skuList);
if (v) {
copy = { ...v };
}
list.push(copy); list.push(copy);
}); });
} else if (second && second.length) { } else if (second && second.length) {
...@@ -222,7 +231,7 @@ export const createSkuListData = (first, second, firstSpecId, secondSpecId) => { ...@@ -222,7 +231,7 @@ export const createSkuListData = (first, second, firstSpecId, secondSpecId) => {
return list; return list;
}; };
export const createProductData = (props, isEdit) => { export const createProductData = (props, isEdit, skuList) => {
const { const {
firstSpecId, firstSpecId,
secondSpecId, secondSpecId,
...@@ -231,20 +240,13 @@ export const createProductData = (props, isEdit) => { ...@@ -231,20 +240,13 @@ export const createProductData = (props, isEdit) => {
fisrtInIdList, fisrtInIdList,
secndInIdList, secndInIdList,
} = props; } = props;
const newFirstList = fisrtNoIdList.concat(fisrtInIdList || []);
let list = []; let list = [];
// if (!isFirstSame && !isSecondSame) { if (isEdit) {
if (!isEdit) { const newFirstList = fisrtNoIdList.concat(fisrtInIdList || []);
list = createSkuListData(fisrtNoIdList, secndNoIdList, firstSpecId, secondSpecId); const newSecondList = secndInIdList.concat(secndNoIdList || []);
list = createSkuListData(newFirstList, newSecondList, firstSpecId, secondSpecId, skuList);
} else { } else {
const list1 = fisrtNoIdList.length list = createSkuListData(fisrtNoIdList, secndNoIdList, firstSpecId, secondSpecId);
? createSkuListData(fisrtNoIdList, secndInIdList, firstSpecId, secondSpecId)
: [];
const list2 = secndNoIdList.length
? createSkuListData(newFirstList, secndNoIdList, firstSpecId, secondSpecId)
: [];
list = [...list1, ...list2];
} }
// }
return list; return list;
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment