<template>
	<view class="container">
		<!-- logo区域 -->
		<image class="logo" src="/static/logo.png" mode="aspectFill"></image>

		<!-- 标题区域 -->
		<view class="title">信息采集迎新系统</view>
		<!-- <view class="title" v-if="pageValue == 2" @click="ceshi">宿舍选取迎新系统</view>
		<view class="title" v-if="pageValue == 3" @click="ceshi">访客预约迎新系统</view> -->

		<!-- 录取号区域 -->
		<view class="box">
			<view class="box_text">录取号</view>
			<view class="box_input">
				<input class="input" type="text" placeholder="请输入录取号" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="admissNum" />
			</view>
		</view>

		<!-- 身份证号区域 -->
		<view class="box">
			<view class="box_text">身份证号</view>
			<view class="box_input">
				<input class="input" type="text" placeholder="请输入身份证号" placeholder-style="color:#CCCCCC;font-size:28rpx" v-model="cardId" />
			</view>
		</view>

		<!-- 登录按钮区域 -->
		<view class="btn" :class="{ active: admissNum && cardId }" @click="handleLogin">授权登录</view>

		<!-- 背景图片区域 -->
		<image class="logo_bg" src="/static/logo-bg.png" mode="aspectFill"></image>

		<!-- 弹窗区域 -->
		<uni-popup ref="popup" :is-mask-click="false">
			<view class="pop">
				<image class="pop_img" src="/static/3.png" mode="aspectFill"></image>
				<!-- 关闭图标 -->
				<uni-icons class="pop_close" type="closeempty" color="#808080" size="20" @click="handleClose"></uni-icons>
				<view class="pop_title">温馨提示</view>
				<view class="pop_text">亲爱的同学，欢迎加入校园大家庭！</view>
				<view class="pop_text">系统显示您当前的缴费流程尚未完成。</view>
				<view class="pop_text">为了确保每位同学都能顺利开启校园生活，</view>
				<view class="pop_text">完成缴费后即可解锁宿舍选择功能哦~</view>
				<view class="pop_text">期待您早日选定心仪的宿舍，开启美好校园生活！</view>
				<view class="pop_btn" @click="handleFinish">去完成缴费</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { loginReq } from '@/api/index.js'

// 页面类型
const pageValue = ref()

// 录取号
const admissNum = ref()

// 身份证号
const cardId = ref()

const popup = ref()

onLoad((options) => {
	// console.log(options)
	// pageValue.value = options.pageValue
	// console.log(pageValue.value)
})

// const ceshi = () => {
// 	popup.value.open()
// }

// 弹窗关闭图标回调
const handleClose = () => {
	popup.value.close()
}

// 授权登录按钮回调
const handleLogin = async () => {
	if (!admissNum.value) {
		uni.showToast({
			title: '请输入录取号',
			icon: 'none'
		})
		return
	}

	if (!cardId.value) {
		uni.showToast({
			title: '请输入身份证号',
			icon: 'none'
		})
		return
	}

	// let reg_admissNum = /^\d{8}$/

	// if (!reg_admissNum.test(admissNum.value)) {
	// 	uni.showToast({
	// 		title: '录取号为8位数字',
	// 		icon: 'none'
	// 	})
	// 	return
	// }

	let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/

	if (!reg.test(cardId.value)) {
		uni.showToast({
			title: '身份证号格式错误',
			icon: 'none'
		})
		return
	}

	const res = await loginReq({
		admissNum: admissNum.value,
		cardId: cardId.value
	})
	// console.log(res)

	if (res.code == 200) {
		uni.setStorageSync('studentInfo', res.data)
		uni.setStorageSync('TOKEN', res.data.token)

		// if (pageValue.value == 1) {
		// 	uni.reLaunch({
		// 		url: '/pages/read/read'
		// 	})
		// } else if (pageValue.value == 2) {
		// 	// uni.reLaunch({
		// 	// 	url: '/pages/select/select'
		// 	// })
		// 	popup.value.open()
		// } else if (pageValue.value == 3) {
		// 	uni.reLaunch({
		// 		url: '/pages/subscribe/subscribe'
		// 	})
		// } else {
		// 	uni.setStorageSync('token', '')
		// 	uni.reLaunch({
		// 		url: '/pages/404/404?message=暂无页面'
		// 	})
		// }
		uni.reLaunch({
			url: '/pages/read/read'
		})
	}
}

// 去完成缴费回调
const handleFinish = () => {
	uni.reLaunch({
		url: '/pages/status/status'
	})
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 0 20rpx;
	min-height: 100vh;
	background: linear-gradient(180deg, rgba(242, 247, 255, 1) 0%, rgba(242, 247, 255, 0) 100%);

	.logo {
		margin-top: 80rpx;
		width: 143rpx;
		height: 143rpx;
	}

	.title {
		margin-top: 28rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.box {
		margin-bottom: 40rpx;
		width: 100%;

		.box_text {
			margin-left: 30rpx;
			font-size: 28rpx;
		}

		.box_input {
			padding: 0 40rpx;
			margin-top: 10rpx;
			height: 100rpx;
			border-radius: 8rpx;
			background-color: #fff;

			.input {
				height: 100%;
			}
		}
	}

	.btn {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 260rpx;
		width: 100%;
		height: 100rpx;
		border-radius: 8rpx;
		font-size: 32rpx;
		color: #fff;
		background-color: #ccc;
	}

	.active {
		background-color: #0061ff;
	}

	.logo_bg {
		position: absolute;
		top: -50rpx;
		right: -45rpx;
		width: 589rpx;
		height: 320rpx;
	}

	.pop {
		position: relative;
		box-sizing: border-box;
		padding: 150rpx 20rpx 50rpx;
		width: 659rpx;
		height: 728rpx;
		border-radius: 15rpx;
		background: linear-gradient(180deg, #ebf2ff 0%, #ffffff 100%);

		.pop_img {
			position: absolute;
			top: -103rpx;
			left: 227rpx;
			width: 206rpx;
			height: 206rpx;
		}

		.pop_close {
			position: absolute;
			top: 19rpx;
			right: 29rpx;
		}

		.pop_title {
			margin-bottom: 28rpx;
			font-size: 32rpx;
			font-weight: bold;
		}

		.pop_text {
			font-size: 28rpx;
			line-height: 50rpx;
		}

		.pop_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 90rpx auto 0;
			width: 543rpx;
			height: 100rpx;
			color: #fff;
			font-size: 32rpx;
			border-radius: 8rpx;
			background-color: #0061ff;
		}
	}
}
</style>
