import React, { Component } from 'react';
import { connect } from "react-redux";
import './login.css'
import api from './../../utils/api'
const mapStateToProps = (state) => ({
  
});

const mapDispatchToProps = (dispatch) => ({

});

class LoginViews extends Component {
    /*
    * 构造函数
    *
    * */
    constructor() {
        super();
        this.state = {
            code:""

        };
    }
    bindCode(e){

        this.setState({code:e.target.value})

    }
    login(e){
        api.loginGzhcode({
            authorizationCode:this.state.code
        }).then(res=>{
            console.log(res)
        })

    }




    /*
    *
    * 生命周期一
    *
    * */
    componentWillMount() {
        /*
        *
        * 如果是ios设备默认第一次不是播放状态，android没事
        *
        * */
        

        /*
        *
        *  请求数据
        *
        *
        * */
       
    }



    /*
    *
    * 生命周期二
    *
    * */
    componentDidMount() {
        console.log(new URLSearchParams(window.location.search))
        this.setState({
            code:new URLSearchParams(window.location.search).get('code')||""
        })
     
    }

    /*
    * 渲染
    * */
    render() {
        return (
            <div className="container">
                <input value={this.state.code} onInput={this.bindCode.bind(this)} />
                <button onClick={this.login.bind(this)}>请求登陆接口</button>
            </div>

        )
    }

    componentWillUnmount() {

    }
}

export default connect(mapStateToProps, mapDispatchToProps)(LoginViews);