<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="keywords" content="酷医云,酷医聚客,病人关系管理,微信管理平台,肾病科宣,慢病管理云平台,SCRM,SPRM,血透管理,科室品牌推广">
    <meta name="description" content="酷医云，是专为肾科和血透中心研发的免费血透管理平台，覆盖诊前、诊中、诊后全流程管理；为血透中心提供覆盖智能营销管理、血透管理、慢病管理、医患沟通、进销存管理以及商城管理等全流程一体化的管理平台。全国数百家血透中心信赖的选择。">
    <title>酷医云-注册</title>
    <link rel="stylesheet" href="/static/css/mobile.css?v=1.0.0">
    <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?7577c975fa7ae685efd61deb009d1b5b";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
</head>

<body>
    <div class="loginBox">
        <h2 class="title">注册账号</h2>
        <div class="reg_wrap">
            <form action="" class="reg">
                <div class="cell">
                    <input id="mobile" type="text" class="input_box " placeholder="手机号码">
                </div>
                <div class="cell">
                    <input id="code" type="text" class="input_box" placeholder="验证码">
                    <span id="codebtn" class="code">获取验证码</span>
                </div>
                <div class="cell">
                    <input id="password" type="text" class="input_box " placeholder="密码">
                </div>
                <input type="hidden" id="aespass" value="{{ .aespass }}">
            </form>
            <div class="join">
                <button id="registbtn" class="submit">即刻开始</button>
            </div>
        </div>
    </div>
    <!-- 弹出框 -->
    <div class="layer" style="display: none;">
        <div class="layerBg"></div>
        <div class="content">
            <div class="tit">
                <h3>提示</h3>
                <div class="close"><img src="/static/images/mobile_site/close.png" alt=""></div>
            </div>
            <span class="tips">您的手机号码已经注册过，请使用电脑谷歌浏览器访问酷医云，并登录使用</span>
        </div>
    </div>

    <!-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> -->
    <script src="/static/js/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="/static/js/layer.js"></script>
    <script src="/static/js/md5.js"></script>
    <script src="/static/js/common.js"></script>
    <script type="text/javascript">
    $(function() {
        $('.close').click(function(){
            $('.layer').fadeOut(300);
        });

        $("#codebtn").click(function() {
            var phone = $("#mobile").val();
            var aespass = $('#aespass').val();

            if (!checkPhone(phone)) {
                return;
            }

            var postData = {
                phone: phone,
                aespass: aespass,
            }
            $("#codebtn").attr("disabled", true);

            postRequest("/getregistcode", postData, function(res) {
                if (res.state == 0) {
                    if (res.code == 604) {
                        $('.layer').show();
                    } else {
                        serverErrorMsg(res);
                    }
                    return;
                }
                changeNum(60);
                layer.msg(res.data.msg);
                $("#codebtn").attr("disabled", false);

            }, function(res) {
                serverErrorMsg(res);
                $("#codebtn").attr("disabled", false);
            });
        });

        //确定
        $("#registbtn").click(function() {
            var code = $("#code").val();

            if (code != null && code != undefined && code != "") {
                var mobile = $("#mobile").val();
                var password = $("#password").val();

                if (canSure(mobile, password)) {
                    $("#registbtn").attr("disabled", true);

                    var postData = {
                        mobile: mobile,
                        password: hex_md5(password),
                        code: code,
                    }

                    postRequest("/mobile/regist/submit", postData, function(res) {
                        $("#registbtn").attr("disabled", false);
                        if (res.state == 0) {
                            serverErrorMsg(res);
                            return;
                        }
                        layer.msg("注册成功");
                        window.location.href = "/mobile/org/create"; //跳转网址

                    }, function(res) {
                        $("#registbtn").attr("disabled", false);
                        serverErrorMsg(res);
                    });

                } else {
                    return;
                }
            }
        });
    });

    function checkPhone(phone) {
        if (!phone || phone == "") {
            layer.msg("手机号码不能为空");
            return false;
        }

        if (!(/^1\d{10}$/.test(phone))) {
            layer.msg("手机号码有误，请重填");
            return false;
        }
        return true;
    }

    function canSure(phone, password) {
        if (!phone || phone == "") {
            layer.msg("手机号码不能为空");
            return false;
        }

        if (!password) {
            layer.msg('密码为空');
            return false;
        }

        if (password.length < 6) {
            layer.msg('密码至少要6位数');
            return false;
        }
        return true;
    }

    function changeNum(num) {
        setTimeout(function() {
            if (num > 1) {
                $('#codebtn').html(num + "s");
                --num;
                changeNum(num);
            } else {
                $('#codebtn').html("发送验证码");
                $("#codebtn").attr("disabled", false);
            }
        }, 1000);
    }
    </script>
</body>
</html>
