<template>
	<view class="content">
		
		<view class="top">
			<view class="top-icon" @click="getback()">
				<uni-icons type="left" size="18"></uni-icons>
			</view>
			<view class="touxiang">
			<image src="../../static/xinlogo.png" mode=""></image>
			</view>
			<view class="twotap" >
				<view  :class="{'blck':activeid == index}" v-for="(item,index) in qh " :key="index" @click="getxz(index)">{{item.text}}</view>
			</view>
			<view class="inputs" v-if="activeid == 0">
				<input type="text" v-model="tel" placeholder="请输入手机号">
			</view>
			<view class="inputs" style="justify-content: space-between; " >
				<input type="text" v-model="yzm" placeholder="请输入验证码">
				 <button  class="jsq"  :disabled="isButtonDisabled" @click="sendVerificationCode">{{ buttonText }}</button>	 
			</view>
			<view class="inputs" >
				<input type="text" v-model="wrod" placeholder="请输入新密码">
			</view>
			
		
			
		</view>
		
		<view class="dl" @click="getzh()">
			<text>找回密码</text>
		</view>
		<view class="dbottom">
			
			<text>登录即代表您已同意</text>
			<text class="lan">《用户协议》</text>
			<text>和</text>
			<text class="lan">《隐私政策》</text>
		</view>
		
		
		
		
	</view>
</template>

<script>
	import request from '../../utils/request';
	export default{
		data(){
			return{
				phoneNumber: "",
				isButtonDisabled: false,
				countdownTime: 60,
				tel:'',
				wrod:'',
				yzm:'',
				qh:[
					{text:'忘记密码'},
				],
				activeid:0
			}
		},
		 computed: {
		    buttonText() {
		      if (this.isButtonDisabled) {
		        return `${this.countdownTime}s 后重新发送`;
		      } else {
		        return "获取验证码";
		      }
		    },
		  }, 	
		methods:{
			getback(){
			uni.navigateBack({
					delta:1,
				})	
			},
			getxz(index){
				this.activeid = index
				
			},
			getzh(){
				const data ={
					phone:this.tel,
					msgCode:this.yzm,
					password:this.wrod
				}
				request({
					url: '/updatePwd',
					method: 'post',
					params: data
				}).then((res)=>{
					console.log('修改请求',res);
					if(res.code == 200){
						uni.showToast({
							title:'修改成功',
							icon:'none'
						})
					}
				})
			},
			    sendVerificationCode() {
					let reg = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$/;
					if (!reg.test(this.tel)) {
						uni.showToast({
							icon: 'none',
							title: '请输入正确的11位手机号'
						})
						this.tel = '';
						return false;
					}
			      if (this.isButtonDisabled) {
			        return; // 如果按钮已禁用，则直接返回
			      }
			     const data = {
			     	  phone:this.tel,
			       }
			     request({
			       url: '/pwdSmsCode',
			       method: 'post',
			       params: data
			     }).then((res)=>{
			     	console.log('验证码',res);
			     	if(res.code == 200){
			     		uni.showToast({
			     			title:'验证码已发送 请注意查收',
			     			icon:'none'
			     		})
			     	}else{
			     		uni.showToast({
			     			title:'网络不佳请稍后再试',
			     			icon:'none'
			     		})
			     	}
			     })
			
			        this.disableButton(); // 禁用按钮
			        this.startCountdown(); // 启动倒计时
			     
			    },
			    disableButton() {
			      this.isButtonDisabled = true;
			    },
			    enableButton() {
			      this.isButtonDisabled = false;
			    },
			    startCountdown() {
			      let countdown = setInterval(() => {
			        this.countdownTime--;
			        if (this.countdownTime === 0) {
			          clearInterval(countdown);
			          this.enableButton(); // 启用按钮
			        }
			      }, 1000);
			    },
		}
	}
	
</script>

<style scoped lang="scss">
	.jsq{
		border: none !important;
		font-size: 14px;
		font-weight: 400;
		color: #0078FF;
	}
	button {
	  border: none !important;
	  background: none !important;
	  margin: 0px;
	   display: block;
	}
	button:focus {
		color: #0078FF;
	  outline: none;
	  box-shadow: none;
	}

	.content{
		box-sizing: border-box;
		
	}
	.top{
		box-sizing: border-box;
		padding: 0px 27px;
		padding-top: 45px;
		background-image: url('../../static/loginbj.png');
		background-size: cover;
		background-position: center;
		width: 100%;
	}
	.top-icon{
		margin-bottom: 45px;
	}
	.touxiang{
		width: 88px;
		height: 88px;
		border-radius: 10px;
		background: #D7D7D7;
		margin: 0 auto;
		margin-bottom: 40px;
		overflow: hidden;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.twotap{
		width: 100%;
		display: flex;
		align-items: center;
		view{
			font-size: 15px;
			font-family: Microsoft YaHei;
			font-weight: 400;
			color: #666666;
			margin-right: 38.5px;
		}
	}
	.blck{
		color: #333333 !important;
		font-weight: bold !important;
	}
	.inputs{
		box-sizing: border-box;
		padding: 16px 0px;
		display: flex;
		align-items: center;
		border-bottom: 2px solid #E8E8E8 ;
		margin-top: 20px;
	}
	.wjworb{
		margin-top: 5px;
		width: 100%;
		display: flex;
		font-size: 12px;
		color: #0078FF;
		justify-content: flex-end;
		align-items: center;
		
	}
	.dl{
		width: 90%;
		height: 44px;
		background: linear-gradient(-46deg, #0853C4 0%, #4282D8 80%);
		border-radius: 5px;
		margin: 0 auto;
		font-size: 16px;
		color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 22px;
	}
	.hging{
		width: 100%;
		text-align: center;
		font-size: 14px;
		font-weight: 400;
		color: #636363;
		margin-top: 20px;
	}
	.wx{
		width: 38px;
		height: 38px;
		overflow: hidden;
		box-sizing: border-box;
		margin: 0px auto;
		margin-top: 20px;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.hui{
		font-size: 10px;
		width: 100%;
		text-align: center;
		font-weight: 400;
		color: #666666;
	}
	.dbottom{
		width: 100%;
		margin: 0 auto;
		font-size: 12px;
		text-align: center;
		color: #333333;
		margin-top: 40px;
		position: fixed;
		bottom: 25px;
	}
	.lan{
		color: #0078FF;
	}
	
	
</style>