Merge pull request #75 from GoldenZqqq/GoldenZqqq/Bug-Fix

添加商品属性项重复选择校验
This commit is contained in:
芋道源码 2024-08-14 12:54:45 +08:00 committed by GitHub
commit 879870ee26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 22 deletions

View File

@ -37,7 +37,7 @@
v-for="item2 in item.propertyOpts" v-for="item2 in item.propertyOpts"
:key="item2.id" :key="item2.id"
:label="item2.name" :label="item2.name"
:value="item2.id" :value="item2.name"
/> />
</el-select> </el-select>
<el-button <el-button
@ -57,7 +57,6 @@
import * as PropertyApi from '@/api/mall/product/property' import * as PropertyApi from '@/api/mall/product/property'
import { PropertyAndValues } from '@/views/mall/product/spu/components' import { PropertyAndValues } from '@/views/mall/product/spu/components'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
import { isNumber } from '@/utils/is'
defineOptions({ name: 'ProductAttributes' }) defineOptions({ name: 'ProductAttributes' })
@ -123,13 +122,11 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) { if (inputValue.value) {
// //
// TODO @ // TODO @
if (isNumber(inputValue.value)) { if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
if (attributeList.value[index].values?.some((item) => item.id === inputValue.value)) { message.warning('已存在相同属性值,请重试')
message.warning('已存在相同属性值,请重试') attributeIndex.value = null
attributeIndex.value = null inputValue.value = ''
inputValue.value = '' return
return
}
} }
// //
try { try {

View File

@ -85,19 +85,9 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { const submitForm = async () => {
// //
for (const option of attributeOptions.value) { for (const attrItem of attributeList.value) {
if (option.name === formData.value.name) { if (attrItem.name === formData.value.name) {
// return message.error('该属性已存在,请勿重复添加')
attributeList.value.push({
id: option.id,
...formData.value,
values: []
})
//
emit('success', option.id, option.id)
//
dialogVisible.value = false
return
} }
} }
@ -117,6 +107,15 @@ const submitForm = async () => {
...formData.value, ...formData.value,
values: [] values: []
}) })
// emit
for (const element of attributeOptions.value) {
if (element.name === formData.value.name) {
emit('success', propertyId, element.id)
message.success(t('common.createSuccess'))
dialogVisible.value = false
return
}
}
// //
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
dialogVisible.value = false dialogVisible.value = false