<template>
  <view class="container">
    <view class="login-wrap">
		<view class="login-form">
			<u--form
				labelPosition="left"
				:model="userInfo"
				:rules="rules"
				ref="form1"
			>
				<u-form-item
					label="手机号"
					prop="phonenumber"
					borderBottom
					labelWidth="auto"
					labelAlign="right"
				  >
				<u--input
					v-model="userInfo.phonenumber"
					placeholder="请输入账号绑定的手机号"
					border="bottom"
					type="number"
					maxlength="11"
				></u--input>
			  </u-form-item>
		  </u--form>
		</view>
	</view>
	<view @click="gotoRetrieveMethod()" class="op-btn-wrap">
		<view class="h-btn">
			<text>下一步</text>
		</view>
	</view>

	<!-- 密码正确 -->
	<u-popup :show="show" :round="10"  mode="center" >
	  <view class="h-popo-content">
		   <view class="h-img">
			   <u-icon name="/static/login/u01.png" color="red" size="50"></u-icon>
		   </view>
		   <view class="text">
			   <text>找回失败</text>
		   </view>
		   <view class="text">
			   <text>未查询到该手机号绑定的账号</text>
		   </view>
		   <view class="h-btn-wrap">
			   <view @click="sureClose" class="h-right-btn">
			   		<text>确定</text>
			   </view>
		   </view>
	  </view>
	</u-popup>

  </view>
</template>
 <script>
export default {
	data() {
		return {
			show: false,
			userInfo: {
				phonenumber: ''
			},
			rules: {
				phonenumber:{
					required: true,
					min: 10,
					max: 12,
					message: '请输入11位电话号码',
					trigger: ['blur', 'change'],
				},
			},
		}
	},
	onLoad() {

	},
	onReady() {
		this.$refs.form1.setRules(this.rules)
	},
	methods: {

		// 去选择找回方式
		gotoRetrieveMethod(){
			let that = this;
			this.$refs.form1.validate().then(res => {
				that.phoneIsExist();
			}).catch(errors => {
				uni.$u.toast('校验失败,请认真填写')
			})
		},
		sureClose(){
			this.show = false;
			uni.$u.route({
				url: '/pages/login/login',
				params: {
					name: 'lisa'
				}
			})
		},
		// 验证电话号码是否存在
		phoneIsExist(){
			let that = this;
			// 验证电话号码是否存在
			phoneIsExist(null,{data:this.userInfo}).then((res)=>{
				console.log(res)
				if(res.phoneIsExist){ // 存在
					uni.$u.route({
						url: '/pages/login/retrieve-method',
						params: {
							data: that.userInfo.phonenumber
						}
					})
				} else {
					that.show = true;
				}
			}).catch(() =>{
				uni.showToast({
					title: "操作失败"
				})
			});
		},
	}
}
</script>
<style lang="scss">
page,body{
	background: #fff;
}
.container{
	background: #fff;
	height: 300px;
	.login-wrap {
		display: flex;
		justify-content: center;
		.login-form{
			width: 90%;
		}
		.account{
			display: flex;
		}
		.identifying-code{
		}
	}
	.op-btn-wrap{
		margin-top: 30px;
		display: flex;
		justify-content: center;
		align-items: center;
		.h-btn{
			text-align: center;
			width: 343px;
			height: 42px;
			background: #FFE05C;
			border-radius: 27px;
			line-height: 42px;
		}
	}
}

.h-popo-content{
	height: 170px;
	padding: 12px;
	width: 300px;
	text-align: center;
	font-size: 14px;
	font-family: PingFangSC-Semibold, PingFang SC;
	.h-img{
		display: flex;
		justify-content: center;
	}
	.h-text{
		margin-top: 12px;
		font-weight: 400;
		color: #666666;
	}
	.text{
		margin-top: 6px;
		font-weight: 400;
		color: #666666;
	}
	.h-btn-wrap{
		display: flex;
		justify-content: space-between;
		color: #333333;
		text-align: center;
		margin-top: 14px;
		.h-left-btn{
			height: 32px;
			line-height: 30px;
			background: #EEEEEE;
			width: 100px;
			text-align: center;
			border-radius: 16px;
			margin: 0 auto;
		}
		.h-right-btn{
			height: 32px;
			line-height: 30px;
			background: #FFE05C;
			width: 100px;
			border-radius: 16px;
			margin: 0 auto;

		}
	}
}
</style>
