<template>
	<view class="content">
		<view class="text-area">
			<view class="text-area-content">
				<view class="logoText">
					<image class="logo" src="/static/logo/logo.png"></image>
					<text class="text1">广州医科大</text>
				</view>
				<view class="line"></view>
				<text class="text2">实验室管理系统</text>
			</view>
			<view class="form-area">
				<view class="form-area-content">
					<view class="name-area">
						<i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i>
						<u--input
						clearable
						placeholder="请输入工号"
						border="none"
						v-model="form.account"></u--input>
					</view>
					<view class="pwd-area">
						<i class="iconfont icon-a-shezhi2" style="margin-right: 10rpx;"></i>
						<u--input
							border="none"
							v-model="form.password" 
							placeholder="请输入密码"
							password
							clearable
						></u--input>
					</view>
				</view>
			</view>
			<button class="form-area-btn" @click="toLogin">登 录</button>
			
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { login,getInfo } from "@/api/user.js"
	import { setToken } from "@/utils/auth.js"
	import cache from '@/utils/storage.js'
	export default {
		data() {
			return {
				form:{
					account:'admin',
					password:'admin123'
				},
				showPassword: true,
				pwdType:"password"
			};
		},
		methods:{
			showPwd(){
				this.pwdType = "text"
			},
			toLogin(){
				uni.showLoading({
					title:"正在登录中",
					icon:'none',
					mask:true
				})
				try{
					login(this.form.account,this.form.password).then(res=>{
						setToken(res.data.token)
						getInfo().then(res=>{
							if(res.data.code===200){
								uni.hideLoading()
								cache.session.setJSON('role',res.data.roles[0])
								cache.session.setJSON('phone',res.data.user.phonenumber)
								cache.session.setJSON('email',res.data.user.email)
								cache.session.setJSON('nickName',res.data.user.nickName)
								cache.session.setJSON('userName',res.data.user.userName)
								cache.session.setJSON('userId',res.data.user.userId)
								uni.switchTab({
									url:'/pages/home/home'
								})
							}
						})
					})
				}catch(err){
					uni.hideLoading()
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.text-area {
		display: flex;
		justify-content: center;
		flex-direction: column;
		position: fixed;
		top: 25%;
		transform: translateY(-20%);
		text-align: center;
		width: 80%;
	}
	.text-area-content{
		.logoText{
			.logo{
				height: 100rpx;
				width: 100rpx;
				transform:translateY(20%);
			}
			.text1{
				color: $uni-text-color;
				font-size: 56rpx;
				transform:translateY(-10%);
				height: 100rpx;
				line-height: 100rpx;
			}
		}
		.text2{
			color: rgba(128, 128, 128, 1);
			font-size: 30rpx;
			line-height: 150%;
		}
		.line{
			width: 354rpx;
			height: 2rpx;
			margin: auto;
			color: $uni-text-color;
			background-color: $uni-text-color-grey;
			font-size: 32rpx;
			line-height: 150%;
			text-align: center;
		}
	}
	.form-area{
		margin-top: 80rpx;
		margin-bottom: 160rpx;
		.name-area,.pwd-area{
			width: 100%;
			height: 100rpx;
			padding-left: 20rpx;
			padding-right: 20rpx;
			color: $uni-text-color-black;
			font-size: 30rpx;
			// line-height: 150%;
			border: rgba(0, 0, 0, 0.3) solid 2rpx;
			text-align: left;
			box-sizing: border-box;
			display: flex;
			align-items: center;
		}
		.name-area{
			border-radius: 20rpx 20rpx 0 0;
		}
		.pwd-area{
			border-radius:0 0 20rpx 20rpx ;
			border-top: 0;
		}
	}
	
	.form-area-btn{
		height: 100rpx;
		width: 100%;
		line-height: 100rpx;
		outline: none;
		background: #19be6b;
		color: $uni-text-color-inverse;
		border-radius: 20rpx;
		margin-top: 30rpx;
		font-size: 32rpx;
	}
</style>
