<%@ page language="java" pageEncoding="utf-8"%>
<%@ page language="java" import="com.fadu.web.util.Constant" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% 
	String token = (String)session.getAttribute(Constant.Session.TOKEN) ;
	String openid = (String)session.getAttribute(Constant.Session.DWLSD_OPENID);
	String preUrl = (String)session.getAttribute(Constant.Request.PREURL);
%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="wap-font-scale" content="no">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>多问</title>
    <script type="text/javascript" src="${contextPath}/static/js/flexible.min.js"></script>    
    <link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/sb/css/sprite.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/sb/css/common.css">
    <link rel="stylesheet" type="text/css" href="${contextPath}/static/weixin/sb/css/main.css">
</head>
<body class="bg-white">
	<div class="page">
		<header class="pad-lr-30 ub ub-ac text-center form-header">
			<p class="width100 fc-blue fs-16">忘记密码</p>
			<a href="javascript:history.back(-1);" class="form-back">
				<span class="icon icon-back-blue"></span>
			</a>
		</header>
		<div class="password-center">
			<form class="pad-l-30 login-form">
				<div class="pad-t-25 pad-b-15 pad-r-30 pos-relate br-bottom1 ub ub-ac">
					<label class="fc-dgrey">手机号：</label>
					<input type="tel" name="phone" id="phone" class="pad-lr-10 ub-f1 form-control">
					<a href="javascript:void(0)" class="fc-blue get-code" id="getValidCode">获取验证码</a>
					<a href="javascript:void(0)" class="fc-blue get-code hide" id="djs">重获(60秒)</a>	
				</div>
				<div class="pad-t-25 pad-b-15 pad-r-30 pos-relate br-bottom1 ub ub-ac">
					<label class="fc-dgrey">验证码：</label>
					<input type="tel" name="code" id="code" class="pad-lr-10 ub-f1 form-control">
				</div>
			</form>
			<a href="#" class="mar-lr-30 mar-t-50 btn-blue block fs-20 btn-submit-password">提交处理</a>
		</div>
	</div>

  	<script type="text/javascript" src="${contextPath}/static/js/jquery-1.12.0.min.js"></script>
  	<script type="text/javascript" src="${contextPath}/static/weixin/common/js/toast.js"></script>
  	<script type="text/javascript" src="${contextPath}/static/weixin/sb/js/main.js"></script>
 	<script type="text/javascript" src="${contextPath}/static/weixin/cd/js/util.js"></script>
 	<script type="text/javascript">
 	$(document).ready(function() {
 		$("#getValidCode").click(function(){
		  	var phone=$("#phone").val();
			if(!checkPhone(phone)){
				return;
			}
  			var b007 = {
				actionCode:"B007",
				mobile:phone,
				type:22				
  			}
	  		postData("${contextPath}/B/android/", JSON.stringify(b007), getValidCodeSucc, fail);
  		}); 		
 		$(".btn-submit-password").click(function(){
 			var phone=$("#phone").val();
			if(!checkPhone(phone)){
				return;
			}
			var code = $("#code").val();
			if(code==null||code==""){
				toast1.alert("请输入验证码！");
				return;
			}
  			var b008 = {
				actionCode:"B008",
				mobile:phone,
				type:22,
				code:code
  			}
	  		postData("${contextPath}/B/android/", JSON.stringify(b008), b008Succ, fail);
 		});
   	});
 	
 	function b008Succ(data){
 		if(data){
 			if(data.success){
 				toast1.alert("验证通过");
 	    		setTimeout(function(){
 	   				$(".login-form").attr("action", "${contextPath}/wx/toChangePasswd").submit();
 		        },2000);
 			}else{
 				toast1.alert(data.message);
 			}
 		}else{
 			toast1.alert('网络异常！');
 		}
 	}
 	
 	/*获取验证码按钮*/
	function codeTimer(obj,str){
		var time = obj.text().slice(3,-2);
		time = parseInt(time);
		time-=1;
		if(time<10){
			time = "0" + time;
		}
		obj.text("重获("+time+"秒)");
		if(time == 0){
			$("#getValidCode").removeClass("hide").show();
  			$("#djs").addClass('hide').html("重获("+60+"秒)");
			return;
		}
		setTimeout(function(){
			codeTimer(obj,obj.text());
		},1000);
	}
 	
	function checkPhone(phone){ 
		if(phone){
			if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){ 
				toast1.alert("手机号码有误，请重填");
				return false; 
			}else{
				return true;
			}
		}else{
			toast1.alert("请输入手机号码");
			return false;
		}
	}
 	
 	function getValidCodeSucc(data){
 		if(data){
 			if(data.success){
 				$("#djs").removeClass('hide').show();
 				$("#getValidCode").addClass('hide');
 				codeTimer($("#djs"));
 				toast1.alert('验证码发送成功！');
 			}else{
 				toast1.alert(data.message);
 			}
 		}else{
 			toast1.alert('网络异常！');
 		}
 	}
	function fail(resp){
		console.log(resp);
	}
	//toast
	var toast1 = new toast({
        pos:'center'
    });	
  </script>
</body>
</html>