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

const FormItem = Form.Item;
afc163's avatar
afc163 committed
10
const { Option } = Select;
11
const { RangePicker } = DatePicker;
afc163's avatar
afc163 committed
12
const { TextArea } = Input;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

@connect(state => ({
  submitting: state.form.regularFormSubmitting,
}))
@Form.create()
export default class BasicForms extends PureComponent {
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.props.dispatch({
          type: 'form/submitRegularForm',
          payload: values,
        });
      }
    });
  }
  render() {
    const { submitting } = this.props;
afc163's avatar
afc163 committed
32
    const { getFieldDecorator, getFieldValue } = this.props.form;
33 34 35 36

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
afc163's avatar
afc163 committed
37
        sm: { span: 7 },
38 39 40 41 42 43 44 45 46 47 48
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };

    const submitFormLayout = {
      wrapperCol: {
        xs: { span: 24, offset: 0 },
afc163's avatar
afc163 committed
49
        sm: { span: 10, offset: 7 },
50 51 52 53
      },
    };

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