BasicForm.js 6.21 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
  };
39 40
  render() {
    const { submitting } = this.props;
afc163's avatar
afc163 committed
41
    const { getFieldDecorator, getFieldValue } = this.props.form;
42 43 44 45

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

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

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