BasicForm.js 6.32 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

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

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

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

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

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

export default BasicForms;