index.tsx 4.52 KB
Newer Older
陈帅's avatar
陈帅 committed
1
import React, { Fragment } from 'react';
WhatAKitty's avatar
WhatAKitty committed
2
import { connect } from 'dva';
3
import { Form, Input, Button, Select, Divider } from 'antd';
4
import styles from './index.less';
陈帅's avatar
陈帅 committed
5 6 7
import { FormComponentProps } from 'antd/lib/form';
import { IStateType } from '../../model';
import { Dispatch } from 'redux';
8

afc163's avatar
afc163 committed
9
const { Option } = Select;
10

WhatAKitty's avatar
WhatAKitty committed
11 12 13 14 15 16 17 18
const formItemLayout = {
  labelCol: {
    span: 5,
  },
  wrapperCol: {
    span: 19,
  },
};
陈帅's avatar
陈帅 committed
19 20
interface Step1Props extends FormComponentProps {
  data?: IStateType['step'];
陈帅's avatar
陈帅 committed
21
  dispatch?: Dispatch<any>;
陈帅's avatar
陈帅 committed
22
}
WhatAKitty's avatar
WhatAKitty committed
23

陈帅's avatar
陈帅 committed
24
class Step1 extends React.PureComponent<Step1Props> {
WhatAKitty's avatar
WhatAKitty committed
25 26
  render() {
    const { form, dispatch, data } = this.props;
陈帅's avatar
陈帅 committed
27 28 29
    if (!data) {
      return;
    }
WhatAKitty's avatar
WhatAKitty committed
30 31 32
    const { getFieldDecorator, validateFields } = form;
    const onValidateForm = () => {
      validateFields((err, values) => {
陈帅's avatar
陈帅 committed
33
        if (!err && dispatch) {
WhatAKitty's avatar
WhatAKitty committed
34
          dispatch({
35
            type: 'BLOCK_NAME_CAMEL_CASE/saveStepFormData',
WhatAKitty's avatar
WhatAKitty committed
36 37
            payload: values,
          });
38 39 40 41
          dispatch({
            type: 'BLOCK_NAME_CAMEL_CASE/saveCurrentStep',
            payload: 'confirm',
          });
WhatAKitty's avatar
WhatAKitty committed
42 43 44 45
        }
      });
    };
    return (
陈帅's avatar
陈帅 committed
46
      <Fragment>
WhatAKitty's avatar
WhatAKitty committed
47
        <Form layout="horizontal" className={styles.stepForm} hideRequiredMark>
jim's avatar
jim committed
48
          <Form.Item {...formItemLayout} label="付款账户">
WhatAKitty's avatar
WhatAKitty committed
49 50 51 52 53 54
            {getFieldDecorator('payAccount', {
              initialValue: data.payAccount,
              rules: [{ required: true, message: '请选择付款账户' }],
            })(
              <Select placeholder="test@example.com">
                <Option value="ant-design@alipay.com">ant-design@alipay.com</Option>
陈帅's avatar
陈帅 committed
55
              </Select>,
WhatAKitty's avatar
WhatAKitty committed
56 57
            )}
          </Form.Item>
jim's avatar
jim committed
58
          <Form.Item {...formItemLayout} label="收款账户">
WhatAKitty's avatar
WhatAKitty committed
59 60 61 62 63 64 65 66 67 68 69
            <Input.Group compact>
              <Select defaultValue="alipay" style={{ width: 100 }}>
                <Option value="alipay">支付宝</Option>
                <Option value="bank">银行账户</Option>
              </Select>
              {getFieldDecorator('receiverAccount', {
                initialValue: data.receiverAccount,
                rules: [
                  { required: true, message: '请输入收款人账户' },
                  { type: 'email', message: '账户名应为邮箱格式' },
                ],
jim's avatar
jim committed
70
              })(<Input style={{ width: 'calc(100% - 100px)' }} placeholder="test@example.com" />)}
WhatAKitty's avatar
WhatAKitty committed
71 72
            </Input.Group>
          </Form.Item>
jim's avatar
jim committed
73
          <Form.Item {...formItemLayout} label="收款人姓名">
WhatAKitty's avatar
WhatAKitty committed
74 75 76
            {getFieldDecorator('receiverName', {
              initialValue: data.receiverName,
              rules: [{ required: true, message: '请输入收款人姓名' }],
jim's avatar
jim committed
77
            })(<Input placeholder="请输入收款人姓名" />)}
WhatAKitty's avatar
WhatAKitty committed
78
          </Form.Item>
jim's avatar
jim committed
79
          <Form.Item {...formItemLayout} label="转账金额">
WhatAKitty's avatar
WhatAKitty committed
80 81
            {getFieldDecorator('amount', {
              initialValue: data.amount,
82
              rules: [
WhatAKitty's avatar
WhatAKitty committed
83
                { required: true, message: '请输入转账金额' },
jim's avatar
jim committed
84 85 86 87
                {
                  pattern: /^(\d+)((?:\.\d+)?)$/,
                  message: '请输入合法金额数字',
                },
88
              ],
jim's avatar
jim committed
89
            })(<Input prefix="¥" placeholder="请输入金额" />)}
WhatAKitty's avatar
WhatAKitty committed
90 91 92 93
          </Form.Item>
          <Form.Item
            wrapperCol={{
              xs: { span: 24, offset: 0 },
jim's avatar
jim committed
94 95 96 97
              sm: {
                span: formItemLayout.wrapperCol.span,
                offset: formItemLayout.labelCol.span,
              },
WhatAKitty's avatar
WhatAKitty committed
98 99 100 101 102 103 104 105 106 107 108 109
            }}
            label=""
          >
            <Button type="primary" onClick={onValidateForm}>
              下一步
            </Button>
          </Form.Item>
        </Form>
        <Divider style={{ margin: '40px 0 24px' }} />
        <div className={styles.desc}>
          <h3>说明</h3>
          <h4>转账到支付宝账户</h4>
jim's avatar
jim committed
110 111 112
          <p>
            如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。
          </p>
WhatAKitty's avatar
WhatAKitty committed
113
          <h4>转账到银行卡</h4>
jim's avatar
jim committed
114 115 116
          <p>
            如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。如果需要,这里可以放一些关于产品的常见问题说明。
          </p>
WhatAKitty's avatar
WhatAKitty committed
117
        </div>
陈帅's avatar
陈帅 committed
118
      </Fragment>
WhatAKitty's avatar
WhatAKitty committed
119 120 121
    );
  }
}
lijiehua's avatar
lijiehua committed
122

陈帅's avatar
陈帅 committed
123 124
export default connect(({ BLOCK_NAME_CAMEL_CASE }: { BLOCK_NAME_CAMEL_CASE: IStateType }) => ({
  data: BLOCK_NAME_CAMEL_CASE.step,
陈帅's avatar
陈帅 committed
125
}))(Form.create<Step1Props>()(Step1));