<template>
	<view class="content">
		<view class="head">
			<text>登录</text>
		</view>
		<view class="login-wrap">
			<view class="username item">
				<text>账号：</text>
				<uni-easyinput :inputBorder="false" class="login_input" type="text" v-model="username" placeholder="请输入账号" />
			</view>
<!-- 			<view class="password item">
				<text>密码：</text>
				<uni-easyinput :inputBorder="false" class="login_input" type="password" v-model="password" placeholder="请输入密码">
				</uni-easyinput>
			</view> -->
<!-- 			<getPhone showByPlatform />	 -->
			<button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
		</view>
	</view>
</template>

<script>
	import { login} from '@/api/user';
	import { setToken } from '@/libs/auth';	
	import getPhone from '@/components/getPhone.vue'
	export default {
		data() {
			return {
				username: "",
				password: "888888",
			}
		},
		onLoad({username,password}) {
			if(username){
				this.username=username;
				this.password=password;
			}
		},
		methods: {		
			loginSubmit() {	
				let username = (this.username).trim();
				let password = (this.password).trim();
				if (username.length < 1) {
					uni.showToast({
						title: '请填写账号',
						icon: "error"
					})
					return;
				}
				login({
					accountName:username,
					password
				}).then((res) => {
					let token = res.data.token;
					uni.setStorageSync('phone',username)
					setToken(token);
					uni.switchTab({
						url: '/pages/index/index'
					})			
				}).catch((res)=>{
					console.log(res)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.head {
			font-size: 50upx;
			text-align: center;
			padding: 40upx 0;
			letter-spacing: 2upx;
		}

		.login-wrap {
			width: 90%;
			margin: 50upx auto 0;
			box-sizing: border-box;
			padding: 20upx;
			border-radius: 8upx;
			.item {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				height: 100upx;
				font-size: 32upx;
				line-height: 100upx;
				input {
					font-size: 32upx;
					height: 100upx;
					border: 0;
				}
			}
			.tip {
				text-align: right;
				padding: 18upx 0;
				font-size: 28upx;
			}

			.submit-BT {
				border-radius: 16upx;
				margin-top: 50upx;
				background-color: #409eff;
				border-color: #409eff;	
			}
		}
	}
</style>
