<template>
	<view class="login">
		<image src="../../static/logo.jpg" mode=""></image>
		<view class="form">
			<van-field label="用户名" :userName="userName" placeholder="请输入用户名" @change="getName" />
			<van-field label="密码" type="password" :passWord="passWord" placeholder="请输入密码" @change="getWord" />
			<van-button type="danger" class="btn" @click="submit">登 录</van-button>
		</view>
		<view class="jump" @click="goRegirster">没有账号去注册</view>
	</view>
	</view>
</template>

<script>
	import {
		toLogin
	} from '../../api/login.js'
	import {
		encrypto
	} from '../../utils/cryptojs.js'
	export default {
		data() {
			return {
				userName: "",
				passWord: ""
			}
		},
		methods: {
			getName(event) {
				this.userName = event.detail;
			},
			getWord(event) {
				this.passWord = event.detail;
			},
			goRegirster() {
				uni.navigateTo({
					url: "/pages/register/register"
				})
			},
			async submit() {
				const result = await toLogin({
					userName: this.userName,
					passWord: encrypto(this.passWord)
				})
				if (result.accessToken) {
					uni.setStorageSync("token", result.accessToken);
					console.log("成功")
					uni.switchTab({
						url: "/pages/home/home"
					})
				}
				// if (result.code ==  "A00001") {
				// 	console.log("走进来")
				// 	Toast.fail(result.msg);
				// }
			}
		}
	}
</script>

<style lang="scss">
	.login {
		.form {
			width: 90%;
			margin: 50rpx auto;
		}

		image {
			width: 300rpx;
			height: 300rpx;
			margin-left: 200rpx;
			margin-top: 150rpx;
		}

		.van-button--normal {
			width: 100%;
			margin-top: 60rpx;
		}

		.jump {
			width: 240rpx;
			margin: 50rpx auto;
			color: blue;
		}
	}
</style>
