<template>
	<view class="container">
		<view class="box"></view>
		<view class="ibox">
			<view class="logoBox">
				<image src="/static/img/logo.png" mode=""></image>
				<view>中南设计院教育建筑云平台</view>
			</view>
			<!-- <view class="item">
				<view>
					<image src="/static/img/zh.png" mode=""></image>
					账号
				</view>
				<u--input placeholder="请输入账号" maxlength="11" border="none" inputAlign="right"
					v-model="value"></u--input>
			</view>
			<view class="item">
				<view>
					<image src="/static/img/mm.png" mode=""></image>
					密码
				</view>
				<u--input password placeholder="请输入密码" maxlength="11" border="none" inputAlign="right"
					v-model="value"></u--input>
			</view>
			<view class="btn" @click="submit">
				登录
			</view> -->
			<view class="loading">
				<image src="/static/img/loading.gif" mode=""></image>
				<view>登录中</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getOauthUrl,
		corpLogin
	} from "@/api/index.js"
	export default {
		data() {
			return {
				deviceType: "phone",
			}
		},
		onLoad() {
			this.login()
		},
		methods: {
			submit() {
				uni.$u.route({
					type: "reLaunch",
					url: 'pages/tabbar/resultSquare',
				})
			},
			// 接收地址传参
			getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			},
			login() {
				let codeList = [9000003, 9000006, 9000004, 9000005]
				// let code = location.href.split("?")[1].split("&")[0].split("=")[1];
				let code=this.getQueryString('code');
				let state=this.getQueryString('state');
				corpLogin({
					code: code
				}).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('TOKEN', res.data.token);
						if(state=='phone'){
							uni.reLaunch({
								url: '/pages/tabbar/resultSquare'
							});
						}else{
							// location.href='http://frp.songlanyun.com:8801/web/#/index'
							location.href='http://csadi.songlanyun.com/index'
							
						}
					} else if (codeList.indexOf(res.code) != -1) {
						uni.$u.toast(res.msg);
						setTimeout(()=>{
							if(state=='phone'){
								uni.reLaunch({
									url: '/pages/login?loginType=account'
								});
							}else{
								// location.href='http://frp.songlanyun.com:8801/web/#/index'
								location.href='http://csadi.songlanyun.com/index'
							}
							// http://frp.songlanyun.com:8801/web/#/index
						},3000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: url('../static/img/loginBg.png');
		background-size: contain;
		position: relative;

		.box {
			width: 740rpx;
			height: 1600rpx;
			background-color: #fff;
			transform: rotateZ(75deg);
			margin: auto;
		}

		.ibox {
			width: 100vw;
			position: absolute;
			top: 530rpx;
			left: 0;
			text-align: center;

			.logoBox {
				margin: 0 auto 40rpx;

				image {
					width: 172rpx;
					height: 70rpx;
					margin-bottom: 5rpx;
				}

				>view {
					font-size: 36rpx;
					color: #E83A27;
					font-weight: 700;
					letter-spacing: 3rpx;
				}
			}

			.item {
				width: 600rpx;
				margin: auto;
				display: flex;
				align-items: center;
				font-size: 28rpx;
				padding: 30rpx 0;
				border-bottom: 1rpx solid rgba(204, 204, 204, 0.6);

				image {
					width: 30rpx;
					height: 30rpx;
					vertical-align: middle;
					margin-right: 5px;
				}
			}

			.btn {
				width: 630rpx;
				height: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin: 55rpx auto;
				background: #e83a27;
				border-radius: 40rpx;
				box-shadow: 0rpx 10rpx 22rpx 0rpx rgba(232, 58, 39, 0.22);
				color: #fff;
			}
		}
	}

	.loading {
		// color: #e83a27;;
		font-size: 28rpx;

		image {
			width: 300rpx;
			height: 300rpx;
		}
	}
</style>