<template>
	<view class="container">
		<!-- 自定义导航栏区域 -->
		<view class="tab" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }" v-show="!showHeader">
			<img class="tab_img" src="../../static/images/people.png" @click="goPage('/pages/myCenter/myCenter')" />
			万载三中
		</view>

		<!-- 页面下拉时显示的导航栏 -->
		<view class="tab2" :style="{ height: customBarH * 2 + 'rpx', paddingTop: statusBarH * 2 + 'rpx' }" v-show="showHeader">万载三中</view>

		<!-- 顶部图片区域 -->
		<view class="header">
			<img mode="aspectFill" class="header_img" src="../../static/images/header.png" />
			<!-- 学校图标区域 -->
			<img mode="aspectFill" class="header_icon" src="../../static/images/school-logo.jpg" />
			<!-- 学校名称区域 -->
			<view class="header_school">万载县第三中学</view>
			<!-- 学生姓名区域 -->
			<view class="header_name">张三</view>
			<!-- 学生年级区域 -->
			<view class="header_grade">初二</view>
			<!-- 二维码区域 -->
			<view class="header_code">
				<uv-qrcode ref="qrcodeRef" size="82rpx" :value="QRCodeUrl" :options="options" @click="handleClickCode"></uv-qrcode>
			</view>
		</view>

		<!-- 详细信息区域 -->
		<view class="body">
			<!-- 个人信息区域 -->
			<view class="body_header">
				<img class="info_bg" src="../../static/images/info-bg.png" />

				<img class="info_img" src="../../static/images/user-photo.png" />
				<view class="info_name">王佳明</view>

				<view class="info_detail" @click="goPage('/pages/myMsg/myMsg')">个人信息＞</view>

				<view class="info_change" @click="goPage('/pages/change/change')">切换 ＞</view>

				<!-- 关联区域 -->
				<view class="info_bind">
					<img @click="goPage('/pages/bind/bind')" class="bind_img" src="../../static/images/bind.png" />
					<text @click="goPage('/pages/bind/bind')">关联小孩</text>
				</view>
			</view>

			<!-- 应用列表区域 -->
			<view class="body_list">
				<!-- 每一个应用区域 -->
				<view class="list_box" v-for="item in list" :key="item.id" @click="goPage(item.path)">
					<img class="box_img" :src="item.url" />
					{{ item.title }}
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app'

onLoad(() => {
	// 获取系统信息
	uni.getSystemInfo({
		success: (e) => {
			// 获取状态栏高度
			statusBarH.value = e.statusBarHeight
			// // 获取菜单按钮栏高度
			let custom = uni.getMenuButtonBoundingClientRect()
			customBarH.value = custom.height
		}
	})
})

onPullDownRefresh(() => {
	qrcodeRef.value.remake()
	setTimeout(() => {
		uni.stopPullDownRefresh()
	}, 1500)
})

onPageScroll((e) => {
	if (e.scrollTop > 70) {
		showHeader.value = true
	} else {
		showHeader.value = false
	}
})
// 顶部导航栏显示隐藏控制
const showHeader = ref(false)

// 状态栏高度
const statusBarH = ref(0)

// 胶囊按钮栏高度
const customBarH = ref(0)

// 二维码元素引用标记
const qrcodeRef = ref(null)

// 应用列表数据
const list = ref([
	// {
	// 	id: 1,
	// 	title: '考勤管理',
	// 	url: '../../static/images/icon.png'
	// },
	// {
	// 	id: 2,
	// 	title: '课表查询',
	// 	url: '../../static/images/icon.png',
	// 	path: ''
	// },
	{
		id: 3,
		title: '学生轨迹',
		url: '../../static/images/icon.png',
		path: '/pages/track/track'
	},
	// {
	// 	id: 4,
	// 	title: '打卡接龙',
	// 	url: '../../static/images/icon.png'
	// },
	// {
	// 	id: 5,
	// 	title: '人脸采集',
	// 	url: '../../static/images/icon.png'
	// },
	// {
	// 	id: 6,
	// 	title: '智慧教学',
	// 	url: '../../static/images/icon.png'
	// },
	{
		id: 7,
		title: '消息通知',
		url: '../../static/images/icon.png',
		path: '/pages/msgWarn/msgWarn'
	},
	{
		id: 8,
		title: '访客预约',
		url: '../../static/images/icon.png',
		path: '/pagesReservation/reservation/reservation'
	},
	// {
	// 	id: 9,
	// 	title: '课后作业',
	// 	url: '../../static/images/icon.png'
	// },
	{
		id: 10,
		title: '校园预警',
		url: '../../static/images/icon.png',
		path: '/pagesWarning/home/home'
	},
	{
		id: 11,
		title: '通讯录',
		url: '../../static/images/icon.png',
		path: '/pages/addressBook/addressBook'
	}
])

