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
c4f7aa76
authored
Aug 26, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码评审】商城:限时折扣活动
parent
af1bec2a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
33 deletions
+45
-33
src/views/mall/promotion/components/SpuAndSkuList.vue
+12
-13
src/views/mall/promotion/discountActivity/DiscountActivityForm.vue
+33
-20
No files found.
src/views/mall/promotion/components/SpuAndSkuList.vue
View file @
c4f7aa76
...
...
@@ -29,15 +29,14 @@
</el-table-column>
<el-table-column
align=
"center"
label=
"销量"
min-width=
"90"
prop=
"salesCount"
/>
<el-table-column
align=
"center"
label=
"库存"
min-width=
"90"
prop=
"stock"
/>
<el-table-column
v-if=
"spuData.length > 1 && isDelete"
align=
"center"
label=
"操作"
min-width=
"90"
>
<
template
#
default=
"scope"
>
<el-button
type=
"primary"
link
@
click=
"deleteSpu(scope.row.id)"
<el-table-column
v-if=
"spuData.length > 1 && isDelete"
align=
"center"
label=
"操作"
min-width=
"90"
>
删除
</el-button>
<
template
#
default=
"scope"
>
<
el-button
type=
"primary"
link
@
click=
"deleteSpu(scope.row.id)"
>
删除
<
/el-button>
</
template
>
</el-table-column>
</el-table>
...
...
@@ -57,7 +56,7 @@ const props = defineProps<{
spuList
:
T
[]
ruleConfig
:
RuleConfig
[]
spuPropertyListP
:
SpuProperty
<
T
>
[]
isDelete
?:
boolean
//
spu是否可以多选
isDelete
?:
boolean
//
SPU 是否可删除;TODO deletable 换成这个名字好点。
}
>
()
const
spuData
=
ref
<
Spu
[]
>
([])
// spu 详情数据列表
...
...
@@ -96,12 +95,12 @@ const emits = defineEmits<{
(
e
:
'delete'
,
spuId
:
number
):
void
}
>
()
/** 多选时可以删除
spu
**/
/** 多选时可以删除
SPU
**/
const
deleteSpu
=
async
(
spuId
:
number
)
=>
{
await
message
.
confirm
(
'是否删除商品编号为'
+
spuId
+
'的数据?'
)
le
t
index
=
spuData
.
value
.
findIndex
((
item
)
=>
item
.
id
==
spuId
)
spuData
.
value
.
splice
(
index
,
1
);
emits
(
'delete'
,
spuId
)
cons
t
index
=
spuData
.
value
.
findIndex
((
item
)
=>
item
.
id
==
spuId
)
spuData
.
value
.
splice
(
index
,
1
)
emits
(
'delete'
,
spuId
)
}
/**
...
...
src/views/mall/promotion/discountActivity/DiscountActivityForm.vue
View file @
c4f7aa76
...
...
@@ -49,7 +49,7 @@ import { cloneDeep } from 'lodash-es'
import
*
as
DiscountActivityApi
from
'@/api/mall/promotion/discount/discountActivity'
import
*
as
ProductSpuApi
from
'@/api/mall/product/spu'
import
{
getPropertyList
,
RuleConfig
}
from
'@/views/mall/product/spu/components'
import
{
formatToFraction
}
from
"@/utils"
;
import
{
formatToFraction
}
from
'@/utils'
defineOptions
({
name
:
'PromotionDiscountActivityForm'
})
...
...
@@ -68,7 +68,7 @@ const spuAndSkuListRef = ref() // sku 限时折扣 配置组件Ref
const
ruleConfig
:
RuleConfig
[]
=
[]
const
spuList
=
ref
<
DiscountActivityApi
.
SpuExtension
[]
>
([])
// 选择的 spu
const
spuPropertyList
=
ref
<
SpuProperty
<
DiscountActivityApi
.
SpuExtension
>
[]
>
([])
const
spuIds
=
ref
<
number
[]
>
([])
;
const
spuIds
=
ref
<
number
[]
>
([])
const
selectSpu
=
(
spuId
:
number
,
skuIds
:
number
[])
=>
{
getSpuDetails
(
spuId
,
skuIds
)
}
...
...
@@ -81,12 +81,12 @@ const getSpuDetails = async (
products
?:
DiscountActivityApi
.
DiscountProductVO
[],
type
?:
string
)
=>
{
//
如果已经包含spu
则跳过
if
(
spuIds
.
value
.
includes
(
spuId
))
{
if
(
type
!==
"load"
)
{
message
.
error
(
"数据重复选择!"
)
//
如果已经包含 SPU
则跳过
if
(
spuIds
.
value
.
includes
(
spuId
))
{
if
(
type
!==
'load'
)
{
message
.
error
(
'数据重复选择!'
)
}
return
;
return
}
spuIds
.
value
.
push
(
spuId
)
const
res
=
(
await
ProductSpuApi
.
getSpuDetailList
([
spuId
]))
as
DiscountActivityApi
.
SpuExtension
[]
...
...
@@ -143,7 +143,12 @@ const open = async (type: string, id?: number) => {
))
as
DiscountActivityApi
.
DiscountActivityVO
for
(
let
productsKey
in
data
.
products
)
{
const
supId
=
data
.
products
[
productsKey
].
spuId
await
getSpuDetails
(
supId
!
,
data
.
products
?.
map
((
sku
)
=>
sku
.
skuId
),
data
.
products
,
"load"
)
await
getSpuDetails
(
supId
!
,
data
.
products
?.
map
((
sku
)
=>
sku
.
skuId
),
data
.
products
,
'load'
)
}
formRef
.
value
.
setValues
(
data
)
}
finally
{
...
...
@@ -164,21 +169,23 @@ const submitForm = async () => {
formLoading
.
value
=
true
try
{
const
data
=
formRef
.
value
.
formModel
as
DiscountActivityApi
.
DiscountActivityVO
// 获取
折扣商品配置
// 获取折扣商品配置
const
products
=
cloneDeep
(
spuAndSkuListRef
.
value
.
getSkuConfigs
(
'productConfig'
))
let
timp
=
false
;
// 校验优惠金额、折扣百分比,是否正确
// TODO @puhui999:这个交互,可以参考下 youzan 的
let
discountInvalid
=
false
products
.
forEach
((
item
:
DiscountActivityApi
.
DiscountProductVO
)
=>
{
if
(
item
.
discountPrice
!=
null
&&
item
.
discountPrice
>
0
)
{
if
(
item
.
discountPrice
!=
null
&&
item
.
discountPrice
>
0
)
{
item
.
discountType
=
1
}
else
if
(
item
.
discountPercent
!=
null
&&
item
.
discountPercent
>
0
)
{
}
else
if
(
item
.
discountPercent
!=
null
&&
item
.
discountPercent
>
0
)
{
item
.
discountType
=
2
}
else
{
timp
=
true
}
else
{
discountInvalid
=
true
}
})
if
(
timp
)
{
message
.
error
(
"优惠金额和折扣百分比需要填写一个"
);
return
;
if
(
discountInvalid
)
{
message
.
error
(
'优惠金额和折扣百分比需要填写一个'
)
return
}
data
.
products
=
products
// 真正提交
...
...
@@ -207,10 +214,16 @@ const resetForm = async () => {
}
/**
* 删除
spu
* 删除
SPU
*/
const
deleteSpu
=
(
spuId
:
number
)
=>
{
spuIds
.
value
.
splice
(
spuIds
.
value
.
findIndex
((
item
)
=>
item
==
spuId
),
1
)
spuPropertyList
.
value
.
splice
(
spuPropertyList
.
value
.
findIndex
((
item
)
=>
item
.
spuId
==
spuId
),
1
)
spuIds
.
value
.
splice
(
spuIds
.
value
.
findIndex
((
item
)
=>
item
==
spuId
),
1
)
spuPropertyList
.
value
.
splice
(
spuPropertyList
.
value
.
findIndex
((
item
)
=>
item
.
spuId
==
spuId
),
1
)
}
</
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