<style lang="scss" scoped>
	.JhphoneRz  {
		width: 100%;
		// height: 100vh;
		background: #FFF;
		.box{
			width: 100%;
			padding: 0 15px;
		}
		.box-item{
			width: 100%;
			margin-top: 40rpx;
			
		}
		.box-item-top{
			display: flex;
			align-items: center;
			font-size: 24rpx;
			color: #111111;
			
		}
		.imgstb{
			width: 11px;
			height: 15px;
			margin-right: 5px;
		}
		
		.box-item-b{
			width:100%;
			height:55px;
			border-bottom:1px solid #E2E2E2;
			display: flex;
			align-items: center;
			justify-content: space-between;
			input{
				margin-left: 15px;
			}
		}
		.yanbtn{
			width: 170rpx;
			height: 60rpx;
			border-radius: 4px;
			display: flex;
			align-items: center;
			justify-content: center;
			border: 1px solid #E2E2E2;
			font-size: 24rpx;
			color: #40766E;
		}
		.tijiao{
			width: 100%;
			height: 40px;
			background: #40766E;
			border-radius: 4px;
			margin-top: 100px;
			font-size: 14px;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	
</style>
<template>
	<div  class='JhphoneRz'>
		<view class="box" v-if="isAttestationEdu==0">
			<view style="font-size: 40rpx;color: #111111;margin-top: 40rpx;">请完成手机绑定验证</view>
			<view style="font-size: 24rpx;color: #999999;margin-top: 20rpx;">请获取验证码进行绑定</view>
			<view class="box-item" style="margin-top: 70rpx;">
				<view class="box-item-top">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhdianhua.png" class="imgstb"></image>
					<text>手机</text>
				</view>
				<view class="box-item-b">
					<input type="number" v-model="addMsg.StuTel" placeholder="请输入你的手机号">
				</view>
			</view>
			<view class="box-item">
				<view class="box-item-top">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhyanzm.png" class="imgstb"></image>
					<text>验证码</text>
				</view>
				<view class="box-item-b" >
					<input type="number" v-model="addMsg.Sendcode" placeholder="请输入你收到的验证码">
					<view class="yanbtn"  @click="getCode">{{show == true?btntext:daojis}}</view>
					
				</view>
			</view>
			<view class="tijiao" @click="tj()">
				提交绑定
			</view>
		</view>
		<view v-if="isAttestationEdu==1" style="width: 100%;display: flex;flex-direction: column;align-items: center;">
			<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/Jhrenzcg.png" style="width: 300rpx;height: 324rpx;margin-top: 256rpx;"></image>
			<text style="font-size: 20px;color: #111111;margin-top: 53px;">验证成功  成为学员</text>
		</view>
		<auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
	</div>
</template>

<script>
	
	
	import auth from "@/components/auth/index.vue";
	export default {
		components: {
			auth
		},
		data() {
			return {
				showAuth:false,
				u:{},
				mainColor: '',
				addMsg:{
					StuTel:'',
					Sendcode:'',
				},
				btntext:'获取验证码',
				show: true,
				count: '',
				timer: null,
				daojis:'60s',
				isAttestationEdu:0,//学员是否认证了 0否1是
			};
		},
		onLoad(options) {
			this.u = uni.getStorageSync("mall_UserInfo");
			if (!this.u) {
			  this.u = {
				nickName: "未登录",
				avatarUrl: ""
			  };
			  this.showAuth = true;
			}	else{
				
			}
			let basedata =uni.getStorageSync("basedata")?uni.getStorageSync("basedata"):'';
			this.isAttestationEdu = basedata.user_info.isAttestationEdu ? basedata.user_info.isAttestationEdu:0
			
			
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
		},
		mounted() {
			let pageTitle = '学员认证'
			let currentPages = getCurrentPages();
			let u = "/" + currentPages[currentPages.length - 1].route;
			let pages = wx.getStorageSync("basedata") ?
				wx.getStorageSync("basedata").bar_title : [];
				pages.forEach((x) => {
					if (x.value == u) {
						pageTitle = x.new_name ? x.new_name : x.name;
					}
				});
			uni.setNavigationBarTitle({
				title: pageTitle,
			});


		},
		methods: {
			getCode(){
				const TIME_COUNT = 60;
				if(this.addMsg.StuTel==''){
					uni.showToast({
						title:'请输入手机号码',
						icon:'none'
					})
					return
				}
				if(this.show==true){
					if (!this.timer) {
						this.getcodedata()//获取验证码
					  this.count = TIME_COUNT;
					  this.show = false;
					  this.timer = setInterval(() => {
					  if (this.count > 0 && this.count <= TIME_COUNT) {
						 this.count--;
						 this.daojis = this.count+'s'
						} else {
						 this.show = true;
						 clearInterval(this.timer);
						 this.timer = null;
						 this.btntext = '重新获取'
						 this.daojis = '60s'
						}
					  }, 1000)
					 }
				}else{
					console.log('不能操作')
				}
				 
			},
			getcodedata(){
				this.request2({
						url: '/api/AppletEducation/SendCodeByStudentInfo',
						data: {StuTel:this.addMsg.StuTel}
					},
					res => {
						if (res.resultCode == 1) {
							uni.showToast({
								title:'短信已发送,注意查收！',
								icon:'none'
							})
						}
					},
					error=>{
						this.show = true;
						clearInterval(this.timer);
						this.timer = null;
						this.btntext = '重新获取'
						this.daojis = '60s'
					}
				);
			},
			tj(){
				if(this.addMsg.StuTel==''){
					uni.showToast({
						title:'请输入手机号码',
						icon:'none'
					})
					return
				}
				if(this.addMsg.Sendcode==''){
					uni.showToast({
						title:'请输入验证码',
						icon:'none'
					})
					return
				}
				uni.showLoading({
				    title: '认证中'
				});
				this.request2({
						url: '/api/AppletEducation/CheckSendCode',
						data: this.addMsg
					},
					res => {
						uni.hideLoading()
						if (res.resultCode == 1) {
							uni.showToast({
								title:res.message,
								icon:'none'
							})
							this.isAttestationEdu = 1;
							this.getHome()
						}
					},
					error=>{
						uni.hideLoading()
					}
				);
			},
			
			
			reloadUserinfo() {
			  this.u = uni.getStorageSync("mall_UserInfo");
			  // this.showAuth=false;
				this.getHome()
			  
			},
			//关闭登录窗口
			gbAuth(){
				uni.navigateBack()
			},
			getHome(){
				this.request2({
						url: "/api/Mall/GetHome",
						data: {page_id: 0,open_school: 0,StoreId: 0},
					},
					(res) => {
						uni.setStorageSync("basedata", res.data);
						let basedata = wx.getStorageSync("basedata")
						this.isAttestationEdu = basedata.user_info.isAttestationEdu ? basedata.user_info.isAttestationEdu:0
					},
					(error) => {}
				);
			},

		}
	};
</script>

<style>

	
</style>
