2
2
* @description 教育信息组件
3
3
*/
4
4
5
- import React , { memo } from 'react'
5
+ import React , { Fragment , memo , useState , useCallback } from 'react'
6
6
7
7
import { Form , Input , Select , Button , DatePicker } from 'antd'
8
+ import { MinusCircleOutlined } from '@ant-design/icons'
8
9
import 'moment/locale/zh-cn'
9
10
import locale from 'antd/es/date-picker/locale/zh_CN'
10
11
import moment from 'moment'
@@ -18,7 +19,9 @@ const layout = {
18
19
}
19
20
20
21
const SelfEducation : React . FC = ( ) => {
21
- const finished = ( values : any ) => {
22
+ const [ formCountArr , setFormCountArr ] = useState < string [ ] > ( [ ] )
23
+
24
+ const finished = useCallback ( ( values : any , item : string ) => {
22
25
if ( values . eduTime && values . eduTime . length > 0 ) {
23
26
const startTime = moment ( values . eduTime [ 0 ] ) . format ( 'YYYY-MM' )
24
27
const endTime = moment ( values . eduTime [ 1 ] ) . format ( 'YYYY-MM' )
@@ -28,44 +31,61 @@ const SelfEducation: React.FC = () => {
28
31
eduTime : [ startTime , endTime ] ,
29
32
}
30
33
)
31
- console . log ( values , forMatInfo )
34
+ console . log ( forMatInfo )
32
35
}
33
- }
34
- return (
35
- < div className = { styles [ 'self-education' ] } >
36
- < Form { ...layout } name = "basic" onFinish = { finished } >
37
- < Form . Item label = "学校" name = "school" rules = { [ { required : true , message : '学校不能为空' } ] } >
38
- < Input />
39
- </ Form . Item >
36
+ } , [ ] )
40
37
41
- < Form . Item label = "专业" name = "profession" rules = { [ { required : true , message : '专业不能为空' } ] } >
42
- < Input />
43
- </ Form . Item >
38
+ const addEduForm = useCallback ( ( ) => {
39
+ setFormCountArr ( [ ... formCountArr , ` ${ Math . random ( ) } ${ Date . now ( ) } ` ] )
40
+ } , [ formCountArr ] )
44
41
45
- < Form . Item label = "学历" name = "eduLevel" rules = { [ { required : true , message : '学历不能为空' } ] } >
46
- < Select >
47
- { eduOption . map ( ( item ) => (
48
- < Select . Option value = { item . value } key = { item . id } >
49
- { item . name }
50
- </ Select . Option >
51
- ) ) }
52
- </ Select >
53
- </ Form . Item >
42
+ const delForm = useCallback ( ( index : number ) => {
43
+ setFormCountArr ( formCountArr . filter ( ( item , k ) => k !== index ) )
44
+ } , [ formCountArr ] )
54
45
55
- < Form . Item
56
- name = "eduTime"
57
- label = "在校时间"
58
- rules = { [ { type : 'array' as const , required : true , message : '时间不能为空!' } ] }
59
- >
60
- < DatePicker . RangePicker locale = { locale } picker = "month" />
61
- </ Form . Item >
62
-
63
- < Form . Item >
64
- < Button type = "primary" htmlType = "submit" >
65
- 完成
66
- </ Button >
67
- </ Form . Item >
68
- </ Form >
46
+ return (
47
+ < div className = { styles [ 'self-education' ] } >
48
+ {
49
+ formCountArr . map ( ( item , index , arr ) => (
50
+ < Fragment key = { item } >
51
+ { arr . length > 1 && < MinusCircleOutlined className = { styles [ 'del-btn' ] } onClick = { ( ) => delForm ( index ) } /> }
52
+ < Form { ...layout } name = { item } onFinish = { ( values ) => finished ( values , item ) } >
53
+ < Form . Item label = "学校" name = "school" rules = { [ { required : true , message : '学校不能为空' } ] } >
54
+ < Input />
55
+ </ Form . Item >
56
+
57
+ < Form . Item label = "专业" name = "profession" rules = { [ { required : true , message : '专业不能为空' } ] } >
58
+ < Input />
59
+ </ Form . Item >
60
+
61
+ < Form . Item label = "学历" name = "eduLevel" rules = { [ { required : true , message : '学历不能为空' } ] } >
62
+ < Select >
63
+ { eduOption . map ( ( item ) => (
64
+ < Select . Option value = { item . value } key = { item . id } >
65
+ { item . name }
66
+ </ Select . Option >
67
+ ) ) }
68
+ </ Select >
69
+ </ Form . Item >
70
+
71
+ < Form . Item
72
+ name = "eduTime"
73
+ label = "在校时间"
74
+ rules = { [ { type : 'array' as const , required : true , message : '时间不能为空!' } ] }
75
+ >
76
+ < DatePicker . RangePicker locale = { locale } picker = "month" />
77
+ </ Form . Item >
78
+
79
+ < Form . Item >
80
+ < Button type = "primary" htmlType = "submit" >
81
+ 完成
82
+ </ Button >
83
+ </ Form . Item >
84
+ </ Form >
85
+ </ Fragment >
86
+ ) )
87
+ }
88
+ < Button type = "dashed" block style = { { background : 'transparent' , color : '#e5e5e5' } } onClick = { addEduForm } > 新增</ Button >
69
89
</ div >
70
90
)
71
91
}
0 commit comments