<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'}">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
              <a class="close" href="javascript:void(0);">上级列表</a><span lay-separator="">/</span>
              <a href="javascript:void(0);"><cite>新增内容</cite></a>
            </span>
        </div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <div class="layui-row">
                    <div class="layui-col-xs8">
                        <div class="layui-form-item">
                            <label class="layui-form-label">标题 *</label>
                            <div class="layui-input-block">
                                <input type="text" id="title" name="title" class="layui-input" value="" placeholder="请输入标题"  maxlength="255" lay-verify="required">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">描述</label>
                            <div class="layui-input-block">
                                <input type="text" id="summary" name="summary" class="layui-input" value="" placeholder="请输入描述"  maxlength="500">
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote">
                            <div>1.占位符格式必须一致，否则无法正确生成文号。除占位符外，其余符号可按需补充</div>
                            <div>2.模板支持的占位符有：年（完整）：yyyy，年（简写）：yy，月：MM，日：dd，数字：nn</div>
                            <div>3.年的占位符只能有一个</div>
                        </blockquote>
                        <div class="layui-row">
                            <div class="layui-col-xs6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">类型 *</label>
                                    <div class="layui-input-block">
                                        <select id="type" name="type" lay-filter="typeSelect" lay-verify="required">
                                            <option value="always" data-template="〔yyyy〕nn">一直累加</option>
                                            <option value="year" data-template="〔yyyy〕nn">按年累加</option>
                                            <option value="month" data-template="〔yyyy-MM〕nn">按月累加</option>
                                            <option value="day" data-template="〔yyyy-MM-dd〕nn">按日累加</option>
                                            <option value="manual" data-template="">手动</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">模板</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="template" name="template" class="layui-input" value="〔yyyy〕nn" placeholder="请输入模板"  maxlength="255" lay-verify="required">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote">
                            <div>1.开始编号：确定了文号生成的第一个值，后续以此累加</div>
                            <div>2.编号长度：确定了文号累加数字的位数</div>
                        </blockquote>
                        <div class="layui-row">
                            <div class="layui-col-xs6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">开始编号 *</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="startNu" name="startNu" class="layui-input" value="1" placeholder="请输入开始编号" lay-verify="required">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">编号长度 *</label>
                                    <div class="layui-input-block">
                                        <input type="number" id="nuLength" name="nuLength" class="layui-input" value="2" placeholder="请输入编号长度" lay-verify="required">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote">
                            文号示例：<span id="docNoDemo"></span>
                        </blockquote>
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label">是否激活</label>
                            <div class="layui-input-block">
                                <input type="radio" name="isActive" value="1" title="是" checked>
                                <input type="radio" name="isActive" value="0" title="否">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">提交新增</button>
                            <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/doc-no/doc-no.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        // 初始化内容
        function initData() {
            var docNo = new DocNo($, form);
            docNo.refreshDocNoDemo();
            docNo.addKeyup();
            docNo.addSelect();
        }
        initData();

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                top.restAjax.post(top.restAjax.path('api/doc-no/save', []), formData.field, null, function(code, data) {
                    var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
                        time: 0,
                        btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
                        shade: 0.3,
                        yes: function(index) {
                            top.dialog.close(index);
                            window.location.reload();
                        },
                        btn2: function() {
                            closeBox();
                        }
                    });
                }, function(code, data) {
                    top.dialog.msg(data.msg);
                }, function() {
                    loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                }, function() {
                    top.dialog.close(loadLayerIndex);
                });
            });
            return false;
        });

        $('.close').on('click', function() {
            closeBox();
        });

        // 校验
        form.verify({
        });
    });
</script>
</body>
</html>