index.tsx 8.72 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { Component } from 'react';
2
import { connect } from 'dva';
陈帅's avatar
陈帅 committed
3
import { formatMessage, FormattedMessage } from 'umi-plugin-react/locale';
afc163's avatar
afc163 committed
4
import {
jim's avatar
jim committed
5 6 7 8 9 10 11 12 13 14
  Form,
  Input,
  DatePicker,
  Select,
  Button,
  Card,
  InputNumber,
  Radio,
  Icon,
  Tooltip,
afc163's avatar
afc163 committed
15
} from 'antd';
16
import PageHeaderWrapper from './components/PageHeaderWrapper';
afc163's avatar
afc163 committed
17
import styles from './style.less';
陈帅's avatar
陈帅 committed
18 19
import { FormComponentProps } from 'antd/lib/form';
import { Dispatch } from 'redux';
20 21

const FormItem = Form.Item;
afc163's avatar
afc163 committed
22
const { Option } = Select;
23
const { RangePicker } = DatePicker;
afc163's avatar
afc163 committed
24
const { TextArea } = Input;
25

陈帅's avatar
陈帅 committed
26 27 28 29 30 31
interface PAGE_NAME_UPPER_CAMEL_CASEProps extends FormComponentProps {
  submitting: boolean;
  dispatch: Dispatch;
}

@connect(({ loading }: { loading: { effects: { [key: string]: boolean } } }) => ({
32
  submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submitRegularForm'],
33
}))
陈帅's avatar
陈帅 committed
34 35
class PAGE_NAME_UPPER_CAMEL_CASE extends Component<PAGE_NAME_UPPER_CAMEL_CASEProps> {
  handleSubmit = (e: React.FormEvent) => {
陈帅's avatar
陈帅 committed
36
    const { dispatch, form } = this.props;
37
    e.preventDefault();
陈帅's avatar
陈帅 committed
38
    form.validateFieldsAndScroll((err, values) => {
39
      if (!err) {
陈帅's avatar
陈帅 committed
40
        dispatch({
41
          type: 'BLOCK_NAME_CAMEL_CASE/submitRegularForm',
42 43 44 45
          payload: values,
        });
      }
    });
jim's avatar
jim committed
46
  };
陈帅's avatar
陈帅 committed
47

48 49
  render() {
    const { submitting } = this.props;
陈帅's avatar
陈帅 committed
50 51 52
    const {
      form: { getFieldDecorator, getFieldValue },
    } = this.props;
53 54 55 56

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
afc163's avatar
afc163 committed
57
        sm: { span: 7 },
58 59 60 61 62 63 64 65 66 67 68
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };

    const submitFormLayout = {
      wrapperCol: {
        xs: { span: 24, offset: 0 },
afc163's avatar
afc163 committed
69
        sm: { span: 10, offset: 7 },
70 71 72 73
      },
    };

