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
f9780b63
authored
Aug 31, 2023
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 1、修复营销活动相关页面打不开的问题 2、修复 spu 添加失败的问题 2、重构 spu 的 sku 校验方式为通用配置的方式
parent
264a29e4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
24 deletions
+82
-24
src/views/mall/product/spu/components/SkuList.vue
+0
-9
src/views/mall/product/spu/components/index.ts
+30
-1
src/views/mall/product/spu/form/BasicInfoForm.vue
+41
-3
src/views/mall/product/spu/form/index.vue
+11
-11
No files found.
src/views/mall/product/spu/components/SkuList.vue
View file @
f9780b63
...
@@ -328,12 +328,10 @@ const tableHeaders = ref<{ prop: string; label: string }[]>([]) // 多属性表
...
@@ -328,12 +328,10 @@ const tableHeaders = ref<{ prop: string; label: string }[]>([]) // 多属性表
* 保存时,每个商品规格的表单要校验下。例如说,销售金额最低是 0.01 这种。
* 保存时,每个商品规格的表单要校验下。例如说,销售金额最低是 0.01 这种。
*/
*/
const
validateSku
=
()
=>
{
const
validateSku
=
()
=>
{
const
checks
=
[
'price'
,
'marketPrice'
,
'costPrice'
]
let
warningInfo
=
'请检查商品各行相关属性配置,'
let
warningInfo
=
'请检查商品各行相关属性配置,'
let
validate
=
true
// 默认通过
let
validate
=
true
// 默认通过
for
(
const
sku
of
formData
.
value
!
.
skus
!
)
{
for
(
const
sku
of
formData
.
value
!
.
skus
!
)
{
// 作为活动组件的校验
// 作为活动组件的校验
if
(
props
.
isActivityComponent
)
{
for
(
const
rule
of
props
?.
ruleConfig
)
{
for
(
const
rule
of
props
?.
ruleConfig
)
{
const
arg
=
getValue
(
sku
,
rule
.
name
)
const
arg
=
getValue
(
sku
,
rule
.
name
)
if
(
!
rule
.
rule
(
arg
))
{
if
(
!
rule
.
rule
(
arg
))
{
...
@@ -342,13 +340,6 @@ const validateSku = () => {
...
@@ -342,13 +340,6 @@ const validateSku = () => {
break
break
}
}
}
}
}
else
{
if
(
checks
.
some
((
check
)
=>
sku
[
check
]
<
0.01
))
{
validate
=
false
// 只要有一个不通过则直接不通过
warningInfo
=
'商品相关价格不能低于 0.01 元!!'
break
}
}
// 只要有一个不通过则结束后续的校验
// 只要有一个不通过则结束后续的校验
if
(
!
validate
)
{
if
(
!
validate
)
{
message
.
warning
(
warningInfo
)
message
.
warning
(
warningInfo
)
...
...
src/views/mall/product/spu/components/index.ts
View file @
f9780b63
import
SkuList
from
'./SkuList.vue'
import
SkuList
from
'./SkuList.vue'
import
{
Spu
}
from
'@/api/mall/product/spu'
interface
PropertyAndValues
{
interface
PropertyAndValues
{
id
:
number
id
:
number
...
@@ -22,4 +23,32 @@ interface RuleConfig {
...
@@ -22,4 +23,32 @@ interface RuleConfig {
message
:
string
message
:
string
}
}
export
{
SkuList
,
PropertyAndValues
,
RuleConfig
}
/**
* 获得商品的规格列表 - 商品相关的公共函数
*
* @param spu
* @return PropertyAndValues 规格列表
*/
const
getPropertyList
=
(
spu
:
Spu
):
PropertyAndValues
[]
=>
{
// 直接拿返回的 skus 属性逆向生成出 propertyList
const
properties
:
PropertyAndValues
[]
=
[]
// 只有是多规格才处理
if
(
spu
.
specType
)
{
spu
.
skus
?.
forEach
((
sku
)
=>
{
sku
.
properties
?.
forEach
(({
propertyId
,
propertyName
,
valueId
,
valueName
})
=>
{
// 添加属性
if
(
!
properties
?.
some
((
item
)
=>
item
.
id
===
propertyId
))
{
properties
.
push
({
id
:
propertyId
!
,
name
:
propertyName
!
,
values
:
[]
})
}
// 添加属性值
const
index
=
properties
?.
findIndex
((
item
)
=>
item
.
id
===
propertyId
)
if
(
!
properties
[
index
].
values
?.
some
((
value
)
=>
value
.
id
===
valueId
))
{
properties
[
index
].
values
?.
push
({
id
:
valueId
!
,
name
:
valueName
!
})
}
})
})
}
return
properties
}
export
{
SkuList
,
PropertyAndValues
,
RuleConfig
,
getPropertyList
}
src/views/mall/product/spu/form/BasicInfoForm.vue
View file @
f9780b63
...
@@ -109,7 +109,12 @@
...
@@ -109,7 +109,12 @@
<!-- 多规格添加-->
<!-- 多规格添加-->
<el-col
:span=
"24"
>
<el-col
:span=
"24"
>
<el-form-item
v-if=
"!formData.specType"
>
<el-form-item
v-if=
"!formData.specType"
>
<SkuList
ref=
"skuListRef"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
/>
<SkuList
ref=
"skuListRef"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
:rule-config=
"ruleConfig"
/>
</el-form-item>
</el-form-item>
<el-form-item
v-if=
"formData.specType"
label=
"商品属性"
>
<el-form-item
v-if=
"formData.specType"
label=
"商品属性"
>
<el-button
class=
"mr-15px mb-10px"
@
click=
"attributesAddFormRef.open"
>
添加规格
</el-button>
<el-button
class=
"mr-15px mb-10px"
@
click=
"attributesAddFormRef.open"
>
添加规格
</el-button>
...
@@ -120,7 +125,12 @@
...
@@ -120,7 +125,12 @@
<SkuList
:is-batch=
"true"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
/>
<SkuList
:is-batch=
"true"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"属性列表"
>
<el-form-item
label=
"属性列表"
>
<SkuList
ref=
"skuListRef"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
/>
<SkuList
ref=
"skuListRef"
:prop-form-data=
"formData"
:propertyList=
"propertyList"
:rule-config=
"ruleConfig"
/>
</el-form-item>
</el-form-item>
</
template
>
</
template
>
</el-col>
</el-col>
...
@@ -175,7 +185,11 @@ import { propTypes } from '@/utils/propTypes'
...
@@ -175,7 +185,11 @@ import { propTypes } from '@/utils/propTypes'
import
{
checkSelectedNode
,
defaultProps
,
handleTree
,
treeToString
}
from
'@/utils/tree'
import
{
checkSelectedNode
,
defaultProps
,
handleTree
,
treeToString
}
from
'@/utils/tree'
import
{
createImageViewer
}
from
'@/components/ImageViewer'
import
{
createImageViewer
}
from
'@/components/ImageViewer'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
DICT_TYPE
,
getIntDictOptions
}
from
'@/utils/dict'
import
{
PropertyAndValues
,
SkuList
}
from
'@/views/mall/product/spu/components/index.ts'
import
{
PropertyAndValues
,
RuleConfig
,
SkuList
}
from
'@/views/mall/product/spu/components/index.ts'
import
ProductAttributes
from
'./ProductAttributes.vue'
import
ProductAttributes
from
'./ProductAttributes.vue'
import
ProductPropertyAddForm
from
'./ProductPropertyAddForm.vue'
import
ProductPropertyAddForm
from
'./ProductPropertyAddForm.vue'
import
{
basicInfoSchema
}
from
'./spu.data'
import
{
basicInfoSchema
}
from
'./spu.data'
...
@@ -186,6 +200,30 @@ import * as ExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
...
@@ -186,6 +200,30 @@ import * as ExpressTemplateApi from '@/api/mall/trade/delivery/expressTemplate'
defineOptions
({
name
:
'ProductSpuBasicInfoForm'
})
defineOptions
({
name
:
'ProductSpuBasicInfoForm'
})
// sku 相关属性校验规则
const
ruleConfig
:
RuleConfig
[]
=
[
{
name
:
'stock'
,
rule
:
(
arg
)
=>
arg
>=
1
,
message
:
'商品库存必须大于等于 1 !!!'
},
{
name
:
'price'
,
rule
:
(
arg
)
=>
arg
>=
0.01
,
message
:
'商品销售价格必须大于等于 0.01 !!!'
},
{
name
:
'marketPrice'
,
rule
:
(
arg
)
=>
arg
>=
0.01
,
message
:
'商品市场价格必须大于等于 0.01 !!!'
},
{
name
:
'costPrice'
,
rule
:
(
arg
)
=>
arg
>=
0.01
,
message
:
'商品成本价格必须大于等于 0.01 !!!'
}
]
// ====== 商品详情相关操作 ======
// ====== 商品详情相关操作 ======
const
{
allSchemas
}
=
useCrudSchemas
(
basicInfoSchema
)
const
{
allSchemas
}
=
useCrudSchemas
(
basicInfoSchema
)
/** 商品图预览 */
/** 商品图预览 */
...
...
src/views/mall/product/spu/form/index.vue
View file @
f9780b63
...
@@ -142,17 +142,17 @@ const submitForm = async () => {
...
@@ -142,17 +142,17 @@ const submitForm = async () => {
await
unref
(
otherSettingsRef
)?.
validate
()
await
unref
(
otherSettingsRef
)?.
validate
()
// 深拷贝一份, 这样最终 server 端不满足,不需要恢复,
// 深拷贝一份, 这样最终 server 端不满足,不需要恢复,
const
deepCopyFormData
=
cloneDeep
(
unref
(
formData
.
value
))
as
ProductSpuApi
.
Spu
const
deepCopyFormData
=
cloneDeep
(
unref
(
formData
.
value
))
as
ProductSpuApi
.
Spu
// 兜底处理 sku 空数据
// 兜底处理 sku 空数据
TODO 后续没得问题就移除
formData
.
value
.
skus
!
.
forEach
((
sku
)
=>
{
//
formData.value.skus!.forEach((sku) => {
// 因为是空数据这里判断一下商品条码是否为空就行
//
// 因为是空数据这里判断一下商品条码是否为空就行
if
(
sku
.
barCode
===
''
)
{
//
if (sku.barCode === '') {
const
index
=
deepCopyFormData
.
skus
!
.
findIndex
(
//
const index = deepCopyFormData.skus!.findIndex(
(
item
)
=>
JSON
.
stringify
(
item
.
properties
)
===
JSON
.
stringify
(
sku
.
properties
)
//
(item) => JSON.stringify(item.properties) === JSON.stringify(sku.properties)
)
//
)
// 删除这条 sku
//
// 删除这条 sku
deepCopyFormData
.
skus
!
.
splice
(
index
,
1
)
//
deepCopyFormData.skus!.splice(index, 1)
}
//
}
})
//
})
deepCopyFormData
.
skus
!
.
forEach
((
item
)
=>
{
deepCopyFormData
.
skus
!
.
forEach
((
item
)
=>
{
// 给sku name赋值
// 给sku name赋值
item
.
name
=
deepCopyFormData
.
name
item
.
name
=
deepCopyFormData
.
name
...
...
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