<template>
	<view>
		<view class="login">
			<view class="verify_tips">
				To verify your email,we've send a verification code to {{username}}
			</view>
			<input type="text" class="login_input" placeholder="Enter code" v-model="resetcode" @input="verificationLogin">
			<view class="tips" v-show="isErr">The code is incorrect.</view>
			<button class="login_submit" :disabled="isLogin" @click="goPage">CONTINUE</button>
			<view class="verify_text" @click="sendresetcode">Resend code</view>
		</view>
		<view class="mask" v-show="isShow" @click="isShow=false"></view>
		<view class="verify_popup" v-show="isShow">
			<view class="verify_popup_close">
				<image src="../../static/img/close.png" mode=""></image>
			</view>
			<view class="verify_popup_title">Send!</view>
			<view class="verify_popup_msg">we send a new verification code to {{query.username}}</view>
			<view class="verify_popup_btn">
				<button @click="isShow=false">OKAY</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {defaultRequest,defaultRequest2} from '../../api/index.js'
	export default {
		data() {
			return {
				isShow:true,
				isErr:false,
				isLogin:true,
				username:'',
				type:'',
				resetcode:'',
				query:{
					_action:'sendresetcode',
					username:'',
					// password:'',
				}
			}
		},
		methods:{
			goPage(){
				console.info(this.username)
				uni.navigateTo({
					url:'changePwd?resetcode='+this.resetcode+'&username='+this.username
				})
			},
			sendresetcode(){
				console.log(this.query)
				defaultRequest(this.query).then(res=>{
					console.log(res)
					if(res.error==0){
						uni.showToast({
							title:res.message,
							icon:'none'
						})
						
					}
				})
			},
			// 验证是否填写登录信息
			verificationLogin(){
				if(this.resetcode){
					this.isLogin=false
				}else{
					this.isLogin=true
				}
			},
			// getcode(){
			// 	this.isShow = false
			// 	let data ={
			// 		_action:'sendresetcode',
			// 		username:this.username
			// 	}
			// 	defaultRequest2(data).then(res =>{
			// 		console.log(res,'ppppp')
			// 	})
			// }
		},
		onLoad(e) {
			console.info(e)
			this.type=e.type
			if(e.type!=0){
				// this.query.password=e.password
				this.query.username=e.email
			}else{
				
			}
			this.username=e.email
			this.sendresetcode()
		}
	}
</script>
<style lang="scss">
	page{
		border-top: 13.33rpx #F7F7F7 solid;
		padding-top: 49.33rpx;
	}
</style>
<style lang="scss" scoped>
	.verify_tips{
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 52rpx;
	}
	.tips{
		margin: 44rpx 0;
	}
	.login_submit{
		margin-bottom: 33.33rpx;
	}
	.verify_text{
		font-size: 24rpx;
		text-align: center;
		font-weight: bold;
	}
	.verify_popup{
		width: 540rpx;
		height: 366.67rpx;
		position: fixed;
		left: 50%;
		margin-left: -270rpx;
		top: 50%;
		margin-top: -190rpx;
		background-color: white;
		border-radius: 20rpx;
		z-index: 999;
		box-sizing: border-box;
		padding:15rpx 22rpx;

		.verify_popup_close{
			text-align: right;
			
			image{
				width: 40rpx;
				height: 40rpx;
			}
		}
		.verify_popup_title{
			font-size: 40rpx;
			font-weight: 600;
			text-align: center;
			margin-bottom: 40rpx;
		}
		.verify_popup_msg{
			font-size: 26.67rpx;
			font-weight: 400;
			margin-bottom: 40rpx;
			text-align: center;
		}
		.verify_popup_btn{
			text-align: center;
			
			button{
				width: 321.33rpx;
				height: 56rpx;
				border-radius: 28rpx;
				background-color: black;
				color: white;
				border: none;
				font-size: 26.67rpx;
				font-weight: bold;
				line-height: 56rpx;
			}
		}
	}
</style>