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

pull/495/head
YunaiV 2024-08-14 13:06:23 +08:00
parent 879870ee26
commit 521ae46cba
5 changed files with 16 additions and 38 deletions

View File

@ -24,20 +24,6 @@ export interface PropertyValueVO {
remark?: string
}
/**
*
*/
export interface PropertyValueDetailVO {
/** 属性项的编号 */
propertyId: number // 属性的编号
/** 属性的名称 */
propertyName: string
/** 属性值的编号 */
valueId: number
/** 属性值的名称 */
valueName: string
}
// ------------------------ 属性项 -------------------
// 创建属性项
@ -96,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
export const deletePropertyValue = (id: number) => {
return request.delete({ url: `/product/property/value/delete?id=${id}` })
}
// 获得属性值精简列表
export const getPropertyValueSimpleList = (propertyId: number): Promise<PropertyValueVO[]> => {
return request.get({ url: '/product/property/value/simple-list', params: { propertyId } })
}

View File

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

View File

@ -34,7 +34,7 @@
@change="handleInputConfirm(index, item.id)"
>
<el-option
v-for="item2 in item.propertyOpts"
v-for="item2 in attributeOptions"
:key="item2.id"
:label="item2.name"
:value="item2.name"
@ -79,6 +79,7 @@ const setInputRef = (el: any) => {
}
}
const attributeList = ref<PropertyAndValues[]>([]) //
const attributeOptions = ref([] as PropertyApi.PropertyValueVO[]) //
const props = defineProps({
propertyList: {
type: Array,
@ -111,9 +112,11 @@ const handleCloseProperty = (index: number) => {
}
/** 显示输入框并获取焦点 */
const showInput = async (index) => {
const showInput = async (index: number) => {
attributeIndex.value = index
inputRef.value[index].focus()
//
await getAttributeOptions(attributeList.value[index].id)
}
/** 输入框失去焦点或点击回车时触发 */
@ -141,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
attributeIndex.value = null
inputValue.value = ''
}
/** 获取商品属性下拉选项 */
const getAttributeOptions = async (propertyId: number) => {
attributeOptions.value = await PropertyApi.getPropertyValueSimpleList(propertyId)
}
</script>

View File

@ -39,7 +39,6 @@ import * as PropertyApi from '@/api/mall/product/property'
defineOptions({ name: 'ProductPropertyForm' })
const emit = defineEmits(['success']) // success
const { t } = useI18n() //
const message = useMessage() //
@ -110,7 +109,6 @@ const submitForm = async () => {
// 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

View File

@ -58,14 +58,9 @@
</el-form>
<!-- 商品属性添加 Form 表单 -->
<ProductPropertyAddForm
ref="attributesAddFormRef"
:propertyList="propertyList"
@success="getPropertyValueList"
/>
<ProductPropertyAddForm ref="attributesAddFormRef" :propertyList="propertyList" />
</template>
<script lang="ts" setup>
import * as PropertyApi from '@/api/mall/product/property'
import { PropType } from 'vue'
import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes'
@ -196,17 +191,4 @@ const onChangeSpec = () => {
const generateSkus = (propertyList: any[]) => {
skuListRef.value.generateTableData(propertyList)
}
// TODO @GoldenZqqq使 success getPropertyValueSimpleList
/* 获取属性值列表 */
const getPropertyValueList = async (id, propertyId) => {
formLoading.value = true
try {
// TODO @
const data = await PropertyApi.getPropertyValuePage({ pageNo: 1, pageSize: 100, propertyId })
propertyList.value.find((item) => item.id === id).propertyOpts = data.list
} finally {
formLoading.value = false
}
}
</script>