<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + path+"/";
	request.setAttribute("contextPath", basePath);
	
	String redirectUrl= request.getParameter("redirectUrl");
	request.setAttribute("redirectUrl", redirectUrl);
%>
<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>忘记密码</title>
    <c:set var="path" value="${pageContext.request.contextPath}" />
    <script src="${contextPath }app/lib/flexible.js"></script>
    <script type="text/javascript" src="${contextPath }res/js/jquery.min.js"></script>
    <script type="text/javascript" src="${contextPath }res/js/layer/layer.min.js"></script>
    <link rel="stylesheet" href="${contextPath }app/lib/flexible.css">
	<link rel="stylesheet" href="${contextPath }app/css/basem.css">
	<link rel="stylesheet" href="${contextPath }app/css/logome.css">
	<script type="text/javascript">
	
	var timeid, remainTime;
	function calcTime() {
		remainTime--;
		if (remainTime > 0) {
			$('#loginForm p[data-action="getcode"]').text("(" + remainTime + "秒)");
		} else {
			window.clearInterval(timeid);
			$('#loginForm p[data-action="getcode"]').text("获取验证码");
			$('#loginForm p[data-action="getcode"]').removeAttr("disabled");
		}
	}

	$(function(){
		
		var $loginForm = $('#loginForm');
		
		$('#loginForm p[data-action="getcode"]').click(function() {				
			var phone=$loginForm.find("input[name='phone']").val();				
			if(phone=='' || phone=='请输入11位手机号码')
			{
				layer.msg("请输入正确的手机号！");
				return false;
			}	
			if(!checkMobile(phone)){
				return;
			}
			
			if($('#loginForm p[data-action="getcode"]').attr("disabled")){
				return;
			}
			$('#loginForm p[data-action="getcode"]').attr("disabled","true");
			var parm='{"phone":"'+phone+'" ,"type":"2"}'
			$.post('${contextPath}rest/mgmUser/getCode.cs',{
				"data":parm
			}, function(data) {1
				if (data.ret == 1) {
					remainTime = 60;
					timeid = window.setInterval("calcTime()", 1000);
				} else { 
					layer.msg(data.msg);
					$('#loginForm p[data-action="getcode"]').removeAttr("disabled");
				}
			}, "json");
		});
		 
 		$('#button').click(function(){ 
			var phone=$("input[name='phone']").val();
			var code=$("input[name='code']").val();
			var password=$("input[name='password']").val();
			var password2=$("input[name='password2']").val();
			if(phone==''){
				layer.msg("请输入手机号！");
				return ;
			}
			if(code=="" || code==null){
				layer.msg("请输入验证码！");
				return ;
			}
			if(password=="" || password2==""){
				layer.msg("请输入新密码！");
				return ;
			}
			if(password!=password2){
				layer.msg("两次密码不一致！");
				return ;
			} 
			 
			var parm='{"phone":"'+phone+'" ,"code":"'+code+'","pwd":"'+password+'","oldPwd":"'+password2+'"}'
			//忘记密码
			$.post('${contextPath}web/mgmUserCtl/forgetPWD.cs', {
				"data" : parm
			}, function(data) {
				var datas=eval(data.data);
				if (data.ret == 1) {
					 layer.msg(data.msg+',跳转到登录！', {
						  time: 1000
						}, function(){
							  window.location.href = '${contextPath }app/login/login.jsp';
						});
				} else { 
					layer.msg(data.msg);
				}
			}, "json");
		}); 
		
		function checkMobile(sMobile){ 
			//手机号正则  
			var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;  
			//电话  
			var phone = $.trim(sMobile);  
			if (!phoneReg.test(phone)) {  
			    alert('请输入有效的手机号码！');  
			    return false;  
			} 
				return true;
		}
	}); 
	
	</script>
</head>
<body>
	<div class="titbox">
		<a class="titreturn left" href="${contextPath }app/login/login.jsp"><img src="${contextPath }app/img/return1@2x.png" alt=""></a>
		<h1>忘记密码</h1>
	</div>
	<div class="forgetbox top50">
		<div class="safe">
		<form action="#" name="loginForm" id="loginForm" method="post">
			<ul class="logul">
				<li>
					<div><img class="logicon" src="${contextPath }app/img/iphone@2x.png" alt=""><span>手机</span></div>
					<input type="text" name="phone" placeholder="请输入您的手机号">
				</li>
				<li>
					<div><img class="logicon" src="${contextPath }app/img/yanz@2x.png" alt=""><span>验证码</span></div>
					<div class="logclean">
						<input class="left"  name="code" type="text" placeholder="请输入验证码">
						<p data-action="getcode" class="right">获取验证码</p>
					</div>
				</li>
				<li>
					<div><img class="logicon" src="${contextPath }app/img/pw@2x.png" alt=""><span>密码</span></div>
					<input type="password" name="password" placeholder="请重新设置您的登录密码">
				</li>
				<li>
					<div><img class="logicon" src="${contextPath }app/img/pw@2x.png" alt=""><span>密码</span></div>
					<input type="password" name="password2" placeholder="请再次输入您的新密码">
				</li>
			</ul>
			<a class="redbtn" href="javascript:void(0);" id="button">完成</a>
		</form>
		</div>
	</div>
</body>
</html>