Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
521ae46c
authored
Aug 14, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【功能优化】添加商品属性时允许选择已有的属性值,点击「选择」后,获取 value 列表
parent
879870ee
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
38 deletions
+16
-38
src/api/mall/product/property.ts
+5
-14
src/views/mall/product/spu/components/index.ts
+0
-1
src/views/mall/product/spu/form/ProductAttributes.vue
+10
-2
src/views/mall/product/spu/form/ProductPropertyAddForm.vue
+0
-2
src/views/mall/product/spu/form/SkuForm.vue
+1
-19
No files found.
src/api/mall/product/property.ts
View file @
521ae46c
...
@@ -24,20 +24,6 @@ export interface PropertyValueVO {
...
@@ -24,20 +24,6 @@ export interface PropertyValueVO {
remark
?:
string
remark
?:
string
}
}
/**
* 商品属性值的明细
*/
export
interface
PropertyValueDetailVO
{
/** 属性项的编号 */
propertyId
:
number
// 属性的编号
/** 属性的名称 */
propertyName
:
string
/** 属性值的编号 */
valueId
:
number
/** 属性值的名称 */
valueName
:
string
}
// ------------------------ 属性项 -------------------
// ------------------------ 属性项 -------------------
// 创建属性项
// 创建属性项
...
@@ -96,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
...
@@ -96,3 +82,8 @@ export const updatePropertyValue = (data: PropertyValueVO) => {
export
const
deletePropertyValue
=
(
id
:
number
)
=>
{
export
const
deletePropertyValue
=
(
id
:
number
)
=>
{
return
request
.
delete
({
url
:
`/product/property/value/delete?id=
${
id
}
`
})
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
}
})
}
src/views/mall/product/spu/components/index.ts
View file @
521ae46c
...
@@ -5,7 +5,6 @@ interface PropertyAndValues {
...
@@ -5,7 +5,6 @@ interface PropertyAndValues {
id
:
number
id
:
number
name
:
string
name
:
string
values
?:
PropertyAndValues
[]
values
?:
PropertyAndValues
[]
propertyOpts
?:
PropertyAndValues
[]
// TODO @GoldenZqqq:建议直接复用 values;
}
}
interface
RuleConfig
{
interface
RuleConfig
{
...
...
src/views/mall/product/spu/form/ProductAttributes.vue
View file @
521ae46c
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
@change="handleInputConfirm(index, item.id)"
@change="handleInputConfirm(index, item.id)"
>
>
<el-option
<el-option
v-for=
"item2 in
item.propertyOpt
s"
v-for=
"item2 in
attributeOption
s"
:key=
"item2.id"
:key=
"item2.id"
:label=
"item2.name"
:label=
"item2.name"
:value=
"item2.name"
:value=
"item2.name"
...
@@ -79,6 +79,7 @@ const setInputRef = (el: any) => {
...
@@ -79,6 +79,7 @@ const setInputRef = (el: any) => {
}
}
}
}
const
attributeList
=
ref
<
PropertyAndValues
[]
>
([])
// 商品属性列表
const
attributeList
=
ref
<
PropertyAndValues
[]
>
([])
// 商品属性列表
const
attributeOptions
=
ref
([]
as
PropertyApi
.
PropertyValueVO
[])
// 商品属性名称下拉框
const
props
=
defineProps
({
const
props
=
defineProps
({
propertyList
:
{
propertyList
:
{
type
:
Array
,
type
:
Array
,
...
@@ -111,9 +112,11 @@ const handleCloseProperty = (index: number) => {
...
@@ -111,9 +112,11 @@ const handleCloseProperty = (index: number) => {
}
}
/** 显示输入框并获取焦点 */
/** 显示输入框并获取焦点 */
const
showInput
=
async
(
index
)
=>
{
const
showInput
=
async
(
index
:
number
)
=>
{
attributeIndex
.
value
=
index
attributeIndex
.
value
=
index
inputRef
.
value
[
index
].
focus
()
inputRef
.
value
[
index
].
focus
()
// 获取属性下拉选项
await
getAttributeOptions
(
attributeList
.
value
[
index
].
id
)
}
}
/** 输入框失去焦点或点击回车时触发 */
/** 输入框失去焦点或点击回车时触发 */
...
@@ -141,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
...
@@ -141,4 +144,9 @@ const handleInputConfirm = async (index: number, propertyId: number) => {
attributeIndex
.
value
=
null
attributeIndex
.
value
=
null
inputValue
.
value
=
''
inputValue
.
value
=
''
}
}
/** 获取商品属性下拉选项 */
const
getAttributeOptions
=
async
(
propertyId
:
number
)
=>
{
attributeOptions
.
value
=
await
PropertyApi
.
getPropertyValueSimpleList
(
propertyId
)
}
</
script
>
</
script
>
src/views/mall/product/spu/form/ProductPropertyAddForm.vue
View file @
521ae46c
...
@@ -39,7 +39,6 @@ import * as PropertyApi from '@/api/mall/product/property'
...
@@ -39,7 +39,6 @@ import * as PropertyApi from '@/api/mall/product/property'
defineOptions
({
name
:
'ProductPropertyForm'
})
defineOptions
({
name
:
'ProductPropertyForm'
})
const
emit
=
defineEmits
([
'success'
])
// 定义 success 事件,用于操作成功后的回调
const
{
t
}
=
useI18n
()
// 国际化
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
...
@@ -110,7 +109,6 @@ const submitForm = async () => {
...
@@ -110,7 +109,6 @@ const submitForm = async () => {
// 判断最终提交的属性名称是否是用户下拉选择的 自己手动输入的属性名称就不执行emit获取该属性名下属性值列表
// 判断最终提交的属性名称是否是用户下拉选择的 自己手动输入的属性名称就不执行emit获取该属性名下属性值列表
for
(
const
element
of
attributeOptions
.
value
)
{
for
(
const
element
of
attributeOptions
.
value
)
{
if
(
element
.
name
===
formData
.
value
.
name
)
{
if
(
element
.
name
===
formData
.
value
.
name
)
{
emit
(
'success'
,
propertyId
,
element
.
id
)
message
.
success
(
t
(
'common.createSuccess'
))
message
.
success
(
t
(
'common.createSuccess'
))
dialogVisible
.
value
=
false
dialogVisible
.
value
=
false
return
return
...
...
src/views/mall/product/spu/form/SkuForm.vue
View file @
521ae46c
...
@@ -58,14 +58,9 @@
...
@@ -58,14 +58,9 @@
</el-form>
</el-form>
<!-- 商品属性添加 Form 表单 -->
<!-- 商品属性添加 Form 表单 -->
<ProductPropertyAddForm
<ProductPropertyAddForm
ref=
"attributesAddFormRef"
:propertyList=
"propertyList"
/>
ref=
"attributesAddFormRef"
:propertyList=
"propertyList"
@
success=
"getPropertyValueList"
/>
</template>
</template>
<
script
lang=
"ts"
setup
>
<
script
lang=
"ts"
setup
>
import
*
as
PropertyApi
from
'@/api/mall/product/property'
import
{
PropType
}
from
'vue'
import
{
PropType
}
from
'vue'
import
{
copyValueToTarget
}
from
'@/utils'
import
{
copyValueToTarget
}
from
'@/utils'
import
{
propTypes
}
from
'@/utils/propTypes'
import
{
propTypes
}
from
'@/utils/propTypes'
...
@@ -196,17 +191,4 @@ const onChangeSpec = () => {
...
@@ -196,17 +191,4 @@ const onChangeSpec = () => {
const
generateSkus
=
(
propertyList
:
any
[])
=>
{
const
generateSkus
=
(
propertyList
:
any
[])
=>
{
skuListRef
.
value
.
generateTableData
(
propertyList
)
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
>
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment