修复多规格商品添加时的子项添加

This commit is contained in:
Kroytz committed 2026-07-18 22:40:52 +08:00
1 parent 2aa950e5f4
commit 2977ef7d81
1 file changed
+9 -1
@@ -740,6 +740,7 @@ const getInfo = (id) => {
const route = useRoute() const route = useRoute()
// 立即生成 // 立即生成
const generate = () => { const generate = () => {
const previousRows = new Map(manyFormValidate.value.map((item) => [JSON.stringify(item.detail), item]));
StoreProductApi.isFormatAttr(formValidate.value.id, { attrs: attrs.value }).then(res => { StoreProductApi.isFormatAttr(formValidate.value.id, { attrs: attrs.value }).then(res => {
manyFormValidate.value = res.value; manyFormValidate.value = res.value;
let headerdel = { let headerdel = {
@@ -759,6 +760,10 @@ const generate = () => {
}); });
oneFormBatch.value[0].pic = formValidate.value.image; oneFormBatch.value[0].pic = formValidate.value.image;
} }
manyFormValidate.value = manyFormValidate.value.map((item) => ({
...item,
...(previousRows.get(JSON.stringify(item.detail)) || {})
}));
}).catch(res => { }).catch(res => {
console.log('err:'+res) console.log('err:'+res)
}) })
@@ -818,12 +823,13 @@ const confirm = () => {
// 删除规格 // 删除规格
const handleRemoveRole = (index) => { const handleRemoveRole = (index) => {
attrs.value.splice(index, 1); attrs.value.splice(index, 1);
manyFormValidate.value.splice(index, 1); if (manyFormValidate.value.length) generate();
} }
// 删除属性 // 删除属性
const handleRemove2 = (item, index) => { const handleRemove2 = (item, index) => {
item.splice(index, 1); item.splice(index, 1);
if (manyFormValidate.value.length) generate();
} }
// 添加规则名称 // 添加规则名称
@@ -844,6 +850,7 @@ const createAttrName = () =>{
clearAttr(); clearAttr();
showIput.value = false; showIput.value = false;
createBnt.value = true; createBnt.value = true;
if (manyFormValidate.value.length) generate();
} else { } else {
message.warning('请添加完整的规格!') message.warning('请添加完整的规格!')
} }
@@ -857,6 +864,7 @@ const createAttr = (num, idx) => {
hash[next] ? '' : hash[next] = true && item.push(next); hash[next] ? '' : hash[next] = true && item.push(next);
return item return item
}, []) }, [])
if (manyFormValidate.value.length) generate();
} else { } else {
message.warning('请添加属性!') message.warning('请添加属性!')
} }