<template>
	<view class="app">
		<view class="title">
			账号登录
		</view>
		<view class="loginphone">
			<input class="phone" type="text" placeholder="手机号码" maxlength="11" v-model="phone" />
		</view>
		<view class="logincode loginphone" style="top: 40%;">
			<u-input class='code phone' placeholder="密码" maxlength="10" v-model="password" type="password"
				:border="true" :password-icon="true" />
		</view>
		<view class="loginbtn" @tap='pwdlogin'>
			登录
		</view>
		<view class="switch" @tap='goregister' style="left:55%">
			没有账号,请先注册
		</view>
		<u-toast ref="uToast" />
	</view>
</template>
<script>
	import {
		appLoginpwd
	} from '../../api/login/index.js'
	export default {
		data() {
			return {
				phone: '13645678906',
				password: '123456',
			};
		},
		//获取到传值
		onLoad(options) {},
		methods: {
			//密码登录
			pwdlogin() {
				appLoginpwd(this.phone, this.password).then(res => {
					if (res.code == 200) {
						if (res.data.registerFlag == false) {
							uni.setStorage({
								key: 'patientId',
								data: res.data.patientId,
								success: function() {
									console.log('patientId保存成功');
								}
							});
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'success',
								duration: '1500'
							})
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/homepage/homepage',
								})
							}, 1500);
						} else {
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'error'
							})
						}
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error'
						})
					}
				})
			},
			//跳转注册页
			goregister() {
				uni.navigateTo({
					url: '/pages/register/register'
				})
			},
		},
		toLogin() {
			// uni.hideKeyboard() //隐藏已经显示的软键盘，如果软键盘没有显示则不做任何操作。
			// uni.redirectTo({
			// 	url: 'login'
			// }); //跳转到登录页
			// uni.navigateBack(); //关闭当前页面，返回上一页面
		}
	}
</script>

<style lang="scss">
	@import "./login.scss";
</style>
