Skip to content

Commit c40ca13

Browse files
author
preschool
committed
Merge branch 'master' of gitee.com:yudaocode/yudao-ui-admin-vue3
2 parents cc1d2b1 + 521ae46 commit c40ca13

File tree

6 files changed

+107
-32
lines changed

6 files changed

+107
-32
lines changed

src/api/mall/product/property.ts

Lines changed: 10 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
// 创建属性项
@@ -65,6 +51,11 @@ export const getPropertyPage = (params: PageParam) => {
6551
return request.get({ url: '/product/property/page', params })
6652
}
6753

54+
// 获得属性项精简列表
55+
export const getPropertySimpleList = (): Promise<PropertyVO[]> => {
56+
return request.get({ url: '/product/property/simple-list' })
57+
}
58+
6859
// ------------------------ 属性值 -------------------
6960

7061
// 获得属性值分页
@@ -91,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
9182
export const deletePropertyValue = (id: number) => {
9283
return request.delete({ url: `/product/property/value/delete?id=${id}` })
9384
}
85+
86+
// 获得属性值精简列表
87+
export const getPropertyValueSimpleList = (propertyId: number): Promise<PropertyValueVO[]> => {
88+
return request.get({ url: '/product/property/value/simple-list', params: { propertyId } })
89+
}

