<template>
	<view class="container">
		<view class="loginTitle">WelcomeLALA</view>
		<view class="loginText">请使用您的账号登录</view>
		<view class="login-box">
			<view class="username">账号</view>
			<input class="input-box" type="number" v-model="phone" placeholder="请输入账号" />
		</view>
		<view class="login-box">
			<view class="username">密码</view>
			<input class="input-box" type="password" v-model="password" placeholder="请输入密码" />
		</view>

		<view class="forget flex">
			
			<text @click="navTo('/pages/public/forget')">忘记密码</text>
		</view>
		<view class="login" @click="toLogin">登录</view>
		<view class="login-tip">
			还没有账号？
			<text class="register" @click="navTo('/pages/public/register')">立即注册</text>
		</view>
	</view>
</template>

<script>
import { mapMutations } from 'vuex';
import { login } from '@/api/login.js';
import { getUserInfo } from '@/api/user.js';
export default {
	data() {
		return {
			phone: '',
			password: '',
		};
	},
	onLoad() {},
	
	methods: {
		...mapMutations('user', ['setUserInfo', 'login']),
		//登录
		async toLogin() {
			uni.showLoading({
				title:'正在登陆中'
			});
			let obj = this;
			obj.logining = true;
			if (obj.phone == '') {
				obj.$api.msg('请输入手机号');
				return;
			}
			if (obj.password == '') {
				obj.$api.msg('请输入密码');
				return;
			}
			login({
				account: obj.phone,
				password: obj.password
			})
				.then(function(e) {
					if (obj.rememberPsw) {
						uni.setStorageSync('HCuname', obj.phone);
						uni.setStorageSync('HCpassw', obj.password);
					} else {
						uni.removeStorageSync('HCuname');
						uni.removeStorageSync('HCpassw');
						obj.phone = '';
						obj.password = '';
					}
					uni.setStorageSync('token', e.data.token);
					getUserInfo({}).then(e => {
						obj.login();
						// 保存返回用户数据
						obj.setUserInfo(e.data);

						uni.switchTab({
							url: '/pages/index/index'
						});
					});
					uni.hideLoading();
				})
				.catch(function(e) {
					console.log(e);
				});
		},
		navTo(url) {
			uni.navigateTo({
				url
			});
		},
		// 后退
		navBack() {
			uni.navigateBack();
		},
		
	}
};
</script>

<style lang="scss">
page {
	min-height: 100%;
	background-color: #ffffff;
	.container {
		width: 100%;
		padding: 30% 60rpx;
	}
}
.loginTitle {
	font-weight: bold;
	color: #333333;
	font-size: 58rpx;
	padding-bottom: 34rpx;
}
.loginText {
	font-weight: 500;
	color: #333333;
	font-size: 34rpx;
	padding-bottom: 34rpx;
}
.login-box {
	padding-top: 90rpx;
	.username {
		padding-bottom: 30rpx;
		font-weight: 500;
		color: #333333;
		font-size: 32rpx;
	}
}
.forget {
	justify-content: flex-end;
	text-align: right;
	margin: 70rpx 0rpx;
	font-weight: 500;
	color: #333333;
	font-size: 28rpx;
	.mui-checkbox{
		font-weight: 500;
		color: #333333;
		font-size: 35rpx;
	}
}
.login {
	background: linear-gradient(90deg, #60BAB0, #60BAB0, #45969B);
	margin-top: 20rpx;
	color: #ffffff;
	text-align: center;
	padding: 26rpx 0rpx;
	border-radius: 50rpx;
}
.login-tip {
	padding: 60rpx 0rpx;
	text-align: center;
	font-weight: 500;
	color: #333333;
	font-size: 28rpx;
	.register {
		color: #5771df;
	}
}
// /* input 样式 */
// .input-placeholder {
// 	color: #ffffff;
// }

// .placeholder {
// 	color: #ffffff;
// }
</style>
