Skip to content

Commit 521ae46

Browse files
committed
【功能优化】添加商品属性时允许选择已有的属性值,点击「选择」后,获取 value 列表
1 parent 879870e commit 521ae46

File tree

5 files changed

+16
-38
lines changed

5 files changed

+16
-38
lines changed

src/api/mall/product/property.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ export interface PropertyValueVO {
2424
remark?: string
2525
}
2626

27-
/**
28-
* 商品属性值的明细
29-
*/
30-
export interface PropertyValueDetailVO {
31-
/** 属性项的编号 */
32-
propertyId: number // 属性的编号
33-
/** 属性的名称 */
34-
propertyName: string
35-
/** 属性值的编号 */
36-
valueId: number
37-
/** 属性值的名称 */
38-
valueName: string
39-
}
40-
4127
// ------------------------ 属性项 -------------------
4228

4329
// 创建属性项
@@ -96,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
9682
export const deletePropertyValue = (id: number) => {
9783
return request.delete({ url: `/product/property/value/delete?id=${id}` })
9884
}
85+
86+
// 获得属性值精简列表
87+
export const getPropertyValueSimpleList = (propertyId: number): Promise<PropertyValueVO[]> => {
88+
return request.get({ url: '/product/property/value/simple-list', params: { propertyId } })
89+
}

src/views/mall/product/spu/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ interface PropertyAndValues {
55
id: number
66
name: string
77
values?: PropertyAndValues[]
8-
propertyOpts?: PropertyAndValues[] // TODO @GoldenZqqq:建议直接复用 values;
98
}
109

1110
interface RuleConfig {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@change="handleInputConfirm(index, item.id)"
3535
>
3636
<el-option
37-
v-for="item2 in item.propertyOpts"
37+
v-for="item2 in attributeOptions"
3838
:key="item2.id"
3939
:label="item2.name"
4040
:value="item2.name"
@@ -79,6 +79,7 @@ const setInputRef = (el: any) => {
7979
}
8080
}
8181
const attributeList = ref<PropertyAndValues[]>([]) // 商品属性列表
82+
const attributeOptions = ref([] as PropertyApi.PropertyValueVO[]) // 商品属性名称下拉框
8283
const props = defineProps({
8384
propertyList: {
8485
type: Array,
@@ -111,9 +112,11 @@ const handleCloseProperty = (index: number) => {
111112
}
112113
113114
/** 显示输入框并获取焦点 */
114-
const showInput = async (index) => {
115+
const showInput = async (index: number) => {
115116
attributeIndex.value = index
116117
inputRef.value[index].focus()
118+
// 获取属性下拉选项
119+
await getAttributeOptions(attributeList.value[index].id)
117120
}
118121
119122
/** 输入框失去焦点或点击回车时触发 */
@@ -141,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
141144
attributeIndex.value = null
142145
inputValue.value = ''
143146
}
147+
148+
/** 获取商品属性下拉选项 */
149+
const getAttributeOptions = async (propertyId: number) => {
150+
attributeOptions.value = await PropertyApi.getPropertyValueSimpleList(propertyId)
151+
}
144152
</script>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import * as PropertyApi from '@/api/mall/product/property'
3939
4040
defineOptions({ name: 'ProductPropertyForm' })
4141
42-
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
4342
const { t } = useI18n() // 国际化
4443
const message = useMessage() // 消息弹窗
4544
@@ -110,7 +109,6 @@ const submitForm = async () => {
110109
// 判断最终提交的属性名称是否是用户下拉选择的 自己手动输入的属性名称就不执行emit获取该属性名下属性值列表
111110
for (const element of attributeOptions.value) {
112111
if (element.name === formData.value.name) {
113-
emit('success', propertyId, element.id)
114112
message.success(t('common.createSuccess'))
115113
dialogVisible.value = false
116114
return

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,9 @@
5858
</el-form>
5959

6060
<!-- 商品属性添加 Form 表单 -->
61-
<ProductPropertyAddForm
62-
ref="attributesAddFormRef"
63-
:propertyList="propertyList"
64-
@success="getPropertyValueList"
65-
/>
61+
<ProductPropertyAddForm ref="attributesAddFormRef" :propertyList="propertyList" />
6662
</template>
6763
<script lang="ts" setup>
68-
import * as PropertyApi from '@/api/mall/product/property'
6964
import { PropType } from 'vue'
7065
import { copyValueToTarget } from '@/utils'
7166
import { propTypes } from '@/utils/propTypes'
@@ -196,17 +191,4 @@ const onChangeSpec = () => {
196191
const generateSkus = (propertyList: any[]) => {
197192
skuListRef.value.generateTableData(propertyList)
198193
}
199-
200-
// TODO @GoldenZqqq:这里不建议使用 success 去刷新。而是改成点击【属性值】的【添加】后,进行加载列表。后端提供了 getPropertyValueSimpleList 接口哈。
201-
/* 获取属性值列表 */
202-
const getPropertyValueList = async (id, propertyId) => {
203-
formLoading.value = true
204-
try {
205-
// TODO @芋艿:需要增加一个全列表接口
206-
const data = await PropertyApi.getPropertyValuePage({ pageNo: 1, pageSize: 100, propertyId })
207-
propertyList.value.find((item) => item.id === id).propertyOpts = data.list
208-
} finally {
209-
formLoading.value = false
210-
}
211-
}
212194
</script>

0 commit comments

Comments
 (0)