【功能优化】添加商品属性时允许选择已有的属性值

pull/495/head
YunaiV 2024-08-14 00:43:34 +08:00
parent e7c9ca0c5b
commit bcb4fc3034
5 changed files with 35 additions and 19 deletions

View File

@ -65,6 +65,11 @@ export const getPropertyPage = (params: PageParam) => {
return request.get({ url: '/product/property/page', params }) return request.get({ url: '/product/property/page', params })
} }
// 获得属性项精简列表
export const getPropertySimpleList = (): Promise<PropertyVO[]> => {
return request.get({ url: '/product/property/simple-list' })
}
// ------------------------ 属性值 ------------------- // ------------------------ 属性值 -------------------
// 获得属性值分页 // 获得属性值分页

View File

@ -5,7 +5,7 @@ interface PropertyAndValues {
id: number id: number
name: string name: string
values?: PropertyAndValues[] values?: PropertyAndValues[]
propertyOpts?: PropertyAndValues[] propertyOpts?: PropertyAndValues[] // TODO @GoldenZqqq建议直接复用 values
} }
interface RuleConfig { interface RuleConfig {

View File

@ -122,6 +122,7 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
const handleInputConfirm = async (index: number, propertyId: number) => { const handleInputConfirm = async (index: number, propertyId: number) => {
if (inputValue.value) { if (inputValue.value) {
// //
// TODO @
if (isNumber(inputValue.value)) { if (isNumber(inputValue.value)) {
if (attributeList.value[index].values?.some((item) => item.id === inputValue.value)) { if (attributeList.value[index].values?.some((item) => item.id === inputValue.value)) {
message.warning('已存在相同属性值,请重试') message.warning('已存在相同属性值,请重试')

View File

@ -16,11 +16,11 @@
allow-create allow-create
default-first-option default-first-option
:reserve-keyword="false" :reserve-keyword="false"
placeholder="请选择属性名称" placeholder="请选择属性名称。如果不存在,可手动输入选择"
style="width: 240px" class="!w-360px"
> >
<el-option <el-option
v-for="item in attrOption" v-for="item in attributeOptions"
:key="item.id" :key="item.id"
:label="item.name" :label="item.name"
:value="item.name" :value="item.name"
@ -53,7 +53,7 @@ const formRules = reactive({
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const attributeList = ref([]) // const attributeList = ref([]) //
const attrOption = ref([]) // const attributeOptions = ref([] as PropertyApi.PropertyVO[]) //
const props = defineProps({ const props = defineProps({
propertyList: { propertyList: {
type: Array, type: Array,
@ -76,13 +76,32 @@ watch(
/** 打开弹窗 */ /** 打开弹窗 */
const open = async () => { const open = async () => {
dialogVisible.value = true dialogVisible.value = true
getAttrOption()
resetForm() resetForm()
//
await getAttributeOptions()
} }
defineExpose({ open }) // open defineExpose({ open }) // open
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { const submitForm = async () => {
//
for (const option of attributeOptions.value) {
if (option.name === formData.value.name) {
//
attributeList.value.push({
id: option.id,
...formData.value,
values: []
})
//
emit('success', option.id, option.id)
//
dialogVisible.value = false
return
}
}
//
// //
if (!formRef) return if (!formRef) return
const valid = await formRef.value.validate() const valid = await formRef.value.validate()
@ -98,15 +117,7 @@ const submitForm = async () => {
...formData.value, ...formData.value,
values: [] values: []
}) })
// emit //
for (const element of attrOption.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
} finally { } finally {
@ -123,12 +134,10 @@ const resetForm = () => {
} }
/** 获取商品属性下拉选项 */ /** 获取商品属性下拉选项 */
const getAttrOption = async () => { const getAttributeOptions = async () => {
formLoading.value = true formLoading.value = true
try { try {
// TODO @ attributeOptions.value = await PropertyApi.getPropertySimpleList()
const data = await PropertyApi.getPropertyPage({ pageNo: 1, pageSize: 100 })
attrOption.value = data.list
} finally { } finally {
formLoading.value = false formLoading.value = false
} }

View File

@ -197,6 +197,7 @@ const generateSkus = (propertyList: any[]) => {
skuListRef.value.generateTableData(propertyList) skuListRef.value.generateTableData(propertyList)
} }
// TODO @GoldenZqqq使 success getPropertyValueSimpleList
/* 获取属性值列表 */ /* 获取属性值列表 */
const getPropertyValueList = async (id, propertyId) => { const getPropertyValueList = async (id, propertyId) => {
formLoading.value = true formLoading.value = true