src/components/DictTag/src/DictTag.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineComponent, PropType, computed } from 'vue'
33
import { isHexColor } from '@/utils/color'
44
import { ElTag } from 'element-plus'
55
import { DictDataType, getDictOptions } from '@/utils/dict'
6-
import { isArray, isString, isNumber } from '@/utils/is'
6+
import { isArray, isString, isNumber, isBoolean } from '@/utils/is'
77
88
export default defineComponent({
99
name: 'DictTag',
@@ -29,15 +29,15 @@ export default defineComponent({
2929
},
3030
setup(props) {
3131
const valueArr: any = computed(() => {
32-
// 1.是Number类型的情况
33-
if (isNumber(props.value)) {
32+
// 1. 是 Number 类型和 Boolean 类型的情况
33+
if (isNumber(props.value) || isBoolean(props.value)) {
3434
return [String(props.value)]
3535
}
36-
// 2.是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol )
36+
// 2. 是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol )
3737
else if (isString(props.value)) {
3838
return props.value.split(props.separator)
3939
}
40-
// 3.数组
40+
// 3. 数组
4141
else if (isArray(props.value)) {
4242
return props.value.map(String)
4343
}
@@ -57,7 +57,7 @@ export default defineComponent({
5757
<div
5858
class="dict-tag"
5959
style={{
60-
display: 'flex',
60+
display: 'inline-flex',
6161
gap: props.gutter,
6262
justifyContent: 'center',
6363
alignItems: 'center'

src/views/mall/product/spu/components/SkuList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
>
2525
<template #default="{ row }">
2626
<span style="font-weight: bold; color: #40aaff">
27-
{{ row.properties[index]?.valueName }}
27+
{{ row.properties?.[index]?.valueName }}
2828
</span>
2929
</template>
3030
</el-table-column>
@@ -168,7 +168,7 @@
168168
>
169169
<template #default="{ row }">
170170
<span style="font-weight: bold; color: #40aaff">
171-
{{ row.properties[index]?.valueName }}
171+
{{ row.properties?.[index]?.valueName }}
172172
</span>
173173
</template>
174174
</el-table-column>
@@ -248,7 +248,7 @@
248248
>
249249
<template #default="{ row }">
250250
<span style="font-weight: bold; color: #40aaff">
251-
{{ row.properties[index]?.valueName }}
251+
{{ row.properties?.[index]?.valueName }}
252252
</span>
253253
</template>
254254
</el-table-column>

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,28 @@
1818
>
1919
{{ value.name }}
2020
</el-tag>
21-
<el-input
22-
v-show="inputVisible(index)"
21+
<el-select
2322
:id="`input${index}`"
2423
:ref="setInputRef"
24+
v-show="inputVisible(index)"
2525
v-model="inputValue"
26-
class="!w-20"
26+
filterable
27+
allow-create
28+
default-first-option
29+
:reserve-keyword="false"
2730
size="small"
31+
class="!w-30"
2832
@blur="handleInputConfirm(index, item.id)"
2933
@keyup.enter="handleInputConfirm(index, item.id)"
30-
/>
34+
@change="handleInputConfirm(index, item.id)"
35+
>
36+
<el-option
37+
v-for="item2 in attributeOptions"
38+
:key="item2.id"
39+
:label="item2.name"
40+
:value="item2.name"
41+
/>
42+
</el-select>
3143
<el-button
3244
v-show="!inputVisible(index)"
3345
class="button-new-tag ml-1"
@@ -42,7 +54,6 @@
4254
</template>
4355

4456
<script lang="ts" setup>
45-
import { ElInput } from 'element-plus'
4657
import * as PropertyApi from '@/api/mall/product/property'
4758
import { PropertyAndValues } from '@/views/mall/product/spu/components'
4859
import { propTypes } from '@/utils/propTypes'
@@ -68,6 +79,7 @@ const setInputRef = (el: any) => {
6879
}
6980
}
7081
const attributeList = ref<PropertyAndValues[]>([]) // 商品属性列表
82+
const attributeOptions = ref([] as PropertyApi.PropertyValueVO[]) // 商品属性名称下拉框
7183
const props = defineProps({
7284
propertyList: {
7385
type: Array,
@@ -100,15 +112,25 @@ const handleCloseProperty = (index: number) => {
100112
}
101113
102114
/** 显示输入框并获取焦点 */
103-
const showInput = async (index) => {
115+
const showInput = async (index: number) => {
104116
attributeIndex.value = index
105117
inputRef.value[index].focus()
118+
// 获取属性下拉选项
119+
await getAttributeOptions(attributeList.value[index].id)
106120
}
107121
108122
/** 输入框失去焦点或点击回车时触发 */
109123
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
110124
const handleInputConfirm = async (index: number, propertyId: number) => {
111125
if (inputValue.value) {
126+
// 重复添加校验
127+
// TODO @芋艿:需要测试下
128+
if (attributeList.value[index].values.find((item) => item.name === inputValue.value)) {
129+
message.warning('已存在相同属性值,请重试')
130+
attributeIndex.value = null
131+
inputValue.value = ''
132+
return
133+
}
112134
// 保存属性值
113135
try {
114136
const id = await PropertyApi.createPropertyValue({ propertyId, name: inputValue.value })
@@ -122,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
122144
attributeIndex.value = null
123145
inputValue.value = ''
124146
}
147+
148+
/** 获取商品属性下拉选项 */
149+
const getAttributeOptions = async (propertyId: number) => {
150+
attributeOptions.value = await PropertyApi.getPropertyValueSimpleList(propertyId)
151+
}
125152
</script>

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@
1010
@keydown.enter.prevent="submitForm"
1111
>
1212
<el-form-item label="属性名称" prop="name">
13-
<el-input v-model="formData.name" placeholder="请输入名称" />
13+
<el-select
14+
v-model="formData.name"
15+
filterable
16+
allow-create
17+
default-first-option
18+
:reserve-keyword="false"
19+
placeholder="请选择属性名称。如果不存在,可手动输入选择"
20+
class="!w-360px"
21+
>
22+
<el-option
23+
v-for="item in attributeOptions"
24+
:key="item.id"
25+
:label="item.name"
26+
:value="item.name"
27+
/>
28+
</el-select>
1429
</el-form-item>
1530
</el-form>
1631
<template #footer>
@@ -37,6 +52,7 @@ const formRules = reactive({
3752
})
3853
const formRef = ref() // 表单 Ref
3954
const attributeList = ref([]) // 商品属性列表
55+
const attributeOptions = ref([] as PropertyApi.PropertyVO[]) // 商品属性名称下拉框
4056
const props = defineProps({
4157
propertyList: {
4258
type: Array,
@@ -60,11 +76,21 @@ watch(
6076
const open = async () => {
6177
dialogVisible.value = true
6278
resetForm()
79+
// 加载列表
80+
await getAttributeOptions()
6381
}
6482
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
6583
6684
/** 提交表单 */
6785
const submitForm = async () => {
86+
// 情况一:如果是已存在的属性,直接结束,不提交表单新增
87+
for (const attrItem of attributeList.value) {
88+
if (attrItem.name === formData.value.name) {
89+
return message.error('该属性已存在,请勿重复添加')
90+
}
91+
}
92+
93+
// 情况二:如果是不存在的属性,则需要执行新增
6894
// 校验表单
6995
if (!formRef) return
7096
const valid = await formRef.value.validate()
@@ -80,6 +106,15 @@ const submitForm = async () => {
80106
...formData.value,
81107
values: []
82108
})
109+
// 判断最终提交的属性名称是否是用户下拉选择的 自己手动输入的属性名称就不执行emit获取该属性名下属性值列表
110+
for (const element of attributeOptions.value) {
111+
if (element.name === formData.value.name) {
112+
message.success(t('common.createSuccess'))
113+
dialogVisible.value = false
114+
return
115+
}
116+
}
117+
// 关闭弹窗
83118
message.success(t('common.createSuccess'))
84119
dialogVisible.value = false
85120
} finally {
@@ -94,4 +129,14 @@ const resetForm = () => {
94129
}
95130
formRef.value?.resetFields()
96131
}
132+
133+
/** 获取商品属性下拉选项 */
134+
const getAttributeOptions = async () => {
135+
formLoading.value = true
136+
try {
137+
attributeOptions.value = await PropertyApi.getPropertySimpleList()
138+
} finally {
139+
formLoading.value = false
140+
}
141+
}
97142
</script>

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<!-- 商品发布 - 库存价格 -->
22
<template>
3-
<el-form ref="formRef" :disabled="isDetail" :model="formData" :rules="rules" label-width="120px">
3+
<el-form
4+
ref="formRef"
5+
:disabled="isDetail"
6+
:model="formData"
7+
:rules="rules"
8+
label-width="120px"
9+
v-loading="formLoading"
10+
>
411
<el-form-item label="分销类型" props="subCommissionType">
512
<el-radio-group
613
v-model="formData.subCommissionType"
@@ -94,7 +101,7 @@ const ruleConfig: RuleConfig[] = [
94101
]
95102
96103
const message = useMessage() // 消息弹窗
97-
104+
const formLoading = ref(false)
98105
const props = defineProps({
99106
propFormData: {
100107
type: Object as PropType<Spu>,

0 commit comments

Comments
 (0)