BasicForm.js 6.31 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 PageHeaderWrapper from '@/components/PageHeaderWrapper';
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

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

42 43
  render() {
    const { submitting } = this.props;
陈帅's avatar
陈帅 committed
44 45 46
    const {
      form: { getFieldDecorator, getFieldValue },
    } = this.props;
47 48 49 50

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

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

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