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

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

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