<template>
	<view class="page">
		<view class="bg-gradient"></view>
		<van-nav-bar title="选择录入类型" left-arrow @click-left="onBack" fixed :z-index="999" />
		<view class="content">
			<view class="student-info">
				<view class="info-row">
					<text class="label">姓名</text>
					<text class="value">{{ studentName }}</text>
				</view>
				<view class="info-row">
					<text class="label">身份证号</text>
					<text class="value">{{ studentIdCard }}</text>
				</view>
			</view>
			<view class="type-list">
				<view class="type-card" @click="selectType('vision')" v-if="visionStatus === 0">
					<view class="type-name">视力数据录入</view>
					<van-icon name="arrow" />
				</view>
				<view class="type-card" @click="selectType('refraction')" v-if="refractionStatus === 0">
					<view class="type-name">屈光度数据录入</view>
					<van-icon name="arrow" />
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { getStudentInfo } from '@/services/common'


const studentName = ref('')
const studentIdCard = ref('')
const visionStatus = ref(0)
const refractionStatus = ref(0)
const params = ref({})

onLoad((options) => {
	if (options.studentId) {
		getStudentInfo(
			options.studentId
		).then((res) => {
			studentName.value = res.data.name
			studentIdCard.value = res.data.id_card
			visionStatus.value = 0
			refractionStatus.value = 0
			params.value = res.data

			params.value = {
				studentId: res.data.id,
				studentName: res.data.name,
				studentGender: res.data.gender,
				studentIdCard: res.data.id_card,
				classId: res.data.class_id,
				className: res.data.class_name,
				grade: res.data.grade,
				visionDataId: res.data.vision_data_id || '',
				schoolName: res.data.school_name || '',
				userName: res.data.name || '',
				userPhone:'17766664444',
				// userOrg: options.userOrg
			}
		})
	}

	if (options.studentName) {
		studentName.value = decodeURIComponent(options.studentName || '')
		studentIdCard.value = decodeURIComponent(options.studentIdCard || '')
		visionStatus.value = Number(options.visionStatus || 0)
		refractionStatus.value = Number(options.refractionStatus || 0)

		params.value = {
			studentId: options.studentId,
			studentName: options.studentName,
			studentGender: options.studentGender,
			studentIdCard: options.studentIdCard,
			classId: options.classId,
			className: options.className,
			grade: options.grade,
			visionDataId: options.visionDataId || '',
			schoolName: options.schoolName,
			userName: options.userName,
			userPhone: options.userPhone,
			userOrg: options.userOrg
		}
	}




})

const selectType = (type) => {
	const url = `/pages/index/vision-input?${Object.keys(params.value).map(k => `${k}=${encodeURIComponent(params.value[k])}`).join('&')}&type=${type}`
	uni.navigateTo({ url })
}

const onBack = () => {
	uni.navigateBack({
		delta: 1,
		success: () => { },
		fail: () => {
			uni.switchTab({
				url: '/pages/index/index'
			})
		}
	})
}
</script>

<style lang="scss" scoped>
.page {
	min-height: 100vh;
	position: relative;
}

.bg-gradient {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: linear-gradient(180deg, #4A9FF5 0%, #FFFFFF 100%);
	z-index: 0;
}

.content {
	padding: 20rpx;
	padding-top: calc(20rpx + 46px);
	position: relative;
	z-index: 1;
}

.student-info {
	background: #fff;
	border-radius: 20rpx;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.info-row {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	margin-bottom: 20rpx;
}

.info-row:last-child {
	margin-bottom: 0;
}

.label {
	width: 160rpx;
	color: #999;
}

.value {
	flex: 1;
	color: #333;
}

.type-list {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
}

.type-card {
	background: #fff;
	border-radius: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 50rpx 30rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	position: relative;
}

.type-name {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	flex: 1;
	text-align: center;
}

.type-card :deep(.van-icon) {
	position: absolute;
	right: 30rpx;
}
</style>
