<% if (auditStatus === 1 || auditStatus === 2) { %>
<!--变更单位-->
<div class="modal fade" id="editcompany" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="myModalLabel">变更单位</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div id="companyshow">
                    <% for (const company of companyList) { %>
                    <div class="form-group">
                        <input type="text" id="<%= company.id %>" class="form-control" value="<%= company.name %>">
                    </div>
                    <% } %>
                </div>
                <div class="alert alert-warning" role="alert">修改后，已创建的变更不受影响。</div>
                <p><button class="btn btn-primary btn-sm" id="addcompany" role="button" title="填写公司"><b class="fa fa-plus"></b></button></p>
                <div id="companyadddiv">
                    <!--<input type="text" class="form-control" placeholder="请输入公司名称">-->
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" id="updatecompany" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>

<!--上报审批-->
<div class="modal fade" id="sub-ap" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title up-change">上报审批</h5>
                <h5 class="modal-title save-change">保存修改</h5>
            </div>
            <form method="post" action="/tender/<%- tender.id %>/change/<%- change.cid %>/save">
                <div class="modal-body">
                    <!--如未创建清单-->
                    <!--<h5>还没添加任何变更清单，无法提交。</h5>-->
                    <!--可以提交审批 但需要设置审批流程-->
                    <div class="form-group">
                        <label>搜索审批人</label>
                        <div class="input-group">
                            <input class="form-control" placeholder="请输入姓名进行检索" type="text" id="search_audit_input">
                            <div class="input-group-append">
                                <button class="btn btn-outline-secondary" type="button" id="search_audit_btn"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                    </div>
                    <div id="search_audit_list">
                    </div>
                    <div class="card mt-3">
                        <div class="card-header">
                            审批流程
                        </div>
                        <ul class="list-group list-group-flush">
                            <% for (const audit of auditList) { %>
                                <% if (audit.usite === 0) { %>
                                <li class="list-group-item">
                                    <i class="fa fa-play-circle fa-rotate-90"></i>
                                    <%= audit.name %><small class="text-muted"><%= audit.jobs %></small>
                                </li>
                                <% } %>
                            <% } %>
                        </ul>
                        <ul class="list-group list-group-flush" id="auditList">
                            <% for (const audit of auditList) { %>
                                <% if (audit.usite !== 0) { %>
                                <li class="list-group-item" data-auditmsg="<%= audit.uid + '/%/' + audit.name + '/%/' + audit.jobs + '/%/' + audit.company %>"
                                    data-auditid="<%= audit.uid %>">
                                    <a href="javascript:void(0)" class="text-danger pull-right remove_audit_btn">移除</a>
                                    <% if (audit.usite === auditList.length-1) { %><i class="fa fa-stop-circle"></i>
                                    <% } else { %><i class="fa fa-chevron-circle-down"></i>
                                    <% } %>
                                    <%= audit.name %><small class="text-muted"><%= audit.jobs %></small>
                                </li>
                                <% } %>
                            <% } %>
                        </ul>
                        <input type="hidden" id="auditIdList" value="">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" data-sumbit="sumbit_change" data-category="up_change" class="btn btn-primary up-change">确认上报</button>
                    <button type="button" data-sumbit="sumbit_change" data-category="save_change" class="btn btn-success save-change">保存修改</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="/public/js/change_company.js"></script>

<!--添加清单-->
<div class="modal fade " tabindex="-1" role="dialog" aria-hidden="true" id="addlist">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="mySmallModalLabel">从清单中选择</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-7">
                        <div style="height:400px;overflow-y:auto">
                            <table class="table table-striped table-bordered table-condensed">
                                <thead><tr><th>序号</th><th>清单编号</th><th>名称</th><th>单位</th><th>单价</th><th>数量</th><th>金额</th></tr></thead>
                                <tbody id="table-list-select">
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col-5">
                        <div style="height:400px;overflow-y:auto">
                            <table class="table table-sm table-bordered">
                                <thead>
                                <tr><th>项目节编号</th><th>名称</th><th>部位明细</th><th>选择</th></tr>
                                </thead>
                                <tbody id="code-list" data-index="">
                                <!--<tr><td colspan="3">自行编辑变更详情</td><td><input type="checkbox"></td></tr>-->
                                <!--<tr><td>1-4-5-1-1-1-1</td><td>桥台桩基础</td><td>0#桥台1#桩</td><td><input type="checkbox"></td></tr>-->
                                <!--<tr><td>1-4-5-1-1-1-1</td><td>桥台桩基础</td><td>0#桥台2#桩</td><td><input type="checkbox"></td></tr>-->
                                <!--<tr><td>1-4-5-1-1-1-1</td><td>桥台桩基础</td><td>0#桥台3#桩</td><td><input type="checkbox"></td></tr>-->
                                <!--<tr><td>1-4-5-1-1-1-1</td><td>桥台桩基础</td><td>0#桥台4#桩</td><td><input type="checkbox"></td></tr>-->
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="add-list-btn btn btn-outline-primary">添加空白清单</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="cancel-list-btn">取消</button>
                <button type="button" class="add-list-btn btn btn-primary">添加</button>
            </div>
        </div>
    </div>
</div>
<% } %>

