Skip to content

Commit 879870e

Browse files
authored
Merge pull request #75 from GoldenZqqq/GoldenZqqq/Bug-Fix
添加商品属性项重复选择校验
2 parents bcb4fc3 + 9475ded commit 879870e

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
v-for="item2 in item.propertyOpts"
3838
:key="item2.id"
3939
:label="item2.name"
40-
:value="item2.id"
40+
:value="item2.name"
4141
/>
4242
</el-select>
4343
<el-button
@@ -57,7 +57,6 @@
5757
import * as PropertyApi from '@/api/mall/product/property'
5858
import { PropertyAndValues } from '@/views/mall/product/spu/components'
5959
import { propTypes } from '@/utils/propTypes'
60-
import { isNumber } from '@/utils/is'
6160
6261
defineOptions({ name: 'ProductAttributes' })
6362
@@ -123,13 +122,11 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
123122
if (inputValue.value) {
124123
// 重复添加校验
125124
// TODO @芋艿:需要测试下
126-
if (isNumber(inputValue.value)) {
127-
if (attributeList.value[index].values?.some((item) => item.id === inputValue.value)) {
128-
message.warning('已存在相同属性值,请重试')
129-
attributeIndex.value = null
130-
inputValue.value = ''
131-
return
132-
}
125+
if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
126+
message.warning('已存在相同属性值,请重试')
127+
attributeIndex.value = null
128+
inputValue.value = ''
129+
return
133130
}
134131
// 保存属性值
135132
try {

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)