<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                身份验证管理
                <small>身份验证</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">身份验证</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label>姓名</label>
                                    <input type="text"
                                           class="form-control" name="name"
                                           id="name"
                                           maxlength="500" placeholder="name"
                                           value="$!{data.name}"
                                    >

                                </div>

                                <div class="form-group form-md-line-input">
                                    <label>身份证号码</label>
                                    <input type="text"
                                           class="form-control" name="idCard"
                                           id="idCard"
                                           maxlength="500" placeholder="idCard"
                                           value="$!{data.idCard}"
                                    >

                                </div>

                                <div class="fform-group form-md-line-input">
                                    <label>描述</label>
                                    <textarea type="text"  class="form-control"
                                              value="" maxlength="500"
                                              name="description" placeholder="描述"
                                    >$!{data.description}</textarea>
                                </div>


                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("qy:authentication:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/authentication/list')" class="btn btn-default">取消</a>
                            </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="common/js/cfapp.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
    });

    function dateToString(date) {
        if (date instanceof Date) {
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            month = month < 10 ? '0' + month: month;
            var day = date.getDate();
            day = day < 10 ? '0' + day: day;
            return year + month + day;
        }
        return '';
    }


    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {

                        var card = $("#idCard").val();
                        var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
                        if(reg.test(card) == false){
                            Cfapp.alert({
                                message: "请输入正确格式的身份证号码",
                                btntext: "确定",
                                success: function () {
                                }
                            });
                        }else{

                            //身份证正则表达式(18位)
                            var isIdCard2 = /^[1-9]\d{5}(19\d{2}|[2-9]\d{3})((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])(\d{4}|\d{3}X)$/i;
                            var stard = "10X98765432"; //最后一位身份证的号码
                            var first = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //1-17系数
                            var sum = 0;
                            if (!isIdCard2.test(card)) {
                                Cfapp.alert({
                                    message: "请输入正确格式的身份证号码",
                                    btntext: "确定",
                                    success: function () {
                                    }
                                });
                                return;
                            }
                            var year = card.substr(6, 4);
                            var month = card.substr(10, 2);
                            var day = card.substr(12, 2);
                            var birthday = card.substr(6, 8);
                            if (birthday != dateToString(new Date(year + '/' + month + '/' + day))) { //校验日期是否合法
                                Cfapp.alert({
                                    message: "请输入正确格式的身份证号码",
                                    btntext: "确定",
                                    success: function () {
                                    }
                                });
                                return;
                            }
                            for (var i = 0; i < card.length - 1; i++) {
                                sum += card[i] * first[i];
                            }
                            var result = sum % 11;
                            var last = stard[result]; //计算出来的最后一位身份证号码
                            if (card[card.length - 1].toUpperCase() == last) {
                                //保存
                                $("#save").attr("disabled", true);
                                $.getJSON("#springUrl('/a/authentication/formData')", $("#myForm").serialize(), function (returnobj) {
                                    $("#save").attr("disabled", false);
                                    if (returnobj.errorNo == 2) {  //保存成功
                                        Cfapp.confirm({
                                            message: "添加成功",
                                            btnoktext: "继续添加",
                                            btncanceltext: "关闭",
                                            success: function () {
                                                location.href = "#springUrl('/a/authentication/form')";
                                            },
                                            cancel: function () {
                                                location.href = "#springUrl('/a/authentication/list')";
                                            }
                                        });
                                    } else if (returnobj.errorNo == 0) {  //修改成功
                                        Cfapp.alert({
                                            message: "更新成功",
                                            btntext: "确定",
                                            success: function () {
                                                location.href = "#springUrl('/a/authentication/list')";
                                            }
                                        });
                                    } else {
                                        Cfapp.alert({
                                            message: "创建失败",
                                            btntext: "确定",
                                            success: function () {
                                                location.href = "#springUrl('/a/authentication/list')";
                                            }
                                        });
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "请输入正确格式的身份证号码",
                                    btntext: "确定",
                                    success: function () {
                                    }
                                });
                                return;
                            }

                        }


                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>