<% if (auditStatus === 3 || auditStatus === 4 || auditStatus === 5 || auditStatus === 7) { %>
<!--审批流程/结果-->
<div class="modal fade" id="sp-list" data-backdrop="static">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">审批流程</h5>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-4">
                        <div class="card mt-3">
                            <ul class="list-group list-group-flush">
                                <% for (const [index,a] of auditList2.entries()) { %>
                                    <li class="list-group-item">
                                        <% if (a.usite === 0 ) { %>
                                            <i class="fa fa-play-circle fa-rotate-90"></i>
                                        <% } else if (index+1 !== auditList2.length) { %>
                                            <i class="fa fa-chevron-circle-down"></i>
                                        <% } else if (index+1 === auditList2.length) { %>
                                            <i class="fa fa-stop-circle"></i>
                                        <% } %>
                                        <%= a.name %>  <small class="text-muted"><%= a.jobs %></small>
                                    </li>
                                <% } %>
                            </ul>
                        </div>
                    </div>
                    <div class="col-8 modal-height-500" style="overflow: auto">
                        <% for (const time in auditList3) { %>
                        <div class="card mt-3">
                            <ul class="list-group list-group-flush">
                                <% for (const [aindex,al] of auditList3[time].entries()) { %>
                                <li class="list-group-item">
                                    <% if (al.usite === 0 && al.status === 2) { %>
                                    <span class="pull-right">重新上报中</span>
                                    <% } else if (al.usite === 0 && al.status === 3) { %>
                                    <span class="text-success pull-right">上报</span>
                                    <% } else if (al.usite !== 0 && al.status === 2) { %>
                                    <span class="pull-right">审批中</span>
                                    <% } else if (al.usite !== 0 && al.status === 3) { %>
                                    <span class="text-success pull-right">审批通过</span>
                                    <% } else if (al.usite !== 0 && al.status === 4) { %>
                                    <span class="text-danger pull-right">审批终止</span>
                                    <% } else if (al.usite !== 0 && (al.status === 5 || al.status === 6)) { %>
                                    <span class="text-warning pull-right">审批退回 </span>
                                    <% } %>
                                    <h5 class="card-title">
                                        <% if (al.usite === 0 && al.status === 2 ) { %>
                                        <i class="fa fa-play-circle fa-rotate-90"></i>
                                        <% } else if (al.usite === 0 && al.status === 3 ) { %>
                                        <i class="fa fa-play-circle fa-rotate-90 text-success"></i>
                                        <% } else if (al.status === 1 || al.status === 2) { %>
                                        <i class="fa <% if (aindex+1 === auditList3[time].length) { %>fa-stop-circle<% } else { %>fa-chevron-circle-down<% } %> "></i>
                                        <% } else if (al.status === 3) { %>
                                        <i class="fa <% if (aindex+1 === auditList3[time].length) { %>fa-stop-circle<% } else { %>fa-chevron-circle-down<% } %> text-success"></i>
                                        <% } else if (al.status === 4) { %>
                                        <i class="fa <% if (aindex+1 === auditList3[time].length) { %>fa-stop-circle<% } else { %>fa-chevron-circle-down<% } %> text-danger"></i>
                                        <% } else if (al.status === 5 || al.status === 6) { %>
                                        <i class="fa <% if (aindex+1 === auditList3[time].length) { %>fa-stop-circle<% } else { %>fa-chevron-circle-down<% } %> text-warning"></i>
                                        <% } %>
                                        <%= al.name %>&nbsp;<small class="text-muted"><%= al.jobs %></small>
                                    </h5>
                                    <% if (al.sin_time !== null || (al.sdesc !== '' && al.sdesc !== null)) { %>
                                        <p class="card-text"><%= al.sdesc %>&nbsp;<%= moment(al.sin_time).format('YYYY-MM-DD') %></p>
                                    <% } %>
                                </li>
                                <% } %>
                            </ul>
                        </div>
                        <% } %>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<% } %>

