<?php $this->display(tpl('head')); 
	$renzheng=unserialize(C('renzheng'));
?>
<style>
	body{
		background-color: #ddd;
	}
	.list,.yz_content{
		float: left;
		width: 98%;
		background: #fff;
		margin: 1%;
	}
	.list ul{
		float: left;
		padding: 10px;
	}
	.list ul a{
		float: left;
		border:1px solid #009688;
		color: #009688;
		padding: 5px 10px;
		margin: 10px 10px 10px 0;
	}
	.list ul a:hover,.list ul a.hover{
		background: #009688;
		color: #fff;
	}
	.yz_content .sort{
		float: left;
		padding: 1%;
		width: 98%;
		border-bottom: 1px solid #ddd;
		font-weight: bolder;
	}
	.yz{
		float: left;
		width: 100%;
		margin-top: 10px;
	}
	.yz .layui-form-label{
		width: 100px;
	}
	.yz .layui-input{
		width: 200px;
	}
	.yz .yzm .layui-input{
		width: 60px;
	}
	.layui-input-block span{
		float: left;
	}
	.layui-input-block span:last-child{
		margin-left: 10px;
	}
	.ok{
		text-align: center;
		padding: 20px;
		font-size: 16px;
	}
	.ok span{
		padding:0 5px;
		color: red;
		font-weight: bolder;
	}
</style>

<div class="list">
	<ul>
		<foreach array="list">
			<php> $hover=$_GET['type'] && $_GET['type']==$row['dir'] ? 'hover' : $key=='0' && !$_GET['type'] ? 'hover' : ''</php>
			<a class="{{$hover}}" href="/user/renzheng/index/type/{{$row['dir']}}">{{$row['name']}}</a>
		</foreach>
	</ul>
</div>
<div class="yz_content">
	<div class="sort">Email验证</div>
	<div class="yz">
		<if condition="C('mydb.email_rz_state') =='1'">
			<div class="ok">您的邮箱“<span>{{C('MYDB.email')}}</span>”已通过验证</div>
		<else>
		<form class="layui-form">
			<div class="layui-form-item">
			    <label class="layui-form-label">请输入Email</label>
			    <div class="layui-input-block">
					<input type="email" id="email" name="email"  value="{{C('MYDB.email')}}" class="layui-input" placeholder="请输入你的Email进行验证"/>
			    </div>
			</div>
			<if condition="$renzheng['email']['is_yzm']">
			<div class="layui-form-item">
			    <label class="layui-form-label">验证码</label>
			    <div class="layui-input-block yzm">
					<span><input type="text" name="yzm" class="layui-input"/></span>
					<span class="yzmcode">
						<img src="{{WEBURL}}/verification_code{{c('html')}}"   onclick="this.src='{{WEBURL}}/verification_code{{c('html')}}?'+Math.random();">
					</span>
			    </div>
			</div>
			</if>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="*">确定</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		</if>
	</div>
</div>
<script>
	var data={};
	layui.use('form', function(){
		var form = layui.form;
		form.on('submit(*)', function(res){
			if(!res.field.email){
				layer.tips('Email不可为空或者Email格式错误', '#email');
				$('#email').focus();
			}
			data=res.field;
			data.type='email';
			data.json=true;
			$.ajax({
				url:"/user/renzheng/send/",
				type: 'POST',
				data:data,
				dataType: 'json',
				success: function(res){
					if(res.code==0){
						layer.prompt({
							value: '',
							title: 'Email认证码',
						}, function(value, index, elem){
							data.code=value;
							$.ajax({
								url:"/user/renzheng/approve/",
								type: 'POST',
								data:data,
								dataType: 'json',
								success: function(res){
									layer.msg(res.text);
									if(res.code==0){
										location.reload() ;
									}
								}
							})
						});
						layer.msg('Email验证码已发送，请注意查收');
					}else{
						layer.msg(res.text);
					}
				}
			})
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});

	});
</script>
<?php $this->display(tpl('foot')); ?>