Skip to content

Commit 0e9fde1

Browse files
committed
fix: 添加商品属性值时增加校验,如果是已存在的属性发出警告且不提交
1 parent bcb4fc3 commit 0e9fde1

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/views/mall/product/spu/form/ProductPropertyAddForm.vue

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,9 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
8585
/** 提交表单 */
8686
const submitForm = async () => {
8787
// 情况一:如果是已存在的属性,直接结束,不提交表单新增
88-
for (const option of attributeOptions.value) {
89-
if (option.name === formData.value.name) {
90-
// 添加到属性列表
91-
attributeList.value.push({
92-
id: option.id,
93-
...formData.value,
94-
values: []
95-
})
96-
// 触发属性列表的加载
97-
emit('success', option.id, option.id)
98-
// 关闭弹窗
99-
dialogVisible.value = false
100-
return
88+
for (const attrItem of attributeList.value) {
89+
if (attrItem.name === formData.value.name) {
90+
return message.error('该属性已存在,请勿重复添加')
10191
}
10292
}
10393
@@ -117,6 +107,15 @@ const submitForm = async () => {
117107
...formData.value,
118108
values: []
119109
})
110+
// 判断最终提交的属性名称是否是用户下拉选择的 自己手动输入的属性名称就不执行emit获取该属性名下属性值列表
111+
for (const element of attributeOptions.value) {
112+
if (element.name === formData.value.name) {
113+
emit('success', propertyId, element.id)
114+
message.success(t('common.createSuccess'))
115+
dialogVisible.value = false
116+
return
117+
}
118+
}
120119
// 关闭弹窗
121120
message.success(t('common.createSuccess'))
122121
dialogVisible.value = false

0 commit comments

Comments
 (0)