{{include file=Main_View('head')}}
<div class="main_content">
	<fieldset class="layui-elem-field layui-field-title">
		<legend>会员密码找回</legend>
	</fieldset>
	<form class="layui-form" method="post">
		<if condition="C('login|login.recaption_method')==0">
		<table class="layui-table" >
			<tr>
				<td>用户名</td>
				<td>
					<input type="text" value="" placeholder="输入需要找回密码的用户名" class="layui-input my-input" name="username" />
				</td>
			</tr>
			<if condition="C('login|LOGIN.forgot_is_email')">
			<tr>
				<td>email</td>
				<td>
					<input type="email" placeholder="输入需要找回密码的email" class="layui-input my-input" name="email" />
				</td>
			</tr>
			</if>
			<if condition="C('login|LOGIN.forgot_is_yzm')">
			<tr>
				<td>验证码</td>
				<td>
					<input type="text" placeholder="" class="layui-input w100 left" name="yzm" />
					<img src="/Verification_Code{{C('HTML')}}" alt="点击图片更换验证码" title="点击图片更换验证码" class="left ml10"  onclick="this.src='/Verification_Code{{C('HTML')}}?'+Math.random();"/>
				</td>
			</tr>
			</if>
			<tr>
				<td colspan="2" align="center" class="login_input">
					<input type="hidden" name="step" value="post" />
					<button class="layui-btn layui-btn-normal">立即重设</button>
				</td>
			</tr>
		</table>
		<else>
			<table class="layui-table" >
				<tr>
					<td width="150" align="right">用户名</td>
					<td>
						<input type="text" id="username" value="" placeholder="输入需要找回密码的用户名" class="layui-input my-input" name="username" />
					</td>
				</tr>
				<tr>
					<td align="right">注册时使用的手机号码</td>
					<td>
						<input type="text" value="" id="mobile" lay-verify='mobile' placeholder="手机号码" class="layui-input left w120" name="mobile" />
						<span class="left ml10 reg_code">验证码：</span>
						<input type="text" class="layui-input w100 left ml10" name="code" id="code" />
						<button id="reg_code_post" class="layui-btn layui-btn-normal left ml10" lay-submit lay-filter="reg_code_post">获取验证码</button>
						<script>
							layui.use(['layer','form'], function(){
								var form = layui.form;
								var layer = layui.layer;
								form.on('submit(reg_code_post)', function(data){
									var username=$('#username').val();
									if(!username){
										layer.tips('用户名不能为空', '#username');
										return false;
									}
							    	var mobile=$('#mobile').val();
							    	var reg = new RegExp('^1[3|4|5|7|8][0-9]{9}$');
							    	if(!reg.test(mobile)){ //正则验证不通过，格式不对
									　　layer.tips('手机号码不正确', '#mobile');
									　　return false;
									}
							    	layer.open({
										type: 1,
										title:"验证码输入",
										content: $('#table_mobile'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
										success:function(){
											$('#mobile_yzm_img').click();
										}
							    	});
							    	return false;
							  	});
							  	
							  	form.on('submit(mobile_yzm_post)', function(data){
							  		var mobile=$('#mobile').val();
							  		var username=$('#username').val();
							  		var mobile_yzm=$('#mobile_yzm').val();
							  		$.ajax({
										url: "/login/index/forgot_mobile_code/",
										type: 'POST',
										data: {
											'username':username,
											'mobile': mobile,
											'yzm':mobile_yzm
										},
										dataType: 'json',
										success: function(res) {
											if(res.code=='0'){
												if($('#yzmimg')){
													$('#yzmimg').click();
												}
												layer.closeAll();
												setIntervals();
												layer.tips('请打开手机查看验证码', '#code');
											}else if(res.code=='9'){
												$('#mobile_yzm_img').click();
												layer.tips(res.text, '#mobile_yzm');
											}else{
												layer.closeAll();
												layer.alert(res.text);
											}
											$('#mobile_yzm').val('');
										}
									});
							    	return false;
							  	})
							})
							var timer='';
							function setIntervals(){
								$('#reg_code_post').html('剩余<span id="timer">{{C('login|LOGIN.mobile_put_time') ? C('login|LOGIN.mobile_put_time') : 60}}</span>秒');
								$('#reg_code_post').attr('disabled','disabled');
								$('#reg_code_post').attr('class','layui-btn layui-btn-primary left ml10');
								timer=window.setInterval(function(){runtimer();},1000);
							}
							function runtimer() {
						        var s = document.getElementById("timer");
						        if(s.innerHTML==1){
						        	$('#reg_code_post').html('获取验证码');
						        	$('#reg_code_post').attr('class','layui-btn layui-btn-normal left ml10');
						        	$('#reg_code_post').removeAttr('disabled');
						        	window.clearInterval(timer); 
						        }else{
						        	 s.innerHTML = s.innerHTML * 1 - 1;
						        }
						       
							}
						</script>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center" class="login_input">
						<input type="hidden" name="step" value="password" />
						<button class="layui-btn layui-btn-normal">下一步</button>
					</td>
				</tr>
			</table>

			<table class="layui-table" id="table_mobile" style="display: none;">
				<tr>
					<td>请输入验证码</td>
					<td> 
						<input type="mobile_yzm" class="layui-input w100 left" name="mobile_yzm" id="mobile_yzm" value="" />
						<img id="mobile_yzm_img" src="/Verification_Code{{C('HTML')}}" alt="点击图片更换验证码" title="点击图片更换验证码" class="left ml10"  onclick="this.src='/Verification_Code?'+Math.random();"/>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<button class="layui-btn layui-btn-normal" lay-submit lay-filter="mobile_yzm_post">确定</button>
					</td>
				</tr>
			</table>

		</if>
	</form>
</div>
{{include file=Main_View('foot')}}