BasicForm.js 6.27 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 30 31 32 33 34 35 36 37
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.props.dispatch({
          type: 'form/submitRegularForm',
          payload: values,
        });
      }
    });
jim's avatar
jim committed
38
  };
陈帅's avatar
陈帅 committed
39

40 41
  render() {
    const { submitting } = this.props;
afc163's avatar
afc163 committed
42
    const { getFieldDecorator, getFieldValue } = this.props.form;
43 44 45 46

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

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

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