    return (
74
      <PageHeaderWrapper
75 76
        title={<FormattedMessage id="BLOCK_NAME.basic.title" />}
        content={<FormattedMessage id="BLOCK_NAME.basic.description" />}
jim's avatar
jim committed
77
      >
78
        <Card bordered={false}>
jim's avatar
jim committed
79
          <Form onSubmit={this.handleSubmit} hideRequiredMark style={{ marginTop: 8 }}>
80
            <FormItem {...formItemLayout} label={<FormattedMessage id="BLOCK_NAME.title.label" />}>
afc163's avatar
afc163 committed
81
              {getFieldDecorator('title', {
jim's avatar
jim committed
82 83 84
                rules: [
                  {
                    required: true,
85
                    message: formatMessage({ id: 'BLOCK_NAME.title.required' }),
jim's avatar
jim committed
86 87
                  },
                ],
88
              })(<Input placeholder={formatMessage({ id: 'BLOCK_NAME.title.placeholder' })} />)}
89
            </FormItem>
90
            <FormItem {...formItemLayout} label={<FormattedMessage id="BLOCK_NAME.date.label" />}>
afc163's avatar
afc163 committed
91
              {getFieldDecorator('date', {
jim's avatar
jim committed
92 93 94
                rules: [
                  {
                    required: true,
95
                    message: formatMessage({ id: 'BLOCK_NAME.date.required' }),
jim's avatar
jim committed
96 97
                  },
                ],
98 99 100 101
              })(
                <RangePicker
                  style={{ width: '100%' }}
                  placeholder={[
102 103
                    formatMessage({ id: 'BLOCK_NAME.placeholder.start' }),
                    formatMessage({ id: 'BLOCK_NAME.placeholder.end' }),
104 105 106
                  ]}
                />
              )}
107
            </FormItem>
108
            <FormItem {...formItemLayout} label={<FormattedMessage id="BLOCK_NAME.goal.label" />}>
afc163's avatar
afc163 committed
109
              {getFieldDecorator('goal', {
jim's avatar
jim committed
110 111 112
                rules: [
                  {
                    required: true,
113
                    message: formatMessage({ id: 'BLOCK_NAME.goal.required' }),
jim's avatar
jim committed
114 115
                  },
                ],
116
              })(
jim's avatar
jim committed
117 118
                <TextArea
                  style={{ minHeight: 32 }}
119
                  placeholder={formatMessage({ id: 'BLOCK_NAME.goal.placeholder' })}
jim's avatar
jim committed
120 121
                  rows={4}
                />
122 123
              )}
            </FormItem>
xiaohuoni's avatar
xiaohuoni committed
124 125 126 127
            <FormItem
              {...formItemLayout}
              label={<FormattedMessage id="BLOCK_NAME.standard.label" />}
            >
afc163's avatar
afc163 committed
128
              {getFieldDecorator('standard', {
jim's avatar
jim committed
129 130 131
                rules: [
                  {
                    required: true,
132
                    message: formatMessage({ id: 'BLOCK_NAME.standard.required' }),
jim's avatar
jim committed
133 134
                  },
                ],
135 136 137
              })(
                <TextArea
                  style={{ minHeight: 32 }}
138
                  placeholder={formatMessage({ id: 'BLOCK_NAME.standard.placeholder' })}
139 140 141
                  rows={4}
                />
              )}
142 143 144
            </FormItem>
            <FormItem
              {...formItemLayout}
afc163's avatar
afc163 committed
145 146
              label={
                <span>
147
                  <FormattedMessage id="BLOCK_NAME.client.label" />
afc163's avatar
afc163 committed
148
                  <em className={styles.optional}>
149 150
                    <FormattedMessage id="BLOCK_NAME.form.optional" />
                    <Tooltip title={<FormattedMessage id="BLOCK_NAME.label.tooltip" />}>
afc163's avatar
afc163 committed
151 152 153 154 155
                      <Icon type="info-circle-o" style={{ marginRight: 4 }} />
                    </Tooltip>
                  </em>
                </span>
              }
156
            >
afc163's avatar
afc163 committed
157
              {getFieldDecorator('client')(
158
                <Input placeholder={formatMessage({ id: 'BLOCK_NAME.client.placeholder' })} />
159 160 161 162
              )}
            </FormItem>
            <FormItem
              {...formItemLayout}
jim's avatar
jim committed
163 164
              label={
                <span>
165
                  <FormattedMessage id="BLOCK_NAME.invites.label" />
166
                  <em className={styles.optional}>
167
                    <FormattedMessage id="BLOCK_NAME.form.optional" />
168
                  </em>
jim's avatar
jim committed
169 170
                </span>
              }
171
            >
afc163's avatar
afc163 committed
172
              {getFieldDecorator('invites')(
173
                <Input placeholder={formatMessage({ id: 'BLOCK_NAME.invites.placeholder' })} />
174 175
              )}
            </FormItem>
afc163's avatar
afc163 committed
176 177
            <FormItem
              {...formItemLayout}
jim's avatar
jim committed
178 179
              label={
                <span>
180
                  <FormattedMessage id="BLOCK_NAME.weight.label" />
181
                  <em className={styles.optional}>
182
                    <FormattedMessage id="BLOCK_NAME.form.optional" />
183
                  </em>
jim's avatar
jim committed
184 185
                </span>
              }
afc163's avatar
afc163 committed
186
            >
187 188
              {getFieldDecorator('weight')(
                <InputNumber
189
                  placeholder={formatMessage({ id: 'BLOCK_NAME.weight.placeholder' })}
190 191 192 193
                  min={0}
                  max={100}
                />
              )}
afc163's avatar
afc163 committed
194
              <span className="ant-form-text">%</span>
afc163's avatar
afc163 committed
195
            </FormItem>
196 197
            <FormItem
              {...formItemLayout}
198 199
              label={<FormattedMessage id="BLOCK_NAME.public.label" />}
              help={<FormattedMessage id="BLOCK_NAME.label.help" />}
200
            >
afc163's avatar
afc163 committed
201 202 203 204
              <div>
                {getFieldDecorator('public', {
                  initialValue: '1',
                })(
afc163's avatar
afc163 committed
205
                  <Radio.Group>
206
                    <Radio value="1">
207
                      <FormattedMessage id="BLOCK_NAME.radio.public" />
208 209
                    </Radio>
                    <Radio value="2">
210
                      <FormattedMessage id="BLOCK_NAME.radio.partially-public" />
211 212
                    </Radio>
                    <Radio value="3">
213
                      <FormattedMessage id="BLOCK_NAME.radio.private" />
214
                    </Radio>
afc163's avatar
afc163 committed
215 216
                  </Radio.Group>
                )}
afc163's avatar
afc163 committed
217 218 219 220
                <FormItem style={{ marginBottom: 0 }}>
                  {getFieldDecorator('publicUsers')(
                    <Select
                      mode="multiple"
221
                      placeholder={formatMessage({ id: 'BLOCK_NAME.publicUsers.placeholder' })}
afc163's avatar
afc163 committed
222 223 224 225 226
                      style={{
                        margin: '8px 0',
                        display: getFieldValue('public') === '2' ? 'block' : 'none',
                      }}
                    >
227
                      <Option value="1">
228
                        <FormattedMessage id="BLOCK_NAME.option.A" />
229 230
                      </Option>
                      <Option value="2">
231
                        <FormattedMessage id="BLOCK_NAME.option.B" />
232 233
                      </Option>
                      <Option value="3">
234
                        <FormattedMessage id="BLOCK_NAME.option.C" />
235
                      </Option>
afc163's avatar
afc163 committed
236 237
                    </Select>
                  )}
238
                </FormItem>
afc163's avatar
afc163 committed
239 240
              </div>
            </FormItem>
afc163's avatar
afc163 committed
241
            <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
242
              <Button type="primary" htmlType="submit" loading={submitting}>
243
                <FormattedMessage id="BLOCK_NAME.form.submit" />
244 245
              </Button>
              <Button style={{ marginLeft: 8 }}>
246
                <FormattedMessage id="BLOCK_NAME.form.save" />
247 248 249 250
              </Button>
            </FormItem>
          </Form>
        </Card>
251
      </PageHeaderWrapper>
252 253 254
    );
  }
}
lijiehua's avatar
lijiehua committed
255

陈帅's avatar
陈帅 committed
256
export default Form.create<PAGE_NAME_UPPER_CAMEL_CASEProps>()(PAGE_NAME_UPPER_CAMEL_CASE);