// 二维码信息
const QRCodeUrl = ref('123')

// 二维码自定义样式
const options = {
	typeNumber: 4,
	foregroundImageBorderRadius: 5,
	foregroundImageSrc: '/static/images/school-logo.jpg'
}

// 跳转页面函数
const goPage = (url) => {
	if (url === '/pagesReservation/reservation/reservation') {
		uni.setStorageSync('Tab-activeIndex', 0)
	}
	uni.navigateTo({
		url
	})
}

// 点击二维码时的回调
const handleClickCode = () => {
	uni.navigateTo({
		url: `/pages/quickMark/quickMark?value=${QRCodeUrl.value}`
	})
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	padding: 0 20rpx;
	min-height: 100vh;
	background-color: #f1f6fe;

	// 自定义导航栏区域样式
	.tab {
		position: relative;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 34rpx;

		.tab_img {
			position: absolute;
			top: v-bind(statusBarH);
			left: 0;
			width: 62rpx;
			height: 62rpx;
		}
	}

	.tab2 {
		z-index: 999;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		padding: 0 20rpx;
		font-size: 34rpx;
		text-align: center;
		background-color: #fff;
	}

	// 顶部图片区域样式
	.header {
		position: relative;
		margin-top: 35rpx;
		width: 710rpx;
		height: 369rpx;
		color: #fff;
		font-size: 36rpx;
		border-radius: 10rpx;

		.header_img {
			width: 100%;
			height: 100%;
		}

		.header_icon {
			position: absolute;
			top: 25rpx;
			left: 25rpx;
			width: 47rpx;
			height: 47rpx;
			border-radius: 50%;
		}

		.header_school {
			position: absolute;
			top: 18rpx;
			left: 81rpx;
			font-size: 40rpx;
		}

		.header_name {
			position: absolute;
			top: 243rpx;
			right: 145rpx;
		}

		.header_grade {
			position: absolute;
			top: 292rpx;
			right: 145rpx;
		}

		.header_code {
			position: absolute;
			top: 245rpx;
			right: 28rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 98rpx;
			height: 98rpx;
			border-radius: 10rpx;
			background-color: #fff;
		}
	}

	// 详细信息区域样式
	.body {
		margin-top: 20rpx;

		.body_header {
			position: relative;
			width: 710rpx;
			height: 128rpx;

			.info_bg {
				position: absolute;
				z-index: 1;
				width: 100%;
				height: 100%;
				pointer-events: none;
			}

			.info_img {
				position: absolute;
				top: 20rpx;
				left: 20rpx;
				z-index: 1;
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
			}

			.info_name {
				position: absolute;
				top: 15rpx;
				left: 132rpx;
				z-index: 1;
				font-size: 32rpx;
				font-weight: bold;
			}

			.info_detail {
				position: absolute;
				top: 64rpx;
				left: 132rpx;
				z-index: 1;
				width: 136rpx;
				height: 46rpx;
				line-height: 46rpx;
				text-align: center;
				font-size: 24rpx;
				color: #0061ff;
				border-radius: 5rpx;
				background-color: #ebf2ff;
			}

			.info_change {
				position: absolute;
				top: 48rpx;
				left: 393rpx;
				z-index: 1;
				font-size: 24rpx;
				color: #a6a6a6;
			}

			.info_bind {
				position: absolute;
				top: 20rpx;
				right: 0;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				padding-right: 25rpx;
				width: 300rpx;
				height: 102rpx;
				font-size: 28rpx;
				color: #0061ff;
				background-color: #e8f1ff;

				.bind_img {
					margin-right: 5rpx;
					width: 42rpx;
					height: 42rpx;
				}
			}
		}

		.body_list {
			padding: 30rpx 30rpx;
			display: grid;
			grid-template-columns: repeat(3, 1fr);
			grid-auto-rows: 240rpx;
			background-color: #fff;
			gap: 20rpx 10rpx;

			.list_box {
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;
				align-items: center;
				font-size: 28rpx;

				.box_img {
					width: 120rpx;
					height: 120rpx;
					border-radius: 32rpx;
				}
			}
		}
	}
}
</style>
