Skip to content

Commit 2937f3c

Browse files
committed
feat: 使用id来对商品属性值重复添加操作进行校验
1 parent 24e69ec commit 2937f3c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 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.name"
40+
:value="item2.id"
4141
/>
4242
</el-select>
4343
<el-button
@@ -57,6 +57,7 @@
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'
6061
6162
defineOptions({ name: 'ProductAttributes' })
6263
@@ -121,11 +122,13 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
121122
const handleInputConfirm = async (index: number, propertyId: number) => {
122123
if (inputValue.value) {
123124
// 重复添加校验
124-
if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
125-
message.warning('已存在相同属性值,请重试')
126-
attributeIndex.value = null
127-
inputValue.value = ''
128-
return
125+
if (isNumber(inputValue.value)) {
126+
if (attributeList.value[index].values?.some((item) => item.id === inputValue.value)) {
127+
message.warning('已存在相同属性值,请重试')
128+
attributeIndex.value = null
129+
inputValue.value = ''
130+
return
131+
}
129132
}
130133
// 保存属性值
131134
try {

0 commit comments

Comments
 (0)