import React from 'react';
import { connect } from 'react-redux';
import { submit } from 'redux-form';
import { Form, Icon, Input, Button, Checkbox } from 'antd';
import cx from 'classnames';
import ReduxFormWrap from '../components/reduxForm/ReduxFormWrap';
import InputField from '../components/reduxForm/InputField';
import { required } from '../components/reduxForm/validate';
import api from '../utils/api';
import './login.less';

class Login extends React.Component {
    static propTypes = {
    }
    constructor(props) {
        super(props);
        this.submitLogin = this.submitLogin.bind(this);
        this.backLogin = this.backLogin.bind(this);
        this.state = {
            key: '1'
        };
    }
    componentDidMount() {
    }
    submitLogin(values) {
        const { dispatch } = this.props;
        api.postLogin(values).then(data => {
            console.log(data);
        })
        console.log("#########:::::::", values);
        // if (values.grant_type == 'password') {    //密码登录
        //     dispatch(login(values));
        // } else if (values.grant_type == 'smscode') {//验证码登录
        //     dispatch(login(values));
        // } else if (values.grant_type == 'change_tenant') {//选择tenant
        //     dispatch(changeTenant(values));
        // }
    }
    backLogin() {
        const { dispatch } = this.props;
        dispatch({
            type: types.UAA_TENANTS,
            payload: {}
        });
    }
    render() {
        const { key } = this.state;
        const { dispatch, uaa_tenants } = this.props;
        return (
            <div className={cx('login_wrap')}>
                <div className={cx('login_form_wrap', 'padding-16')}>
                    <div className={cx('login_form_bgm')}></div>
                    <ReduxFormWrap form="login_password" initialValues={{ grant_type: 'password', scope: 'global_access:tenant_admin', username: '18510929499', password: 'a123456' }} className={'mtop-40'}
                        onSubmit={this.submitLogin}>
                        <InputField width="auto" prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.75)' }} />} placeholder="用户名" name="username" validate={[required]} />
                        <InputField width="auto" prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.75)' }} />} placeholder="密码" name="password" validate={[required]} />
                        <div className={cx('login_form_item')}>
                            <Button type="primary" block onClick={() => {
                                dispatch(submit('login_password'))
                            }}>登录</Button>
                        </div>
                    </ReduxFormWrap>
                </div>
            </div >
        );
    }
}



const mapState = (state) => {
    const {
        router: { location = {} }
    } = state;
    return {
        location
    };
};
export default connect(mapState)(Login);