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