<% include ../tender/tender_sub_menu.ejs %>
<div class="panel-content">
    <div class="panel-title">
        <div class="title-main d-flex justify-content-between">
            <h2>
                期列表
            </h2>
            <div>
                <% if (ctx.session.sessionUser.accountId === ctx.tender.data.user_id && ctx.tender.data.ledger_status === auditConst.status.checked &&
                        (stages.length === 0 || stages[0].status === auditConst.status.checked)) { %>
                <a href="#add-qi" data-toggle="modal" data-target="#add-qi" class="btn btn-primary btn-sm pull-right">开始新一期</a>
                <% } %>
            </div>
        </div>
    </div>
    <div class="content-wrap">
        <div class="c-body">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>期数</th>
                    <th class="text-center">计量月份</th>
                    <th class="text-center">本期合同计量</th>
                    <th class="text-center">本期数量变更计量</th>
                    <th class="text-center">本期完成计量</th>
                    <th class="text-center">截止上期完成计量</th>
                    <th class="text-center">截止本期完成计量</th>
                    <th class="text-center">审批状态</th>
                    <th class="text-center">审批进度</th>
                </tr>
                </thead>
                <tbody>
                <% for (const s of stages) { %>
                <tr>
                    <td>
                        <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>">第 <%- s.order %> 期</a>
                        <% if (s.status === auditConst.status.uncheck && s.user_id === ctx.session.sessionUser.accountId) { %>
                        <a href="#edit" data-toggle="modal" data-target="#edit"><i class="fa fa-pencil-square-o "></i></a>
                        <% } %>
                    </td>
                    <td class="text-center"><%- s.s_time %></td>
                    <td class="text-right"><%- (s.contract_tp ? s.contract_tp : '')%></td>
                    <td class="text-right"><%- (s.qc_tp ? s.qc_tp : '')%></td>
                    <td class="text-right"><%- (s.tp ? s.tp : '')%></td>
                    <td class="text-right"><%- (s.pre_tp ? s.pre_tp : '')%></td>
                    <td class="text-right"><%- (s.end_tp ? s.end_tp : '')%></td>
                    <td class="text-center">
                    <% if (s.status === auditConst.status.uncheck && s.user_id === ctx.session.sessionUser.accountId) { %>
                        <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
                    <% } else if (s.status === auditConst.status.checkNo && s.curAuditor && s.user_id === ctx.session.sessionUser.accountId) { %>
                        <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
                    <% } else if (s.status === auditConst.status.checking && s.curAuditor && s.curAuditor.aid === ctx.session.sessionUser.accountId) { %>
                        <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
                    <% } else if (s.status === auditConst.status.checkNoPre && s.curAuditor && s.curAuditor2.aid === ctx.session.sessionUser.accountId) { %>
                        <a href="<%- '/tender/' + ctx.tender.id + '/measure/stage/' + s.order %>" class="btn <%- auditConst.statusButtonClass[s.status] %> btn-sm"><%- auditConst.statusButton[s.status] %></a>
                    <% } else { %>
                        <span class="<%- auditConst.auditStringClass[s.status] %>"><%- auditConst.auditString[s.status] %></span>
                    <% } %>
                    </td>

                    <td class="<%- auditConst.auditProgressClass[s.status] %>">
                        <% if (s.curAuditor) { %>
                        <a href="#sp-list" data-toggle="modal" data-target="#sp-list" s-order="<%- s.order %>"><%- s.curAuditor.name %><%if (s.curAuditor.role !== '' && s.curAuditor.role !== null) { %>-<%- s.curAuditor.role %><% } %></a>
                        <% } %>
                        <%- auditConst.auditProgress[s.status] %>
                    </td>
                </tr>
                <% } %>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    const stages = JSON.parse('<%- JSON.stringify(stages) %>');
</script>
