【功能优化】添加商品属性时允许选择已有的属性值,点击「选择」后,获取 value 列表

pull/495/MERGE
YunaiV 2024-08-14 21:54:21 +08:00
parent 521ae46cba
commit 2dc738a6e7
2 changed files with 31 additions and 15 deletions

View File

@ -123,15 +123,25 @@ const showInput = async (index: number) => {
const emit = defineEmits(['success']) // success
const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) {
//
// TODO @
// 1.
if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
message.warning('已存在相同属性值,请重试')
attributeIndex.value = null
inputValue.value = ''
return
}
//
// 2.1 使
const existValue = attributeOptions.value.find((item) => item.name === inputValue.value)
if (existValue) {
attributeIndex.value = null
inputValue.value = ''
attributeList.value[index].values.push({ id: existValue.id, name: existValue.name })
emit('success', attributeList.value)
return
}
// 2.2
try {
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
attributeList.value[index].values.push({ id, name: inputValue.value })

View File

@ -83,18 +83,32 @@ defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */
const submitForm = async () => {
//
// 1.1
for (const attrItem of attributeList.value) {
if (attrItem.name === formData.value.name) {
return message.error('该属性已存在,请勿重复添加')
}
}
//
//
// 1.2
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
// 2.1 使
const existProperty = attributeOptions.value.find((item) => item.name === formData.value.name)
if (existProperty) {
//
attributeList.value.push({
id: existProperty.id,
...formData.value,
values: []
})
//
dialogVisible.value = false
return
}
// 2.2
//
formLoading.value = true
try {
@ -106,14 +120,6 @@ const submitForm = async () => {
...formData.value,
values: []
})
// emit
for (const element of attributeOptions.value) {
if (element.name === formData.value.name) {
message.success(t('common.createSuccess'))
dialogVisible.value = false
return
}
}
//
message.success(t('common.createSuccess'))
dialogVisible.value = false