index.js 8.38 KB
Newer Older
1 2
import React, { PureComponent } from 'react';
import { connect } from 'dva';
3
import { formatMessage, FormattedMessage } from 'umi/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';
18 19

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

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

250
export default PAGE_NAME_UPPER_CAMEL_CASE;