<template>
	<div class="LoginMain" v-if="logintype !='ewm'">
		<div class="info">
			<div class="tip">查询体检信息</div>
			<div class="label">身份证</div>
			<div>
				<van-field v-model="info.sfz" placeholder="请输入用户名" />
			</div>
			 
			<div class="label">电话</div>
			<div>
				<van-field v-model="info.tel" placeholder="请输入用户名" />
			</div>
		 
			<van-button type="primary" class="button" round   @click="SearchInfo()">查询</van-button>
		</div>
		 
	</div>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		useRoute,
		useRouter
	} from "vue-router"
	import { H5GetPersonReportDetail} from "@/api/api.js";
		import { showToast } from 'vant';
	const route = useRoute()
	const router = useRouter();
	const login = () => {
		loading.value=true
		window.location.replace(import.meta.env.VITE_APP_WXCODE_URL)
	}
	let loading=ref(false)
	let info=ref({
		sfz:'',
		tel:''
	})
	let buttonText=ref('开始预约')
	const SearchInfo=(tijian_num=null,jigou_code=null)=>{
		if(tijian_num !=null && tijian_num!=undefined){
			info.value={
				tj_num:tijian_num,
				jigou_code:jigou_code
			}
		}else{
			if(info.value.sfz=='' || info.value.tel==''){
				showToast('请输入身份证和手机号码');
				return false
			}
		}
		
		H5GetPersonReportDetail({info:info.value}).then(res => {
			 loading.value=false
				if (res.status) {
					  sessionStorage.setItem('sfz', res.data.info.id_card_num);
					  sessionStorage.setItem('token', res.data.token);
					  sessionStorage.setItem('refreshToken', res.data.refresh_token);
					  var token = sessionStorage.getItem('token');
					  if (token == res.data.token){
						  router.push('/showReport')
					  }
				} else {
					showToast(res.msg);
				}
		
			})
	}
	let tijian_num=ref('');
	let logintype=ref('');
	let jigou_code=ref('');
	onMounted(() => {
		
		tijian_num.value =route.query.tj_num
		logintype.value =route.query.lg_type
		jigou_code.value=route.query.c
	
		sessionStorage.setItem('loginType', logintype.value);
		sessionStorage.setItem('tijian_num', tijian_num.value);
		let sloginType=sessionStorage.getItem('loginType');
		console.log(logintype.value)
		if(sloginType=='ewm'){  //如果是扫码过来的
				if(tijian_num.value != undefined){
					SearchInfo(tijian_num.value,jigou_code.value)
				}else{
					showToast('参数缺失');	
				}
		} 
		//router.replace('/selectOrganization')
		//window.location.href="http://localhostcommon/wxLogin"

	})
</script>

<style scoped>
	.LoginMain {
		 
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100vh;
		background-image: url('../assets/image/login.jpg');
		background-size: 100%;
		background-repeat: no-repeat;
		background-color: #afeefd;
		background-position: top center;

	}
	.button{
		width: 60%;
		margin-top: 50%;
		background-color: #33cdc9;
		color:#fff;
		border: 3px solid #e6f5fd;
	}
	.info {
		position: relative;
		top: -10px;
		/* border: 1px solid red; */
		border-radius: 10px;
		background-color: #fff;
		padding: 20px 20px;
	
	}
	
	.info .van-field {
		border-bottom: 1px solid #ccc;
	}
	.info .label{
		font-size: 18px;
		color: #3f3f3f;
		font-weight: 700;
		margin: 20px auto 0px auto;
	}
	.button{
		width: 100%;
		background-color: #33cdc9;
		border: 0px;
		margin-top: 40px;
	}
</style>