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
20f3f726
authored
Jun 07, 2023
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 数组操作添加 ? 可选操作符,避免属性值为 null 时报错
parent
b89db1af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
src/views/mall/product/spu/addForm.vue
+1
-1
src/views/mall/product/spu/components/BasicInfoForm.vue
+7
-7
No files found.
src/views/mall/product/spu/addForm.vue
View file @
20f3f726
...
@@ -104,7 +104,7 @@ const getDetail = async () => {
...
@@ -104,7 +104,7 @@ const getDetail = async () => {
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
res
=
(
await
ProductSpuApi
.
getSpu
(
id
))
as
ProductSpuApi
.
Spu
const
res
=
(
await
ProductSpuApi
.
getSpu
(
id
))
as
ProductSpuApi
.
Spu
res
.
skus
!
.
forEach
((
item
)
=>
{
res
.
skus
?
.
forEach
((
item
)
=>
{
// 回显价格分转元
// 回显价格分转元
item
.
price
=
formatToFraction
(
item
.
price
)
item
.
price
=
formatToFraction
(
item
.
price
)
item
.
marketPrice
=
formatToFraction
(
item
.
marketPrice
)
item
.
marketPrice
=
formatToFraction
(
item
.
marketPrice
)
...
...
src/views/mall/product/spu/components/BasicInfoForm.vue
View file @
20f3f726
...
@@ -256,7 +256,7 @@ watch(
...
@@ -256,7 +256,7 @@ watch(
return
return
}
}
copyValueToTarget
(
formData
,
data
)
copyValueToTarget
(
formData
,
data
)
formData
.
sliderPicUrls
=
data
[
'sliderPicUrls'
].
map
((
item
)
=>
({
formData
.
sliderPicUrls
=
data
[
'sliderPicUrls'
]
?
.
map
((
item
)
=>
({
url
:
item
url
:
item
}))
}))
// 只有是多规格才处理
// 只有是多规格才处理
...
@@ -265,16 +265,16 @@ watch(
...
@@ -265,16 +265,16 @@ watch(
}
}
// 直接拿返回的 skus 属性逆向生成出 propertyList
// 直接拿返回的 skus 属性逆向生成出 propertyList
const
properties
=
[]
const
properties
=
[]
formData
.
skus
.
forEach
((
sku
)
=>
{
formData
.
skus
?
.
forEach
((
sku
)
=>
{
sku
.
properties
.
forEach
(({
propertyId
,
propertyName
,
valueId
,
valueName
})
=>
{
sku
.
properties
?
.
forEach
(({
propertyId
,
propertyName
,
valueId
,
valueName
})
=>
{
// 添加属性
// 添加属性
if
(
!
properties
.
some
((
item
)
=>
item
.
id
===
propertyId
))
{
if
(
!
properties
?
.
some
((
item
)
=>
item
.
id
===
propertyId
))
{
properties
.
push
({
id
:
propertyId
,
name
:
propertyName
,
values
:
[]
})
properties
.
push
({
id
:
propertyId
,
name
:
propertyName
,
values
:
[]
})
}
}
// 添加属性值
// 添加属性值
const
index
=
properties
.
findIndex
((
item
)
=>
item
.
id
===
propertyId
)
const
index
=
properties
?
.
findIndex
((
item
)
=>
item
.
id
===
propertyId
)
if
(
!
properties
[
index
].
values
.
some
((
value
)
=>
value
.
id
===
valueId
))
{
if
(
!
properties
[
index
].
values
?
.
some
((
value
)
=>
value
.
id
===
valueId
))
{
properties
[
index
].
values
.
push
({
id
:
valueId
,
name
:
valueName
})
properties
[
index
].
values
?
.
push
({
id
:
valueId
,
name
:
valueName
})
}
}
})
})
})
})
...
...
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