BasicForm.js 6.29 KB
Newer Older
1 2
import React, { PureComponent } from 'react';
import { connect } from 'dva';
afc163's avatar
afc163 committed
3
import {
jim's avatar
jim committed
4 5 6 7 8 9 10 11 12 13
  Form,
  Input,
  DatePicker,
  Select,
  Button,
  Card,
  InputNumber,
  Radio,
  Icon,
  Tooltip,
afc163's avatar
afc163 committed
14
} from 'antd';
15
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
afc163's avatar
afc163 committed
16
import styles from './style.less';
17 18

const FormItem = Form.Item;
afc163's avatar
afc163 committed
19
const { Option } = Select;
20
const { RangePicker } = DatePicker;
afc163's avatar
afc163 committed
21
const { TextArea } = Input;
22

Andreas Cederström's avatar
Andreas Cederström committed
23 24
@connect(({ loading }) => ({
  submitting: loading.effects['form/submitRegularForm'],
25 26 27
}))
@Form.create()
export default class BasicForms extends PureComponent {
jim's avatar
jim committed
28
  handleSubmit = e => {
29
    e.preventDefault();
30 31
    const { form, dispatch } = this.props;
    form.validateFieldsAndScroll((err, values) => {
32
      if (!err) {
33
        dispatch({
34 35 36 37 38
          type: 'form/submitRegularForm',
          payload: values,
        });
      }
    });
jim's avatar
jim committed
39
  };
陈帅's avatar
陈帅 committed
40

41
  render() {
42 43
    const { submitting, form } = this.props;
    const { getFieldDecorator, getFieldValue } = form;
44 45 46 47

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
afc163's avatar
afc163 committed
48
        sm: { span: 7 },
49 50 51 52 53 54 55 56 57 58 59
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };

    const submitFormLayout = {
      wrapperCol: {
        xs: { span: 24, offset: 0 },
afc163's avatar
afc163 committed
60
        sm: { span: 10, offset: 7 },
61 62 63 64
      },
    };

    return (
jim's avatar
jim committed
65 66 67 68
      <PageHeaderLayout
        title="基础表单"
        content="表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。"
      >
69
        <Card bordered={false}>
jim's avatar
jim committed
70 71
          <Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
            <FormItem {...formItemLayout} label="标题">
afc163's avatar
afc163 committed
72
              {getFieldDecorator('title', {
jim's avatar
jim committed
73 74 75 76 77 78 79
                rules: [
                  {
                    required: true,
                    message: '请输入标题',
                  },
                ],
              })(<Input placeholder="给目标起个名字" />)}
80
            </FormItem>
jim's avatar
jim committed
81
            <FormItem {...formItemLayout} label="起止日期">
afc163's avatar
afc163 committed
82
              {getFieldDecorator('date', {
jim's avatar
jim committed
83 84 85 86 87 88 89
                rules: [
                  {
                    required: true,
                    message: '请选择起止日期',
                  },
                ],
              })(<RangePicker style={{ width: '100%' }} placeholder={['开始日期', '结束日期']} />)}
90
            </FormItem>
jim's avatar
jim committed
91
            <FormItem {...formItemLayout} label="目标描述">
afc163's avatar
afc163 committed
92
              {getFieldDecorator('goal', {
jim's avatar
jim committed
93 94 95 96 97 98
                rules: [
                  {
                    required: true,
                    message: '请输入目标描述',
                  },
                ],
99
              })(
jim's avatar
jim committed
100 101 102 103 104
                <TextArea
                  style={{ minHeight: 32 }}
                  placeholder="请输入你的阶段性工作目标"
                  rows={4}
                />
105 106
              )}
            </FormItem>
jim's avatar
jim committed
107
            <FormItem {...formItemLayout} label="衡量标准">
afc163's avatar
afc163 committed
108
              {getFieldDecorator('standard', {
jim's avatar
jim committed
109 110 111 112 113 114 115
                rules: [
                  {
                    required: true,
                    message: '请输入衡量标准',
                  },
                ],
              })(<TextArea style={{ minHeight: 32 }} placeholder="请输入衡量标准" rows={4} />)}
116 117 118
            </FormItem>
            <FormItem
              {...formItemLayout}
afc163's avatar
afc163 committed
119 120 121 122 123 124 125 126 127 128 129
              label={
                <span>
                  客户
                  <em className={styles.optional}>
                    选填
                    <Tooltip title="目标的服务对象">
                      <Icon type="info-circle-o" style={{ marginRight: 4 }} />
                    </Tooltip>
                  </em>
                </span>
              }
130
            >
afc163's avatar
afc163 committed
131 132
              {getFieldDecorator('client')(
                <Input placeholder="请描述你服务的客户,内部客户直接 @姓名/工号" />
133 134 135 136
              )}
            </FormItem>
            <FormItem
              {...formItemLayout}
jim's avatar
jim committed
137 138
              label={
                <span>
陈帅's avatar
陈帅 committed
139 140
                  邀评人
                  <em className={styles.optional}>选填</em>
jim's avatar
jim committed
141 142
                </span>
              }
143
            >
afc163's avatar
afc163 committed
144 145
              {getFieldDecorator('invites')(
                <Input placeholder="请直接 @姓名/工号,最多可邀请 5 人" />
146 147
              )}
            </FormItem>
afc163's avatar
afc163 committed
148 149
            <FormItem
              {...formItemLayout}
jim's avatar
jim committed
150 151
              label={
                <span>
陈帅's avatar
陈帅 committed
152 153
                  权重
                  <em className={styles.optional}>选填</em>
jim's avatar
jim committed
154 155
                </span>
              }
afc163's avatar
afc163 committed
156
            >
jim's avatar
jim committed
157
              {getFieldDecorator('weight')(<InputNumber placeholder="请输入" min={0} max={100} />)}
afc163's avatar
afc163 committed
158
              <span className="ant-form-text">%</span>
afc163's avatar
afc163 committed
159
            </FormItem>
jim's avatar
jim committed
160
            <FormItem {...formItemLayout} label="目标公开" help="客户、邀评人默认被分享">
afc163's avatar
afc163 committed
161 162 163 164
              <div>
                {getFieldDecorator('public', {
                  initialValue: '1',
                })(
afc163's avatar
afc163 committed
165
                  <Radio.Group>
afc163's avatar
afc163 committed
166 167 168 169 170
                    <Radio value="1">公开</Radio>
                    <Radio value="2">部分公开</Radio>
                    <Radio value="3">不公开</Radio>
                  </Radio.Group>
                )}
afc163's avatar
afc163 committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
                <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>
                  )}
186
                </FormItem>
afc163's avatar
afc163 committed
187 188
              </div>
            </FormItem>
afc163's avatar
afc163 committed
189
            <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
190
              <Button type="primary" htmlType="submit" loading={submitting}>
afc163's avatar
afc163 committed
191
                提交
192
              </Button>
afc163's avatar
afc163 committed
193
              <Button style={{ marginLeft: 8 }}>保存</Button>
194 195 196 197 198 199 200
            </FormItem>
          </Form>
        </Card>
      </PageHeaderLayout>
    );
  }
}