<template>
	<view class="regirster">
		<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>
	</view>
</template>

<script>
	import {
		toRegister
	} 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;
			},
			// async	submit() {
			// 	const result = await toRegister({
			// 		userName: this.userName,
			// 		passWord: encrypto(this.passWord)
			// 	})
			// 	console.log(result,'结果')
			// }
			submit() {
				toRegister({
					userName: this.userName,
					passWord: encrypto(this.passWord)
				}).then(res => {
					if (res.accessToken) {
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				}).catch(error => {
					console.log(error, '失败')
				})
			}
		}
	}
</script>

<style lang="scss">
	.regirster {
		.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>
