index.tsx 3.5 KB
Newer Older
1
import React from 'react';
WhatAKitty's avatar
WhatAKitty committed
2
import { connect } from 'dva';
陈帅's avatar
陈帅 committed
3
import { Form, Input, Button, Alert, Divider, Statistic } 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

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

陈帅's avatar
陈帅 committed
23
class Step2 extends React.Component<Step2Props> {
WhatAKitty's avatar
WhatAKitty committed
24 25
  render() {
    const { form, data, dispatch, submitting } = this.props;
陈帅's avatar
陈帅 committed
26 27 28
    if (!data) {
      return;
    }
WhatAKitty's avatar
WhatAKitty committed
29 30
    const { getFieldDecorator, validateFields } = form;
    const onPrev = () => {
陈帅's avatar
陈帅 committed
31
      if (dispatch) {
陈帅's avatar
陈帅 committed
32 33 34 35
        dispatch({
          type: 'BLOCK_NAME_CAMEL_CASE/saveCurrentStep',
          payload: 'info',
        });
陈帅's avatar
陈帅 committed
36
      }
WhatAKitty's avatar
WhatAKitty committed
37
    };
陈帅's avatar
陈帅 committed
38
    const onValidateForm = (e: React.FormEvent) => {
WhatAKitty's avatar
WhatAKitty committed
39 40 41
      e.preventDefault();
      validateFields((err, values) => {
        if (!err) {
陈帅's avatar
陈帅 committed
42
          if (dispatch) {
陈帅's avatar
陈帅 committed
43 44 45 46 47 48 49
            dispatch({
              type: 'BLOCK_NAME_CAMEL_CASE/submitStepForm',
              payload: {
                ...data,
                ...values,
              },
            });
陈帅's avatar
陈帅 committed
50
          }
WhatAKitty's avatar
WhatAKitty committed
51 52 53 54 55 56 57 58 59 60 61
        }
      });
    };
    return (
      <Form layout="horizontal" className={styles.stepForm}>
        <Alert
          closable
          showIcon
          message="确认转账后,资金将直接打入对方账户,无法退回。"
          style={{ marginBottom: 24 }}
        />
jim's avatar
jim committed
62
        <Form.Item {...formItemLayout} className={styles.stepFormText} label="付款账户">
WhatAKitty's avatar
WhatAKitty committed
63 64
          {data.payAccount}
        </Form.Item>
jim's avatar
jim committed
65
        <Form.Item {...formItemLayout} className={styles.stepFormText} label="收款账户">
WhatAKitty's avatar
WhatAKitty committed
66 67
          {data.receiverAccount}
        </Form.Item>
jim's avatar
jim committed
68
        <Form.Item {...formItemLayout} className={styles.stepFormText} label="收款人姓名">
WhatAKitty's avatar
WhatAKitty committed
69 70
          {data.receiverName}
        </Form.Item>
jim's avatar
jim committed
71
        <Form.Item {...formItemLayout} className={styles.stepFormText} label="转账金额">
WhatAKitty's avatar
WhatAKitty committed
72 73 74
          <span className={styles.money}>{data.amount}</span>
        </Form.Item>
        <Divider style={{ margin: '24px 0' }} />
jim's avatar
jim committed
75
        <Form.Item {...formItemLayout} label="支付密码" required={false}>
WhatAKitty's avatar
WhatAKitty committed
76 77
          {getFieldDecorator('password', {
            initialValue: '123456',
jim's avatar
jim committed
78 79 80 81 82 83 84
            rules: [
              {
                required: true,
                message: '需要支付密码才能进行支付',
              },
            ],
          })(<Input type="password" autoComplete="off" style={{ width: '80%' }} />)}
WhatAKitty's avatar
WhatAKitty committed
85 86 87 88 89
        </Form.Item>
        <Form.Item
          style={{ marginBottom: 8 }}
          wrapperCol={{
            xs: { span: 24, offset: 0 },
jim's avatar
jim committed
90 91 92 93
            sm: {
              span: formItemLayout.wrapperCol.span,
              offset: formItemLayout.labelCol.span,
            },
WhatAKitty's avatar
WhatAKitty committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107
          }}
          label=""
        >
          <Button type="primary" onClick={onValidateForm} loading={submitting}>
            提交
          </Button>
          <Button onClick={onPrev} style={{ marginLeft: 8 }}>
            上一步
          </Button>
        </Form.Item>
      </Form>
    );
  }
}
陈帅's avatar
陈帅 committed
108 109 110 111 112 113 114 115 116 117 118 119
export default connect(
  ({
    BLOCK_NAME_CAMEL_CASE,
    loading,
  }: {
    BLOCK_NAME_CAMEL_CASE: IStateType;
    loading: {
      effects: { [key: string]: boolean };
    };
  }) => ({
    submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submitStepForm'],
    data: BLOCK_NAME_CAMEL_CASE.step,
陈帅's avatar
陈帅 committed
120
  }),
陈帅's avatar
陈帅 committed
121
)(Form.create<Step2Props>()(Step2));