<!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">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.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"/>
                            <input name="accountsId" value="$!{accountId}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label for="name">编码规则名称</label>
                                    <input type="text"
                                           class="form-control htmlescape" name="name" id="name"
                                           maxlength="50" placeholder="编码规则名称" required="required"
                                           value="$!{data.name}">
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label for="bo">业务对象(需要全路径,譬如: com.cftech.base.codingrule.model.Codingrule)</label>
                                    <input type="text" name="bo" id="bo" value="$!{data.bo}"
                                           class="form-control htmlescape" placeholder="请输入业务对象">
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>间隔符号</label>
                                    <select class="form-control select2" data-placeholder="选择间隔符号"
                                            style="width: 100%;" id="mid">
                                        <option value="*">无</option>
                                        <option value="-">-</option>
                                        <option value="_">_</option>
                                        <option value="/">/</option>
                                        <option value=".">.</option>
                                    </select>
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label for="tplselect">选择模版<input id="generateCode" class="btn btn-success"
                                                                      value="生成规则模版"></label>
                                    <select class="form-control select2" data-placeholder="选择选择模版"
                                            style="width: 100%;" id="tplselect">
                                        <option value="*">无</option>
                                        <option value="0">4位顺序号</option>
                                        <option value="1">5位顺序号</option>
                                        <option value="2">按日期+顺序号</option>
                                        <option value="3">关键字+顺序号</option>
                                        <option value="4">关键字+日期+顺序号</option>
                                    </select>
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label for="bo">规则模版<code>顺序号以英文*代替,
                                        日期仅可使用yyyyMMdd年月日替换,关键字用XX替代，可自行修改成需要的关键字</code></label>
                                    <input type="text" name="tpl" id="tpl" value="$!{data.tpl}"
                                           class="form-control htmlescape" placeholder="请输入规则模版或选择一个模版">
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label for="bo"><input id="previewCode" class="btn btn-success"
                                                           value="预览规则模版"></label>
                                    <input type="text" name="preivew" id="preivew"
                                           class="form-control htmlescape" placeholder="请点击预览规则模版" readonly>
                                </div>
                            </div>

                            <input type="text" style="display: none" name="_csrf" value="${_csrf.token}"/>
                            <input  type="text" style="display: none" name="_csrf_header" value="${_csrf.headerName}"/>

                            <div class="box-footer">
                                #if($shiro.hasPermission("sys:codingrule:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/codingrule/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>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!-- Select2 -->
<script src="plugins/select2/select2.full.min.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="plugins/jquery-validation/js/localization/messages_zh.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 src="js/jquery.serializejson.js"></script>
<script>
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
    });


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

            var generateCode = function () {
                $('#generateCode').on('click', function () {
                    //分隔符
                    var mid = $('#mid').val();
                    if (mid == '*') {
                        mid = '';
                    }
                    var defaultNo = '****';
                    var key = 'XX';
                    //模版
                    var tplSelect = $('#tplselect').val();
                    if (!tplSelect || tplSelect == '' || tplSelect == '*') {
                        Cfapp.alert({
                            message: "请先选择模版",
                            btntext: "确定",
                            success: function () {

                            }
                        });
                        return;
                    }
                    if (tplSelect == '0') {
                        //只是顺序号,4位
                        $('#tpl').val('****');
                    } else if (tplSelect == '1') {
                        //只是顺序号，5位
                        $('#tpl').val('*****');
                    } else if (tplSelect == '2') {
                        $('#tpl').val(pdate + mid + defaultNo);
                    } else if (tplSelect == '3') {
                        $('#tpl').val(key + mid + defaultNo);
                    } else if (tplSelect == '4') {
                        $('#tpl').val(key + mid + pdate + mid + defaultNo);
                    }
                });
            };

            var preivewCode = function () {
                $('#previewCode').on('click', function () {
                    var tpl = $('#tpl').val();
                    if (!tpl || tpl == '') {
                        Cfapp.alert({
                            message: "请先生成规则模版或填写规则模版",
                            btntext: "确定",
                            success: function () {

                            }
                        });
                        return;
                    }
                    //替换顺序号
                    tpl = tpl.replace('yyyyMMdd', '20170101');
                    tpl = tpl.replace(new RegExp(/\*/g), '0');
                    tpl = tpl.substr(0, tpl.length - 1) + '1';
                    $('#preivew').val(tpl);
                });
            };

            var bindEvent = function () {
                $(".select2").select2();
                generateCode();
                preivewCode();
                $("#myForm").validate({
                    rules: {
                        name: {
                            required: true,
                            htmlescape: true
                        },
                        number: {
                            required: true,
                            htmlescape: true
                        }
                    },
                    messages: {
                        name: {
                            required: "请输入编码规则名称!",
                            htmlescape: "请您不要输入特殊字符!"
                        }
                    },
                    submitHandler: function (form) {
                        $("#save").attr("disabled", true);
                        $.ajax(
                            {
                                type: "POST",
                                dataType: "json",
                            url:"#springUrl('/a/codingrule/formData')",
                                data:$("#myForm").serializeJSON(),
                                success:function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/codingrule/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/codingrule/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/codingrule/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/codingrule/list')";
                                    }
                                });
                            }
                        } });
                    }
                })
            }
            initFormCtrl();
        }
        return {

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

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