BasicForm.js
6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import {
Form, Input, DatePicker, Select, Button, Card, InputNumber, Radio, Icon, Tooltip,
} from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import styles from './style.less';
const FormItem = Form.Item;
const { Option } = Select;
const { RangePicker } = DatePicker;
const { TextArea } = Input;
@connect(({ loading }) => ({
submitting: loading.effects['form/submitRegularForm'],
}))
@Form.create()
export default class BasicForms extends PureComponent {
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.props.dispatch({
type: 'form/submitRegularForm',
payload: values,
});
}
});
}
render() {
const { submitting } = this.props;
const { getFieldDecorator, getFieldValue } = this.props.form;
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 7 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 12 },
md: { span: 10 },
},
};
const submitFormLayout = {
wrapperCol: {
xs: { span: 24, offset: 0 },
sm: { span: 10, offset: 7 },
},
};
return (
<PageHeaderLayout title="基础表单" content="表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。">
<Card bordered={false}>
<Form
onSubmit={this.handleSubmit}
hideRequiredMark
style={{ marginTop: 8 }}
>
<FormItem
{...formItemLayout}
label="标题"
>
{getFieldDecorator('title', {
rules: [{
required: true, message: '请输入标题',
}],
})(
<Input placeholder="给目标起个名字" />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="起止日期"
>
{getFieldDecorator('date', {
rules: [{
required: true, message: '请选择起止日期',
}],
})(
<RangePicker style={{ width: '100%' }} placeholder={['开始日期', '结束日期']} />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="目标描述"
>
{getFieldDecorator('goal', {
rules: [{
required: true, message: '请输入目标描述',
}],
})(
<TextArea style={{ minHeight: 32 }} placeholder="请输入你的阶段性工作目标" rows={4} />
)}
</FormItem>
<FormItem
{...formItemLayout}
label="衡量标准"
>
{getFieldDecorator('standard', {
rules: [{
required: true, message: '请输入衡量标准',
}],
})(
<TextArea style={{ minHeight: 32 }} placeholder="请输入衡量标准" rows={4} />
)}
</FormItem>
<FormItem
{...formItemLayout}
label={
<span>
客户
<em className={styles.optional}>
(选填)
<Tooltip title="目标的服务对象">
<Icon type="info-circle-o" style={{ marginRight: 4 }} />
</Tooltip>
</em>
</span>
}
>
{getFieldDecorator('client')(
<Input placeholder="请描述你服务的客户,内部客户直接 @姓名/工号" />
)}
</FormItem>
<FormItem
{...formItemLayout}
label={<span>邀评人<em className={styles.optional}>(选填)</em></span>}
>
{getFieldDecorator('invites')(
<Input placeholder="请直接 @姓名/工号,最多可邀请 5 人" />
)}
</FormItem>
<FormItem
{...formItemLayout}
label={<span>权重<em className={styles.optional}>(选填)</em></span>}
>
{getFieldDecorator('weight')(
<InputNumber placeholder="请输入" min={0} max={100} />
)}
<span>%</span>
</FormItem>
<FormItem
{...formItemLayout}
label="目标公开"
help="客户、邀评人默认被分享"
>
<div>
{getFieldDecorator('public', {
initialValue: '1',
})(
<Radio.Group>
<Radio value="1">公开</Radio>
<Radio value="2">部分公开</Radio>
<Radio value="3">不公开</Radio>
</Radio.Group>
)}
<FormItem style={{ marginBottom: 0 }}>
{getFieldDecorator('publicUsers')(
<Select
mode="multiple"
placeholder="公开给"
style={{
margin: '8px 0',
display: getFieldValue('public') === '2' ? 'block' : 'none',
}}
>
<Option value="1">同事甲</Option>
<Option value="2">同事乙</Option>
<Option value="3">同事丙</Option>
</Select>
)}
</FormItem>
</div>
</FormItem>
<FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
<Button type="primary" htmlType="submit" loading={submitting}>
提交
</Button>
<Button style={{ marginLeft: 8 }}>保存</Button>
</FormItem>
</Form>
</Card>
</PageHeaderLayout>
);
}
}