<!DOCTYPE html>
<html lang=zh-cn>
<head>
    <meta charset=utf-8>
    <title>纵横计量支付系统</title>
    <meta name=description content=计量支付>
    <meta name=copyright content=smartcost.com.cn>
    <link rel=stylesheet href="{{rootUrl}}global/css/bootstrap.css">
    <link rel=stylesheet href={{rootUrl}}global/css/style.css>
    <script src={{rootUrl}}global/js/jquery-1.9.1.min.js></script>
    <script src={{rootUrl}}global/js/bootstrap.js></script>
    <script src={{rootUrl}}global/js/jl.js></script>
    <script src={{rootUrl}}global/js/jquery.cookie.min.js></script>
</head>
<body>
<!-- include "top" -->
<div class="wrapContent">
    <!-- include "left" -->
    <div class="mainContainer">
        <!--内容-->
        <div class="mainContent">
            <div class="title clearfix">
                <div class="fR">
                    <a class="btn btn-link" href="http://smartcost.com.cn/product/19" target="_blank"><i class="icon-question-sign"></i>&nbsp;帮助</a>
                </div>
            </div>
            <div class="form">
                <form class="form-horizontal">
                    <legend>短信通知</legend>
                    <!-- if {{smsNoticeSwitch}} < 1 -->
                    <!--管理员关闭功能-->
                    <div class="alert alert-danger">
                        短信通知功能已被关闭。
                    </div>
                    <!--管理员关闭功能-->
                    <!-- else -->
                    <!-- if {{uprofile.isnotice}} < 1 -->
                    <!--初次使用-->
                    <div class="alert alert-info">
                        初次使用，请先添加用于接收通知的手机号码。
                    </div>
                    <div id="input_error" class="form-group">
                        <label class="col-sm-1 control-label">添加手机</label>
                        <div class="col-sm-2">
                            <input class="form-control" id="mobile" name="mobile" type="text" placeholder="输入您的新手机号码"><span id="help-inline"
                                                                                                       class="help-block" style="display: none"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">短信校验码</label>
                        <div class="col-sm-2">
                            <input class="form-control" type="text" id="verifycode" name="verifycode" placeholder="输入验证码" maxlength="11"
                                   class="span2">
                        </div>
                        <div class="col-sm-2">
                            <input type="button" class="btn btn-default" id="getting" value="获取验证码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"></label>
                        <div class="col-sm-2">
                            <i class="icon-ok icon-white"></i><input type="button" id="addMobile"
                                                                     class="btn btn-primary" value="确定添加"/>
                        </div>
                    </div>
                    <!--初次使用-->
                    <!-- else -->
                    <!--正常使用-->
                    <div class="form-group">
                        <label class="col-sm-1 control-label">接收手机</label>
                        <div class="col-sm-2 ">
                            <input class="form-control" type="text" value="{{uprofile.mobile}}" disabled="">&nbsp;<a
                                href="{{rootUrl}}user/profile/sms/edit">修改手机</a>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">通知类型</label>
                        <div class="col-sm-5">
                            <label class="checkbox-inline">
                                <input type="checkbox" checked value="option1" disabled> 到我审批
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" checked value="option1" disabled> 标段审批通过（上报人接收）
                            </label>
                            <label class="checkbox-inline">
                                <input type="checkbox" checked value="option1" disabled> 标段审批不通过（上报人接收）
                            </label>
                        </div>
                    </div>
                    <!--正常使用-->
                    <!-- endif -->
                    <!-- endif -->
                    </fieldset>
                </form>
            </div>
        </div>
        <!--内容-->
    </div>
</div>
<script type="text/javascript">autoFlashHeight();</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#mobile").blur(function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                cache: false,
                data: {"mobile": $(this).val()},
                url: "{{rootUrl}}user/profile/check/mobile",
                success: function(data){
                    if (data["mobile"] > 0) {
                        $("#input_error").addClass('has-error');
                        $("#help-inline").html('手机号码已被使用');
                        $("#help-inline").show();
                    } else {
                        $("#input_error").removeClass('has-error');
                        $("#help-inline").hide();
                    }
              	}
            });
        });


        /*仿刷新：检测是否存在cookie*/
        if ($.cookie("sms")) {
            var count = $.cookie("sms");
            var btn = $('#getting');
            btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
            var resend = setInterval(function () {
                count--;
                if (count > 0) {
                    btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
                    $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
                } else {
                    clearInterval(resend);
                    btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
                }
            }, 1000);
        }

        /*点击改变按钮状态，已经简略掉ajax发送短信验证的代码*/
        $('#getting').click(function () {
            var btn = $(this);
            if ($("#mobile").val() == '') {
                $("#input_error").addClass('has-error');
                $("#help-inline").html('手机号码不能为空');
                $("#help-inline").show();
                return false;
            }
            $.ajax({
                type: "POST",
                dataType: "json",
                cache: false,
                data: {"mobile": $("#mobile").val()},
                url: "{{rootUrl}}user/profile/check/mobile",
                success: function(data){
                  if (data["mobile"] > 0) {
                      $("#input_error").addClass('has-error');
                      $("#help-inline").html('手机号码已被使用');
                      $("#help-inline").show();
                      return false;
                  } else {
                      $("#input_error").removeClass('has-error');
                      $("#help-inline").hide();
                      $.ajax({
                          type: "POST",
                          dataType: "json",
                          cache: false,
                          data: {"mobile": $("#mobile").val()},
                          url: "{{rootUrl}}user/profile/sms/send/verify",
                          success: function(data){
                            if(data["verify"]==true){
                              var count = 60;
                              var resend = setInterval(function () {
                                  count--;
                                  if (count > 0) {
                                      btn.val('重新获取 ' + count + 's');
                                      $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
                                  } else {
                                      clearInterval(resend);
                                      btn.val("获取验证码").removeAttr('disabled style');
                                  }
                              }, 1000);
                              btn.attr('disabled', true).css('cursor', 'not-allowed');
                            }
                          }
                      });
                  }
                }
            });
        });

        /*点击改变按钮状态，已经简略掉ajax发送短信验证的代码*/
        $('#addMobile').click(function () {
            $.ajax({
                type: "POST",
                dataType: "json",
                cache: false,
                data: {"mobile": $("#mobile").val(), "verifycode": $("#verifycode").val()},
                url: "{{rootUrl}}user/profile/sms",
                error: function (err) {
                    alert(err);
                },
                success: function () {
                    window.location.href = "{{rootUrl}}user/profile/sms";
                }
            });
        });
    });
</script>
</body>
