<!--弹出添加中间计量-->
<div class="modal fade" id="add-mj" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">添加中间计量</h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>中间计量编号<b class="text-danger">*</b></label>
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="请输入中间计量编号" value="WJQR1-201711" id="mj-code">
                        <div class="input-group-append">
                            <button class="btn btn-outline-secondary" type="button" title="自动编号" id="autoCode"><i class="fa fa-repeat"></i></button>
                        </div>
                        <div class="invalid-feedback" style="display: none" id="mj-Hint">您输入的编号已存在</div>
                    </div>
                </div>
                <div class="form-group">
                    <label>计量月份</label>
                    <input data-view="months" data-min-view="months" class="datepicker-here form-control" placeholder="按时间筛选" type="text" data-date-format="yyyy MM " data-language="zh" id="mj-date">
                </div>
                <div class="form-group">
                    <label>计量期</label>
                    <select class="form-control">
                        <option disabled>选填</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="addCancel">关闭</button>
                <button type="button" class="btn btn-primary" id="addOk">添加</button>
            </div>
        </div>
    </div>
</div>
<!--计量编号规则设置-->
<div class="modal fade" id="setting" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">中间计量设置</h5>
            </div>
            <div class="modal-body">
                <ul class="nav nav-tabs mb-3" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" data-toggle="tab" href="#profile" role="tab">信息设置</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" data-toggle="tab" href="#rule" role="tab">编号规则</a>
                    </li>
                </ul>
                <div class="tab-content" >
                    <div class="tab-pane fade show active" id="profile" role="tabpanel">
                        <div class="form-group">
                            <label>中间计量编号<b class="text-danger">*</b></label>
                            <div class="input-group">
                                <input type="text" class="form-control" placeholder="请输入中间计量编号" value="WJQR1-201711">
                                <div class="input-group-append">
                                    <button class="btn btn-outline-secondary" type="button" title="自动编号"><i class="fa fa-repeat"></i></button>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>计量月份</label>
                            <input data-view="months" data-min-view="months" class="datepicker-here form-control" placeholder="按时间筛选" type="text" data-date-format="yyyy MM " data-language="zh">
                        </div>
                        <div class="form-group">
                            <label>计量期</label>
                            <select class="form-control">
                                <option>选填</option>
                                <option>15</option>
                                <option>14</option>
                            </select>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="rule" role="tabpanel">
                        <h5 id="preview">
                            当前规则：
                            <% if (codeRule && codeRule instanceof Array) { %>
                            <% const preview = []; %>
                            <% for (const rule of codeRule) { %>
                            <% preview.push(rule.preview); %>
                            <% } %>
                            <%- preview.join(''); %>
                            <% } %>
                        </h5>
                        <h5 id="ruleParts">
                            <% if (codeRule && codeRule instanceof Array) { %>
                            <% for (const rule of codeRule) { %>
                            <span class="badge badge-light" title="<%- ruleConst.ruleString[rule.rule_type]%>">
                                        <span><%- rule.preview %></span>
                                        <a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>
                                    </span>
                            <% } %>
                            <% } %>
                        </h5>
                        <h5>添加新规则组件</h5>
                        <div class="form-group">
                            <select class="form-control">
                                <option disabled selected>请选择组件</option>
                                <% for (const index in ruleConst.ruleString) { %>
                                <option value="<%- index %>"><%- ruleConst.ruleString[index] %></option>
                                <% } %>
                            </select>
                        </div>
                        <div class="form-group" id="format" style="display: none">
                            <label>自动编号位数</label>
                            <input min="3" class="form-control" step="1" max="6" value="3" type="number">
                        </div>
                        <div class="form-group" id="text" style="display: none">
                            <label>起始编号</label>
                            <input class="form-control" value="001" type="text">
                        </div>
                        <button class="btn btn-primary" id="addRule">添加组件</button>
                    </div>
                </div>
            </div>
            <div class="modal-footer d-flex justify-content-between">
                <div>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--编辑中间计量-->
<div class="modal fade" id="edit" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">编辑中间计量</h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>中间计量编号<b class="text-danger">*</b></label>
                    <div class="input-group">
                        <input id="codeEdit" type="text" class="form-control" placeholder="请输入中间计量编号" value="WJQR1-201711">
                        <div class="input-group-append">
                            <button class="btn btn-outline-secondary" type="button" title="自动编号"><i class="fa fa-repeat"></i></button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label>计量月份</label>
                    <input data-view="months" data-min-view="months" class="datepicker-here form-control" placeholder="按时间筛选" type="text" data-date-format="yyyy MM " data-language="zh">
                </div>
            </div>
            <div class="modal-footer d-flex justify-content-between">
                <a href="javascript: void(0)" data-toggle="modal" data-target="#del" class="btn btn-outline-danger btn-sm pull-right">删除 WJQR1-201710</a>
                <div>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="editOk">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--首次使用-->
<div class="modal" id="first">
    <div class="modal-dialog" role="document" >
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">设置中间计量编号规则</h5>
            </div>
            <div class="modal-body">
                <h5 >
                    当前规则：
                    <span id="preview">
                        <% if (codeRule && codeRule instanceof Array) { %>
                        <% const preview = []; %>
                        <% for (const rule of codeRule) { %>
                        <% preview.push(rule.preview); %>
                        <% } %>
                        <%- preview.join(''); %>
                        <% } %>
                    </span>
                </h5>
                <h5 id="ruleParts">
                    <% if (codeRule && codeRule instanceof Array) { %>
                    <% for (const rule of codeRule) { %>
                    <span class="badge badge-light" title="<%- ruleConst.ruleString[rule.rule_type]%>">
                            <span>
                                <%- rule.preview %>
                            </span>
                            <a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>
                        </span>
                    <% } %>
                    <% } %>
                </h5>
                <h5>添加新规则组件</h5>
                <div class="form-group">
                    <select class="form-control">
                        <option disabled selected>请选择组件</option>
                        <% for (const index in ruleConst.ruleString) { %>
                        <option value="<%- index %>"><%- ruleConst.ruleString[index] %></option>
                        <% } %>
                    </select>
                </div>
                <div class="form-group" id="format" style="display: none">
                    <label>自动编号位数</label>
                    <input min="3" class="form-control" step="1" max="6" value="3" type="number">
                </div>
                <div class="form-group" id="text" style="display: none">
                    <label>起始编号</label>
                    <input class="form-control" value="001" type="text">
                </div>
                <button class="btn btn-primary" id="addRule">添加组件</button>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button class="btn btn-primary" id="setRule">确定</button>
            </div>
        </div>
    </div>
</div>
<!--删除-->
<div class="modal fade" id="del" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <h5>确认删除 <span id="code">WJQR1-201710</span> ？</h5>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-danger" id="delOk">确认删除</button>
            </div>
        </div>
    </div>
</div>
<script>
    const ruleType = <%- ruleType %>;
    const ruleConst = JSON.parse('<%- JSON.stringify(ruleConst) %>');
    let codeRule = JSON.parse('<%- JSON.stringify(codeRule) %>');
</script>
<script src="/public/js/moment/moment.min.js"></script>
<script src="/public/js/datepicker/datepicker.min.js"></script>
<script src="/public/js/datepicker/datepicker.zh.js"></script>