<template>
	<view class="login-page">
		<view class="login-header">
			<view class="header-bg"></view>
			<view class="hospital-logo">
				<view class="logo-icon">
					<text class="icon-hospital">+</text>
				</view>
			</view>
			<view class="hospital-info">
				<text class="hospital-name">秦皇岛中医院</text>
				<text class="hospital-subtitle">医技预约系统</text>
			</view>
		</view>
		
		<view class="login-content">
			<view class="welcome-section">
				<text class="welcome-title">欢迎使用</text>
				<text class="welcome-desc">请输入患者登记号进行登录</text>
			</view>
			
			<view class="login-form">
				<view class="form-item">
					<view class="input-wrapper">
						<uni-icons type="person" size="20" color="#2E7D32"></uni-icons>
						<input 
							class="input-field" 
							type="text" 
							v-model="regnum" 
							placeholder="请输入患者登记号"
							placeholder-class="placeholder-text"
							@confirm="LoginFunc"
						/>
					</view>
				</view>
				
				<view class="login-tips">
					<uni-icons type="info" size="14" color="#999"></uni-icons>
					<text class="tips-text">登记号可在就诊卡或挂号单上找到</text>
				</view>
				
				<button class="login-btn" :disabled="regnum === ''" @click="LoginFunc()">
					<text v-if="!loading">登 录</text>
					<text v-else>登录中...</text>
				</button>
			</view>
			
			<view class="login-footer">
				<view class="footer-item">
					<uni-icons type="medal" size="16" color="#2E7D32"></uni-icons>
					<text>三甲医院</text>
				</view>
				<view class="footer-divider"></view>
				<view class="footer-item">
					<uni-icons type="heart" size="16" color="#2E7D32"></uni-icons>
					<text>用心服务</text>
				</view>
				<view class="footer-divider"></view>
				<view class="footer-item">
					<uni-icons type="staff" size="16" color="#2E7D32"></uni-icons>
					<text>专业医疗</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, onMounted } from "vue"
	import { Login } from "@/api"
	import { onLoad } from "@dcloudio/uni-app"
	
	let regnum = ref('');
	let loading = ref(false);
	
	const LoginFunc = () => {
		if (regnum.value === '') {
			uni.showToast({
				title: '请输入患者登记号',
				icon: 'none'
			});
			return false;
		}
		
		loading.value = true;
		
		Login({ regnum: regnum.value }).then(res => {
			loading.value = false;
			if (res.status) {
				uni.setStorageSync("access_token", res.data.token);
				uni.setStorageSync("refresh_token", res.data.refresh_token);
				uni.showToast({
					title: '登录成功',
					icon: 'success'
				});
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/CheckItemMainList'
					});
				}, 500);
			}
		}).catch(() => {
			loading.value = false;
		});
	}
	
	onMounted(() => {
		const token = uni.getStorageSync("access_token");
		if (token) {
			uni.reLaunch({
				url: '/pages/CheckItemMainList'
			});
		}
	});
</script>

<style lang="scss" scoped>
	.login-page {
		min-height: 100vh;
		background: linear-gradient(180deg, #F5F7FA 0%, #FFFFFF 100%);
	}
	
	.login-header {
		position: relative;
		padding: 80rpx 40rpx 60rpx;
		text-align: center;
		
		.header-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			height: 280rpx;
			background: linear-gradient(135deg, #2E7D32 0%, #4CAF50 50%, #81C784 100%);
			border-radius: 0 0 60rpx 60rpx;
		}
		
		.hospital-logo {
			position: relative;
			z-index: 1;
			margin-bottom: 24rpx;
			
			.logo-icon {
				width: 120rpx;
				height: 120rpx;
				background: #FFFFFF;
				border-radius: 50%;
				display: inline-flex;
				align-items: center;
				justify-content: center;
				box-shadow: 0 8rpx 32rpx rgba(46, 125, 50, 0.3);
				
				.icon-hospital {
					font-size: 60rpx;
					font-weight: bold;
					color: #2E7D32;
				}
			}
		}
		
		.hospital-info {
			position: relative;
			z-index: 1;
			
			.hospital-name {
				display: block;
				font-size: 40rpx;
				font-weight: 600;
				color: #FFFFFF;
				letter-spacing: 4rpx;
				text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
			}
			
			.hospital-subtitle {
				display: block;
				font-size: 28rpx;
				color: rgba(255, 255, 255, 0.9);
				margin-top: 12rpx;
			}
		}
	}
	
	.login-content {
		padding: 40rpx 48rpx;
		
		.welcome-section {
			text-align: center;
			margin-bottom: 60rpx;
			
			.welcome-title {
				display: block;
				font-size: 44rpx;
				font-weight: 600;
				color: #333333;
				margin-bottom: 16rpx;
			}
			
			.welcome-desc {
				display: block;
				font-size: 28rpx;
				color: #999999;
			}
		}
		
		.login-form {
			.form-item {
				margin-bottom: 24rpx;
				
				.input-wrapper {
					display: flex;
					align-items: center;
					background: #FFFFFF;
					border: 2rpx solid #E8E8E8;
					border-radius: 24rpx;
					padding: 0 32rpx;
					height: 100rpx;
					transition: all 0.3s ease;
					
					&:focus-within {
						border-color: #2E7D32;
						box-shadow: 0 0 0 4rpx rgba(46, 125, 50, 0.1);
					}
					
					.input-field {
						flex: 1;
						font-size: 32rpx;
						color: #333333;
						margin-left: 16rpx;
					}
				}
			}
			
			.login-tips {
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 32rpx 0;
				
				.tips-text {
					font-size: 24rpx;
					color: #999999;
					margin-left: 8rpx;
				}
			}
			
			.login-btn {
				width: 100%;
				height: 100rpx;
				background: linear-gradient(135deg, #2E7D32 0%, #4CAF50 100%);
				border-radius: 24rpx;
				font-size: 34rpx;
				font-weight: 500;
				color: #FFFFFF;
				border: none;
				letter-spacing: 8rpx;
				box-shadow: 0 8rpx 24rpx rgba(46, 125, 50, 0.3);
				transition: all 0.3s ease;
				
				&:active {
					transform: scale(0.98);
					opacity: 0.9;
				}
				
				&[disabled] {
					background: #CCCCCC;
					box-shadow: none;
				}
			}
		}
		
		.login-footer {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 80rpx;
			padding: 40rpx 0;
			
			.footer-item {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #666666;
				
				text {
					margin-left: 8rpx;
				}
			}
			
			.footer-divider {
				width: 2rpx;
				height: 24rpx;
				background: #E0E0E0;
				margin: 0 24rpx;
			}
		}
	}
	
	.placeholder-text {
		color: #CCCCCC;
		font-size: 32rpx;
	}
</style>