<template>
	<view class="adminLogin">
		<navigation-bar-view ref="nav"></navigation-bar-view>
		<view class="body">
			<view class="input-box">
				<input :value="body.account" placeholder="请输入账号" placeholder-style="color: #B7B7B7" @input="changeAccount" />
			</view>
			<view class="input-box" style="margin-top: 1.7vw;">
				<input placeholder="请输入密码" password placeholder-style="color: #B7B7B7" @input="changePassword" />
			</view>
			<view class="btn" @click="login">登录</view>
		</view>
	</view>
</template>

<script>
	import navigationBarView from '../../components/navigationBarView.vue';
	export default {
		components: {
			navigationBarView
		},

		data() {
			return {
				body: {
					account: '',
					password: ''
				}
			}
		},
		
		onLoad() {
			this.body.account = uni.getStorageSync('account');
		},

		methods: {
			changeAccount(e) {
				console.log(e);
				this.body.account = e.detail.value;
			},

			changePassword(e) {
				this.body.password = e.detail.value;
			},

			login() {
				this.body.deviceSn = uni.getStorageSync('sn');
				this.$api.managerLogin(this.body).then(res => {
					uni.setStorageSync('access_token', res.data.token);
					uni.setStorageSync('account', this.body.account);
					uni.redirectTo({
						url: '/pages/admin/index'
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.adminLogin {
		width: 100vw;
		height: 100vw;
		background-color: #FFFFFF;

		.body {
			padding: 30.3vw 7.3vw 0;

			.input-box {
				padding: 4.3vw 0;
				border-bottom: 2rpx solid #999999;

				input {
					font-size: 4.3vw;
				}
			}

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 11.5vw;
				border-radius: 11.5vw;
				margin-top: 8.1vw;
				font-weight: 500;
				font-size: 4.3vw;
				background: linear-gradient(to right, #FEE704, #FDD001);
			}
		}
	}
</style>
