<template>
	<login-template :title="titleText" hide-bottom>
		<jl-input type="text" v-model="password" placeholder="设置长度6至20位的密码" @confirm="reg" showPassword clearable></jl-input>
		<view class="btn" v-if='loading'>处理中...</view>
		<view class="btn" v-else-if='password' @click="reg">确认</view>
		<view class="btn nocheck" v-else>确认</view>
	</login-template>
</template>

<script>
	import {
		reg,
		forgetPW
	} from '@/api/reg.js'
	import jlInput from '@/components/jl-input/main.vue'
	import loginTemplate from './template.vue'
	import {
		password
	} from '@/untils/validate.js'
	import md5 from 'js-md5'

	export default {
		components: {
			jlInput,
			loginTemplate
		},
		data() {
			return {
				loading: false,
				titleText: '',
				password: '',
			}
		},
		onLoad() {
			uni.$emit('passwordGetTitle', (title) => {
				this.titleText = title
			})
		},
		methods: {
			reg() {
				if (password(this.password)) {
					uni.showToast({
						title: '请设置长度6至20位的密码',
						icon: 'none'
					});
				} else {
					uni.$emit('setPassword', {
						password: md5(this.password),
						cb: () => {
							this.loading = false
						}
					})
				}
			}
		}
	}
</script>

<style>
	@import "./css";

	.inPlaSmall {
		font-family: PingFangSC-Regular;
		font-size: 19rpx;
		color: #d8d8d8;
	}
</style>
