Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenshaokai
jinfa-platform
Commits
a9cde169
Commit
a9cde169
authored
Mar 23, 2022
by
前端-钟卫鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 暂存商品新增可新增属性值功能
parent
4595fbee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
30 deletions
+122
-30
productAttributeForm.tsx
...mmodity/products/addProductsItem/productAttributeForm.tsx
+122
-30
No files found.
src/pages/commodity/products/addProductsItem/productAttributeForm.tsx
View file @
a9cde169
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'react'
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'react'
import
{
history
,
useIntl
}
from
'umi'
import
{
history
,
useIntl
}
from
'umi'
import
{
Form
,
Select
,
Checkbox
,
Tabs
,
Input
,
DatePicker
,
Row
,
Col
}
from
'antd'
import
{
Form
,
Select
,
Checkbox
,
Tabs
,
Input
,
DatePicker
,
Row
,
Col
,
Button
,
Modal
}
from
'antd'
import
{
inject
,
observer
}
from
'mobx-react'
import
{
inject
,
observer
}
from
'mobx-react'
import
{
store
}
from
'@/store'
import
{
store
}
from
'@/store'
import
{
validatorByte
}
from
'@/utils/regExp'
import
{
validatorByte
}
from
'@/utils/regExp'
...
@@ -29,6 +29,7 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -29,6 +29,7 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
const
[
isClearFormAndDataInEdit
,
setIsClearFormAndDataInEdit
]
=
useState
<
boolean
>
(
false
)
// 编辑情况下 是否要清空商品属性表单数据和页面全局数据
const
[
isClearFormAndDataInEdit
,
setIsClearFormAndDataInEdit
]
=
useState
<
boolean
>
(
false
)
// 编辑情况下 是否要清空商品属性表单数据和页面全局数据
const
productAttributeFormRef
=
useRef
()
const
productAttributeFormRef
=
useRef
()
const
[
attributeForm
]
=
Form
.
useForm
()
const
[
attributeForm
]
=
Form
.
useForm
()
const
[
addForm
]
=
Form
.
useForm
()
const
{
ProductStore
}
=
store
const
{
ProductStore
}
=
store
const
{
const
{
attributeLists
,
attributeLists
,
...
@@ -38,6 +39,10 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -38,6 +39,10 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
clearProductDetailsUnitPriceAndPicListInEdit
,
clearProductDetailsUnitPriceAndPicListInEdit
,
setIsRecombination
setIsRecombination
}
=
ProductStore
}
=
ProductStore
const
[
addVisible
,
setAddVisible
]
=
useState
<
boolean
>
(
false
)
const
[
loading
,
setLoading
]
=
useState
<
boolean
>
(
false
)
const
currentRow
=
useRef
<
any
>
()
const
[
dataSource
,
setDataSource
]
=
useState
<
any
>
([...
attributesData
])
useEffect
(()
=>
{
useEffect
(()
=>
{
onRef
(
productAttributeFormRef
)
onRef
(
productAttributeFormRef
)
...
@@ -143,6 +148,42 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -143,6 +148,42 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
setProductSelectAttribute
(
_selectAttributeByEdit
)
setProductSelectAttribute
(
_selectAttributeByEdit
)
}
}
const
addAtttributeValue
=
(
record
)
=>
{
console
.
log
(
record
)
currentRow
.
current
=
record
setAddVisible
(
true
)
addForm
.
setFieldsValue
({
'name'
:
record
[
'name'
],
isEnable
:
true
,
groupName
:
record
[
'groupName'
]})
}
const
handleAdd
=
()
=>
{
setLoading
(
true
)
addForm
.
submit
()
}
const
addSubmit
=
(
values
)
=>
{
console
.
log
(
values
,
'addSubmitvv'
)
console
.
log
(
dataSource
)
// @todo 调用后台新增属性值接口 成功后写入属性值
const
_dataSource
=
dataSource
.
map
((
item
,
index
)
=>
{
if
(
item
.
id
===
currentRow
.
current
.
id
)
{
item
.
customerAttributeValueList
.
push
({
...
item
.
customerAttributeValueList
[
0
],
id
:
10086
,
...
values
,
})
}
return
item
})
console
.
log
(
_dataSource
)
setDataSource
([...
_dataSource
])
}
const
handleCancel
=
()
=>
{
setAddVisible
(
false
)
addForm
.
resetFields
()
setLoading
(
false
)
}
const
renderTabPanchildren
=
(
attrItem
:
any
)
=>
{
const
renderTabPanchildren
=
(
attrItem
:
any
)
=>
{
let
_isPrice
=
null
let
_isPrice
=
null
let
_isUpdateAttribute
=
null
let
_isUpdateAttribute
=
null
...
@@ -169,18 +210,25 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -169,18 +210,25 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
message
:
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.message'
})
message
:
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.message'
})
}]
}
}]
}
>
>
<
Select
<
Row
>
disabled=
{
_isDisabled
}
<
Col
span=
{
20
}
>
placeholder=
{
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.placeholder.1'
})
}
<
Select
allowClear
disabled=
{
_isDisabled
}
onChange=
{
(
v
)
=>
onChange
(
v
,
attrItem
)
}
placeholder=
{
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.placeholder.1'
})
}
>
allowClear
{
onChange=
{
(
v
)
=>
onChange
(
v
,
attrItem
)
}
attrItem
?.
customerAttributeValueList
.
length
>
0
&&
attrItem
.
customerAttributeValueList
.
map
((
item
:
any
)
=>
(
>
<
Option
key=
{
item
.
id
}
value=
{
item
.
id
}
>
{
item
.
value
}
</
Option
>
{
))
attrItem
?.
customerAttributeValueList
.
length
>
0
&&
attrItem
.
customerAttributeValueList
.
map
((
item
:
any
)
=>
(
}
<
Option
key=
{
item
.
id
}
value=
{
item
.
id
}
>
{
item
.
value
}
</
Option
>
</
Select
>
))
}
</
Select
>
</
Col
>
<
Col
span=
{
4
}
>
<
Button
type=
"link"
onClick=
{
()
=>
addAtttributeValue
(
attrItem
)
}
>
新增属性值
</
Button
>
</
Col
>
</
Row
>
</
Form
.
Item
>
</
Form
.
Item
>
}
}
{
{
...
@@ -208,21 +256,28 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -208,21 +256,28 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
message
:
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.message'
})
message
:
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.message'
})
}]
}
}]
}
>
>
<
Checkbox
.
Group
<
Row
>
onChange=
{
(
v
)
=>
onChange
(
v
,
attrItem
)
}
<
Col
span=
{
20
}
>
disabled=
{
_isDisabled
}
<
Checkbox
.
Group
style=
{
{
width
:
"100%"
}
}
onChange=
{
(
v
)
=>
onChange
(
v
,
attrItem
)
}
>
disabled=
{
_isDisabled
}
<
Row
>
style=
{
{
width
:
"100%"
}
}
{
>
attrItem
?.
customerAttributeValueList
.
length
>
0
&&
attrItem
.
customerAttributeValueList
.
map
((
item
:
any
,
index
:
string
)
=>
(
<
Row
>
<
Col
span=
{
6
}
key=
{
item
.
id
}
>
{
<
Checkbox
value=
{
item
.
id
}
>
{
item
.
value
}
</
Checkbox
>
attrItem
?.
customerAttributeValueList
.
length
>
0
&&
attrItem
.
customerAttributeValueList
.
map
((
item
:
any
,
index
:
string
)
=>
(
</
Col
>
<
Col
span=
{
6
}
key=
{
item
.
id
}
>
))
<
Checkbox
value=
{
item
.
id
}
>
{
item
.
value
}
</
Checkbox
>
}
</
Col
>
</
Row
>
))
</
Checkbox
.
Group
>
}
</
Row
>
</
Checkbox
.
Group
>
</
Col
>
<
Col
span=
{
4
}
>
<
Button
type=
"link"
onClick=
{
()
=>
addAtttributeValue
(
attrItem
)
}
>
新增属性值
</
Button
>
</
Col
>
</
Row
>
</
Form
.
Item
>
</
Form
.
Item
>
)
)
}
}
...
@@ -264,7 +319,7 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -264,7 +319,7 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
>
>
<
Tabs
defaultActiveKey=
"1"
tabPosition=
"left"
>
<
Tabs
defaultActiveKey=
"1"
tabPosition=
"left"
>
{
{
attributesData
?.
length
>
0
&&
attributesData
.
map
(
attributeItem
=>
dataSource
?.
length
>
0
&&
dataSource
.
map
(
attributeItem
=>
!
productInfoByEdit
?.
isUpdateAttribute
&&
(
attributeItem
?.
createTime
>
productInfoByEdit
?.
createTime
)
?
null
:
<
TabPane
tab=
{
attributeItem
.
name
}
key=
{
attributeItem
.
id
}
>
!
productInfoByEdit
?.
isUpdateAttribute
&&
(
attributeItem
?.
createTime
>
productInfoByEdit
?.
createTime
)
?
null
:
<
TabPane
tab=
{
attributeItem
.
name
}
key=
{
attributeItem
.
id
}
>
{
{
renderTabPanchildren
(
attributeItem
)
renderTabPanchildren
(
attributeItem
)
...
@@ -274,7 +329,44 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
...
@@ -274,7 +329,44 @@ const ProductAttributeForm: React.FC<Iprops> = (props) => {
}
}
</
Tabs
>
</
Tabs
>
</
Form
>
</
Form
>
{
attributesData
?.
length
===
0
&&
<
span
style=
{
{
opacity
:
0.6
}
}
>
{
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.none'
})
}
</
span
>
}
{
dataSource
?.
length
===
0
&&
<
span
style=
{
{
opacity
:
0.6
}
}
>
{
intl
.
formatMessage
({
id
:
'commodity.products.addProductsItem.productAttributeForm.none'
})
}
</
span
>
}
<
Modal
title=
"增加属性值"
visible=
{
addVisible
}
onOk=
{
handleAdd
}
forceRender=
{
true
}
confirmLoading=
{
loading
}
onCancel=
{
handleCancel
}
>
<
Form
{
...
layout
}
form=
{
addForm
}
name=
"add-form"
labelAlign=
"left"
colon=
{
false
}
onFinish=
{
addSubmit
}
>
<
Form
.
Item
name=
'groupName'
label=
'属性组名称'
style=
{
{
display
:
'none'
}
}
>
<
Input
disabled=
{
true
}
/>
</
Form
.
Item
>
<
Form
.
Item
name=
'name'
label=
'属性名称'
>
<
Input
disabled=
{
true
}
/>
</
Form
.
Item
>
<
Form
.
Item
name=
'value'
label=
'属性值名称'
>
<
Input
placeholder=
"请输入属性值"
/>
</
Form
.
Item
>
</
Form
>
</
Modal
>
</>)
</>)
}
}
...
...
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