import React, { Component } from 'react';
import { browserHistory } from 'amos-react-router';
import { Login } from 'amos-security/lib';
import { normalPolicy } from './../../utils/pwdPolicy';
import { devLogoIn } from './../../services/securityServices';
import * as endConf from 'amos-processor/lib/config/endconf';

const AmosConfig = endConf.AmosConfig;
const  businessFirstPage = AmosConfig.sysConf.businessFirstPage;

class LoginComponent extends Component {
  constructor(props) {
    super(props);
  }

  goto() {
    browserHistory.push('mapmain');
    // window.open('/main/onDutyDynamic');
    window.open(businessFirstPage);
    let dev_userName = document.getElementById('userName').value;
    let dev_password = document.getElementById('password').value;
    let result = normalPolicy(dev_password);
    window.userMsg = {
      userName: dev_userName,
      userPwd: result
    };
    let params = {
      userName: dev_userName,
      password: result.password,
      secretKey: result.secretKey,
      loginType: 'WEB'
    };
    devLogoIn(params).then((data)=>{
      let dev_token = data['X-Access-Token'];
      // console.log(data);
      window.localStorage.setItem('dev_token', dev_token);
    },(err) => {
      console.log(err);
    });
  }
  render() {
    return <Login goto={this.goto} logo="/src/assets/auth/logo.png" title="实战指挥平台" desicOne="对党忠诚  纪律严明" desictTow="赴汤蹈火  竭诚为民" />;
  }
}

LoginComponent.propTypes = {};

export default LoginComponent;
