diff --git a/yshop-drink-vue3/src/views/mall/product/storeProduct/StoreProductForm.vue b/yshop-drink-vue3/src/views/mall/product/storeProduct/StoreProductForm.vue index 513dd3e..2224f52 100644 --- a/yshop-drink-vue3/src/views/mall/product/storeProduct/StoreProductForm.vue +++ b/yshop-drink-vue3/src/views/mall/product/storeProduct/StoreProductForm.vue @@ -740,6 +740,7 @@ const getInfo = (id) => { const route = useRoute() // 立即生成 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 => { manyFormValidate.value = res.value; let headerdel = { @@ -759,6 +760,10 @@ const generate = () => { }); oneFormBatch.value[0].pic = formValidate.value.image; } + manyFormValidate.value = manyFormValidate.value.map((item) => ({ + ...item, + ...(previousRows.get(JSON.stringify(item.detail)) || {}) + })); }).catch(res => { console.log('err:'+res) }) @@ -818,12 +823,13 @@ const confirm = () => { // 删除规格 const handleRemoveRole = (index) => { attrs.value.splice(index, 1); - manyFormValidate.value.splice(index, 1); + if (manyFormValidate.value.length) generate(); } // 删除属性 const handleRemove2 = (item, index) => { item.splice(index, 1); + if (manyFormValidate.value.length) generate(); } // 添加规则名称 @@ -844,6 +850,7 @@ const createAttrName = () =>{ clearAttr(); showIput.value = false; createBnt.value = true; + if (manyFormValidate.value.length) generate(); } else { message.warning('请添加完整的规格!') } @@ -857,6 +864,7 @@ const createAttr = (num, idx) => { hash[next] ? '' : hash[next] = true && item.push(next); return item }, []) + if (manyFormValidate.value.length) generate(); } else { message.warning('请添加属性!') }