<!--删除标段-->
<div class="modal fade" id="del-bg" 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">
                <h5>删除后，数据无法恢复，请谨慎操作。</h5>
            </div>
            <form class="modal-footer" action="/tender/<%- tender.id %>/change/delete" method="post">
                <input type="hidden" name="cid" id="delete-cid" value="">
                <input type="hidden" name="_csrf" value="<%= ctx.csrf %>" />
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-danger">确定删除</button>
            </form>
        </div>
    </div>
</div>
<% if (tender.user_id === uid) { %>
<!--弹出添加变更令-->
<div class="modal fade" id="add-bj" 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 is-invalid" placeholder="请输入变更令号" value="变更申请编号" id="bj-code">
                        <div class="input-group-append" id="autoCodeShow" <% if (codeRule.length === 0) { %>style="display: none"<% } %>>
                            <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="bjHint">您输入的编号已存在</div>
                    </div>
                </div>
                <div class="form-group">
                    <label>工程名称<b class="text-danger">*</b></label>
                    <input class="form-control" value="" type="text" id="bj-name">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="addCancel">关闭</button>
                <a href="javascript: void(0)" class="btn btn-primary" id="addOk">确认添加</a>
            </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="#bianhao" role="tab" aria-controls="home" aria-selected="true">编号规则</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="bianhao">
                        <h5>
                            当前规则：
                            <span id="preview">
                                <% if (codeRule && codeRule instanceof Array) { %>
                                    <% const preview = []; %>
                                    <% for (const rule of codeRule) { %>
                                        <% preview.push(rule.preview); %>
                                    <% } %>
                                    <%- preview.join(tender.c_connector !== null && tender.c_connector !== '3' ? ruleConst.connectorString[tender.c_connector] : ''); %>
                                <% } %>
                            </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 class="my-3">连接符</h5>
                        <div class="form-group">
                            <select class="form-control connector-change">
                                <option disabled selected>请选择</option>
                                <% for (const index in ruleConst.connectorString) { %>
                                    <option value="<%- index %>" <% if (tender.c_connector !== null && tender.c_connector === parseInt(index)) { %>selected<% } %>><%- ruleConst.connectorString[index] %></option>
                                <% } %>
                            </select>
                        </div>
                        <h5 class="my-3">添加新规则组件</h5>
                        <div class="form-group">
                            <select class="form-control rule-change">
                                <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-outline-primary" id="addRule">添加组件</button>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <% if (tender.c_rule_first) { %><button type="button" class="btn btn-secondary" data-dismiss="modal" id="changeFirst">暂时不需要</button><% } %>
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="hide_modal" <% if (tender.c_rule_first) { %>style="display: none"<% } %>>关闭</button>
                <button type="button" class="btn btn-primary" id="setRule">确定添加</button>
            </div>
        </div>
    </div>
</div>
<% } %>
<script>
    const ruleType = <%- ruleType %>;
    const ruleConst = JSON.parse('<%- JSON.stringify(ruleConst) %>');
    let codeRule = JSON.parse('<%- JSON.stringify(codeRule) %>');
    let connectorRule = '<%- tender.c_connector %>';
    let cRuleFirst = '<%- tender.c_rule_first %>';
</script>
<script src="/public/js/moment/moment.min.js"></script>