<% if (auditStatus === 6) { %>
    <!--审批通过-->
    <div class="modal fade" id="sp-done" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">审批通过</h5>
                </div>
                <form action="/change/approval?_csrf=<%= ctx.csrf %>" method="post" id="success-approval">
                <div class="modal-body">
                    <div class="card mt-3">
                        <ul class="list-group list-group-flush">
                            <% for (const [index,a] of auditList.entries()) { %>
                            <li class="list-group-item">
                                <% if (a.status === 3 && a.usort === 0) { %>
                                <span class="text-success pull-right">上报</span>
                                <% } else if (a.status === 3 && a.usort !== 0) { %>
                                <span class="text-success pull-right">审批通过</span>
                                <% } else if (a.status === 2) { %>
                                <span class="pull-right">审批中</span>
                                <% } %>
                                <h5 class="card-title">
                                    <% if (a.usort === 0) { %>
                                    <i class="fa fa-play-circle fa-rotate-90 <% if (a.status === 3) { %>text-success<% } %>"></i>
                                    <% } else if (a.usort !== 0 && index+1 !== auditList.length) { %>
                                    <i class="fa fa-chevron-circle-down <% if (a.status === 3) { %>text-success<% } %>"></i>
                                    <% } else if (a.usort !== 0 && index+1 === auditList.length) { %>
                                    <i class="fa fa-stop-circle"></i>
                                    <% } %>
                                    <%= a.name %>&nbsp;<small class="text-muted"><%= a.jobs%></small>
                                </h5>
                                <% if (a.sin_time !== null || (a.sdesc !== '' && a.sdesc !== null)) { %>
                                    <p class="card-text"><%= a.sdesc %>&nbsp;<%= moment(a.sin_time).format('YYYY-MM-DD') %></p>
                                <% } %>
                                <% if (a.status === 2) { %>
                                    <div class="form-group">
                                        <label>审批意见<b class="text-danger">*</b></label>
                                        <textarea class="form-control" name="sdesc"></textarea>
                                        <input type="hidden" name="audit_id" value="<%= a.id %>">
                                        <% if (a.usort !== 0 && index+1 === auditList.length) { %>
                                        <!--终审填写批复编号-->
                                        <div class="form-group mt-3">
                                            <label><b class="text-danger">*&nbsp;</b>批复编号</label>
                                            <input class="form-control" value="<%= change.name %>" name="p_code" type="text">
                                        </div>
                                        <% } else { %>
                                            <input type="hidden" name="audit_next_id" value="<%= auditList[index+1].id %>">
                                        <% } %>
                                    </div>
                                <% } %>
                            </li>
                            <% } %>
                        </ul>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="status" value="3">
                    <input type="hidden" name="w_code" value="">
                    <input type="hidden" name="change_id" value="<%= change.cid %>">
                    <input type="hidden" name="bills_list" id="change-list-approval" value="">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-success approval-btn">确认通过</button>
                </div>
                </form>
            </div>
        </div>
    </div>
    <!--审批退回-->
    <div class="modal fade" id="sp-back" data-backdrop="static">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">审批退回</h5>
                </div>
                <form action="/change/approval?_csrf=<%= ctx.csrf %>" method="post" id="fail-approval">
                <div class="modal-body">
                    <div class="card mt-3">
                        <ul class="list-group list-group-flush">
                            <% for (const [index,a] of auditList.entries()) { %>
                                <li class="list-group-item">
                                    <% if (a.status === 3 && a.usort === 0) { %>
                                        <span class="text-success pull-right">上报</span>
                                    <% } else if (a.status === 3 && a.usort !== 0) { %>
                                        <span class="text-success pull-right">审批通过</span>
                                    <% } else if (a.status === 2) { %>
                                        <span class="pull-right">审批中</span>
                                    <% } %>
                                    <h5 class="card-title">
                                        <% if (a.usort === 0) { %>
                                            <i class="fa fa-play-circle fa-rotate-90 <% if (a.status === 3) { %>text-success<% } %>"></i>
                                        <% } else if (a.usort !== 0 && index+1 !== auditList.length) { %>
                                            <i class="fa fa-chevron-circle-down <% if (a.status === 3) { %>text-success<% } %>"></i>
                                        <% } else if (a.usort !== 0 && index+1 === auditList.length) { %>
                                            <i class="fa fa-stop-circle"></i>
                                        <% } %>
                                        <%= a.name %>&nbsp;<small class="text-muted"><%= a.jobs%></small>
                                    </h5>
                                    <% if (a.sin_time !== null || (a.sdesc !== '' && a.sdesc !== null)) { %>
                                        <p class="card-text"><%= a.sdesc %>&nbsp;<%= moment(a.sin_time).format('YYYY-MM-DD') %></p>
                                    <% } %>
                                    <% if (a.status === 2) { %>
                                        <div class="form-group">
                                            <label>审批意见<b class="text-danger">*</b></label>
                                            <textarea class="form-control" name="sdesc"></textarea>
                                            <input type="hidden" name="audit_id" value="<%= a.id %>">
                                        </div>
                                        <div class="alert alert-warning">
                                            <div class="form-check form-check-inline">
                                                <input class="form-check-input" type="radio" name="status" id="change-back" value="5">
                                                <label class="form-check-label" for="change-back">退回上报 <%= auditList[0].name %></label>
                                            </div>
                                            <% if (index !== 1) { %>
                                            <div class="form-check form-check-inline">
                                                <input class="form-check-input" type="radio" name="status" id="chagne-backnew" value="6">
                                                <label class="form-check-label" for="chagne-backnew">退回上一审批人 <%= auditList[index-1].name %></label>
                                                <input type="hidden" name="audit_last_id" value="<%= auditList[index-1].id %>">
                                            </div>
                                            <% } %>
                                            <div class="form-check form-check-inline">
                                                <input class="form-check-input" type="radio" name="status" id="change-stop" value="4">
                                                <label class="form-check-label" for="change-stop">终止</label>
                                            </div>
                                        </div>
                                        <div class="alert alert-danger change-approval-stop" style="display: none">
                                            审批终止，将结束本次审批，本条变更令作废。
                                        </div>
                                    <% } %>
                                </li>
                            <% } %>
                        </ul>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="w_code" value="">
                    <input type="hidden" name="change_id" value="<%= change.cid %>">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-warning change-approval-back approval-btn">确认退回</button>
                    <button type="button" class="btn btn-danger change-approval-stop approval-btn" style="display: none">确认终止</button>
                </div>
                </form>
            </div>
        </div>
    </div>
<% } %>

<!--添加附件-->
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="addfujian">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="myModalLabel">上传附件</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <p>上传文件大小最大：30MB</p>
                <p><input class="btn btn-primary" value="选择文件" type="file" id="upload-file" /></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="upload-file-btn">添加</button>
            </div>
        </div>
    </div>
</div>
