index.tsx 8.65 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
interface PAGE_NAME_UPPER_CAMEL_CASEProps extends FormComponentProps {
  submitting: boolean;
陈帅's avatar
陈帅 committed
28
  dispatch: Dispatch<any>;
陈帅's avatar
陈帅 committed
29 30 31
}

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

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