<template>
	<view class="register">
		<Logo></Logo>
		<view class="form">
			<!-- <van-form> -->
			<van-field :value="username" name="用户名" label="用户名" placeholder="请输入用户名" @change="onUser" />
			<van-field :value="password" type="password"  name="密码" label="密码" placeholder="请输入密码" @change="onWord" />
			<view class="btn">
				<van-button type="danger" block square form-type="submit" @click="goRegister">立即注册</van-button>
			</view>
			<!-- </van-form> -->
		</view>
	</view>
</template>


<script>
	import {
		toRegister
	} from '../../api/user.js';
	import {
		encrypto
	} from '@/utils/cryptojs.js'
	export default {
		data() {
			return {
				userName: "",
				passWord: ""
			}
		},
		methods: {
			onUser(event) {
				this.userName = event.detail;
			},
			onWord(event) {
				this.passWord = event.detail;
			},
			goRegister() {
				let obj = {
					userName: this.username,
					passWord: encrypto(this.password)
				}
				toRegister(obj).then(res => {
					if(res.accessToken) {
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.form {
		width: 80%;
		margin: 50rpx auto;

		.btn {
			margin-top: 40rpx;
		}
	}
</style>
