<template>
	<div class="GetWxCode">
		<van-loading color="#1989fa" >加载中...</van-loading>
	</div>
</template>

<script setup>
	import {
		ref,
		onMounted 
	} from 'vue';
	import { useRoute,useRouter  } from "vue-router"
	import {
		wxGetOpenid
	} from "@/api/api.js";
	import { showToast } from 'vant';
	const router = useRouter();
	const route = useRoute()
	const code = route.params.code  //获取到的微信code
	//const code = routeParams.value.code
	console.log(code)
	const GetOpenid =()=>{   //拿code 换取openid
		wxGetOpenid({code:code}).then(res=>{
			if(res.status=='ok'){
				sessionStorage.setItem('token', res.token);
				sessionStorage.setItem('refreshToken', res.refresh_token);
				var token = sessionStorage.getItem('token');
				let loginType=sessionStorage.getItem('loginType');//登录状态 空为正常登录 report为查看报告
				console.log(loginType)
				if (token == res.token){
					if(loginType=='report'){
						 router.replace('/ShowReport')
						 return false
					}
					if(res.isRegister){
						//跳转到选择机构
					//	window.location.href="./#/selectOrganization"
						 router.replace('/selectOrganization')
					}else{
						//跳转到注册
						//window.location.href="./#/register"
						 router.replace('/register')
					}
				}else{
					showToast('查询存储信息失败');
				}
			}else{
				showToast(res.msg);
			}
		})
	}
	onMounted(()=>{
		GetOpenid()
	})
</script>

<style scoped>
	.GetWxCode{
		display: flex;
		align-items: center;
		justify-content: center ;
		height: 100vh;
	}
</style>