<%@ page language="java" pageEncoding="UTF-8"
		 contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String basePath = request.getContextPath();
%>
<!doctype html>
<html>
<head>
	<jsp:include page="../common/head.jsp"></jsp:include>
<meta charset="utf-8">
<title>注册</title>
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/resource/css/open/register.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/resource/css/open/base.css">
</head>

<body>
	
		<div class="top01"><!---头部-->
			<div class="top01-main">
				<div class="top-left">
					<img onclick="javascript:window.location.href='<%=basePath%>/open/'" src="<%=basePath%>/resource/images/logo_min.png" class="logo">
					<h1 class="top-font-1" onclick="javascript:window.location.href='<%=basePath%>/open/'">衡水大数据</h1>
					<span class="top-font-2">欢迎注册</span> 
				</div>
				<div class="top-right">
					<span class="top-font-3">
					已有账户？
					</span>
					<span onclick="javascript:window.location.href='<%=basePath%>/open/account/login.htm'" class="top-font-4">
						请登录
					</span>
				</div>
			</div>
		</div>
		<div class="mid09"><!---注册表-->
			<div class="mid09-main">
				<form id="registerFrom" method="post" action="<%=basePath%>/share/account/register.action">
					<div class="div10">
						<span class="div1-font-1"><span class="xinghao" >*</span>用户名</span>
						<input name="username" type="text" placeholder="请输入用户名" >
					</div>
					<div id="name" class="tishi" hidden>! &nbsp该用户名已被注册</div>
					<div id="showOrHide" style="display: none">
					<div class="shoujihao1">
						<span class="div1-font-1">
							<span class="xinghao" >*</span>手机号
						</span>
						<div class="div2">
							<div class="div1-left">
								<span class="div1-left-font">+86</span>
							</div>
							<%--<input type="text" id="phone" placeholder="用户名/手机号" class="shoujihao">--%>
							<input type="text" id="phone" name="phone" onkeyup="(this.v=function()
							{this.value=this.value.replace(/[^0-9-]+/,'');})
							.call(this)" onblur="this.v();"  class="shoujihao">
						</div>
					</div>
					<div class="tishi" id="shouji"></div>
					<div class="div10">
						<span class="div1-font-1"><span class="xinghao" >*</span>验证码</span>
						<div class="div3">
							<input type="text" id="code"  placeholder="验证码" class="input2">
							<%--<div class="div4">获取验证码</div>--%>
							<input type="button" style="background-color: #2251ac;width: 115px;height: 38px;margin-left: 9px;float: left;color: #ffffff" id="code_btn" value="获取验证码">
						</div>
					</div>
					<div class="tishi" id="codeTishi"></div>
					</div>
					<div class="div10">
						<span class="div1-font-2"><span class="xinghao">*</span>登录密码</span>
						<input name="password" type="password" placeholder="请输入密码" class="input">
					</div>
					<div class="div10">
						<span class="div1-font-2"><span class="xinghao">*</span>确认密码</span>
						<input name="password1" type="password" placeholder="请再次输入密码" class="input">
					</div>
					<div id="mima" class="tishi" hidden>! &nbsp两次输入的密码不一致</div>
					<div class="div5">
						<input id="cbAgreement" type="checkbox" class="checkbox" checked="checked">
						<span class="div5-font">我已阅读并接受</span><a class="xieyi" target="_blank" href="<%=basePath%>/open/static/agreement_register">《平台注册协议》</a>
					</div>
					<div class="clearfix"></div>
					<div class="zhuce">
						<span class="lijizhuce" id="btn_register" onclick="nowRegister()">立即注册</span>
					</div>
				</form>
				<div class="line8"></div>
			</div>
		</div>
		<div class="foot001"><!---底部-->
			<div class="foot01">
				<p class="foot01-main">
					<a href="<%=basePath%>/open/static/about" >关于我们</a>
					<span class="span"></span>
					<a href="<%=basePath%>/open/static/about">联系我们</a>
					<span class="span"></span>
					<a href="<%=basePath%>/open/static/help_guidance">新手指导</a>
					<span class="span"></span>
					<a href="<%=basePath%>/open/static/help_api_use">API使用</a>
					<span class="span"></span>
					<a href="<%=basePath%>/open/static/help_microapp_use">微应用使用</a>
					<span class="span"></span>
					<a href="<%=basePath%>/open/static/help_question">常见问题</a>
					<span class="span"></span>
					<a href="javascript:void(0);">技术支持</a>
					<span class="span"></span>
				</p>
				<p class="banquan1">Copyright&copy;2017-2018 衡水市建设投资集团有限公司 版权所有</p><%--衡水.com--%>
			</div>
		</div>
		<script type="text/javascript">

			var falg = false ;
            //获取验证码
            $(function() {

                $.post("<%=basePath%>/open/account/isSecurityCode.action",function (data) {
                    falg = data ;
					if (data){
					    $("#showOrHide").show() ;
					}else {
                        $("#showOrHide").hide() ;
					}
                },"json") ;

                $("#code_btn").on("click", function() {
                    var phone = $("#phone") ;
                    if(!isPoneAvailable(phone)) {
                        $("#shouji").html("<font color='red'>请输入正确的手机号！</font>");
                        $("#btn_register").attr("disabled",true);
                        return false;
                    }
                    $("#shouji").empty() ;
                    $("#btn_register").attr("disabled",false);
                    $.ajax({
                        type: 'POST',
                        url: "<%=basePath%>/open/account/validatePhone.action", // 请求的action路径
                        data: {
                            phone: $("#phone").val()
                        },
                        dataType: "json",
                        success: function(data) {
                            if (data.stateCode==200){
                                alert('发送成功，请注意查收！') ;
                            }else{
                                alert(data.msg) ;
                            }
                        }
                    });
                    addCookie("secondsremained", 60, 60); //添加cookie记录,有效时间60s
                    settime($("#code_btn")); //开始倒计时
                })
                var v = getCookieValue("secondsremained") ? getCookieValue("secondsremained") : 0;//获取cookie值
                if(v > 0) {
                    settime($("#code_btn")); //开始倒计时
                }
            })

            function isPoneAvailable($poneInput) {
                var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
                if (!myreg.test($poneInput.val())) {
                    return false;
                } else {
                    return true;
                }
            }


            //发送验证码时添加cookie
            function addCookie(name, value, expiresHours) {
                var cookieString = name + "=" + escape(value);
                //判断是否设置过期时间,0代表关闭浏览器时失效
                if(expiresHours > 0) {
                    var date = new Date();
                    date.setTime(date.getTime() + expiresHours * 1000);
                    cookieString = cookieString + ";expires=" + date.toUTCString();
                }
                document.cookie = cookieString;
            }
            //修改cookie的值
            function editCookie(name, value, expiresHours) {
                var cookieString = name + "=" + escape(value);
                if(expiresHours > 0) {
                    var date = new Date();
                    date.setTime(date.getTime() + expiresHours * 1000); //单位是毫秒
                    cookieString = cookieString + ";expires=" + date.toGMTString();
                }
                document.cookie = cookieString;
            }


            //根据名字获取cookie的值
            function getCookieValue(name) {
                var strCookie = document.cookie;
                var arrCookie = strCookie.split("; ");
                for(var i = 0; i < arrCookie.length; i++) {
                    var arr = arrCookie[i].split("=");
                    if(arr[0] == name) {
                        return unescape(arr[1]);
                        break;
                    }
                }


            }


            //开始倒计时
            var countdown;
            function settime(obj) {
                countdown = getCookieValue("secondsremained");
                var tim = setInterval(function() {
                    countdown--;
                    obj.attr("disabled", true);
                    obj.attr("value", "重新发送(" + countdown + ")");
                    if(countdown <= 0 ) {
                        clearInterval(tim);
                        $(obj).removeAttr("disabled");
                        $(obj).attr("value", "重新发送");
                    }
                    editCookie("secondsremained", countdown, countdown + 1);
                }, 1000) //每1000毫秒执行一次


            }



			function nowRegister() {
			    if (!$("#cbAgreement").is(":checked")){
			        alert("请阅读并勾选《平台注册协议》");
			        return;
				}
				//进行验证码校验
				if (falg){
                    $.post("<%=basePath%>/open/account/isCode.action",{"phone":$("#phone").val(),"code":$("#code").val()},function (data) {
                        if (data.stateCode==200){
                            $("#codeTishi").empty() ;
                            $("#btn_register").attr("disabled",false);
                            $.post("<%=basePath%>/open/account/register.action",$("#registerFrom").serialize(),function (datas) {
                                if (datas.ms=='参数不能为空'){
                                    swal("参数不能为空") ;
                                }else if (datas.msg=='密码不一致'){
                                    $("#mima").show() ;
                                }else if (datas.msg=='用户名已存在'){
                                    $("#name").show() ;
                                } else if(datas.stateCode==200){
									swal("注册成功") ;
                                    window.location.href='<%=basePath%>/open/account/login.htm' ;
                                }else {
									swal(datas.msg) ;
                                }
                            },"json") ;
                        }else {
                            $("#codeTishi").html("<font color='red'>"+data.msg+"</font>");
                            $("#btn_register").attr("disabled",true);
                            return false;
                        }
                    },"json") ;
				}else {
                    $.post("<%=basePath%>/open/account/register.action",$("#registerFrom").serialize(),function (datas) {
                        if (datas.ms=='参数不能为空'){
							swal("参数不能为空") ;
                        }else if (datas.msg=='密码不一致'){
                            $("#mima").show() ;
                        }else if (datas.msg=='用户名已存在'){
                            $("#name").show() ;
                        } else if(datas.stateCode==200){
							swal("注册成功") ;
                            window.location.href='<%=basePath%>/open/account/login.htm' ;
                        }else {
							swal(datas.msg) ;
                        }
                    },"json") ;
				}

            }
		</script>
</body>
</html>
