import React, { Component } from 'react';

import { BrowserRouter as Router, Route, Link } from "react-router-dom";

import { Spin } from 'antd';
import axios from 'axios';
class Otherloginstart extends Component {

	componentDidMount() {
		let query=this.props.location.search;

		if(query!= ""){
			const type = query.split('?code=');
			const types = type[1].split('&state=');
			const typeshref = types[1].split(',');

			let codeurl = `/auth/wechat/callback.json`
			axios.get(codeurl,{params:{
					code:types[0]
				}}).then((result)=> {
				if(result){
					if(result.data.status===0){
						if(result.data.new_user===true){
							window.location.href=`https://${typeshref[1]}/otherlogin?type=wechat`;
						}else{
							// this.getinfo()
							if(typeshref[0]==="account"){
								window.location.href=`https://${typeshref[1]}/account/binding`;
							}else{
								window.location.href=`https://${typeshref[1]}`;
							}

						}
					}
				}
			}).catch((error)=>{

			})
		}


	}

	render() {
		// Loading
		return (
			<div className="App" style={{minHeight: '800px',width:"100%"}}>
				<style>
					{
						`
						 .margintop{
						   margin-top:20%;
						 }
						`
					}
				</style>
				<Spin size="large" className={"margintop"}/>
			</div>
		);
	}
}

export default Otherloginstart;