<% if (ctx.session.sessionUser.accountId === ctx.tender.data.user_id && ctx.tender.data.ledger_status === auditConst.status.checked &&
        (stages.length === 0 || stages[stages.length- 1].status === auditConst.status.checked)) { %>
<!--弹出添加期-->
<div class="modal fade" id="add-qi" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <form class="modal-content" action="<%- preUrl + '/measure/stage/add' %>" method="post">
            <div class="modal-header">
                <h5 class="modal-title">添加新一期</h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label>期</label>
                    <input class="form-control" value="第 <%- stages.length + 1 %> 期" type="text" readonly="">
                </div>
                <div class="form-group">
                    <label>计量年月</label>
                    <input class="datepicker-here form-control" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text" name="date">
                </div>
                <div class="form-group">
                    <label>开始-截止日期</label>
                    <input class="datepicker-here form-control" placeholder="点击选择时间" data-range="true" data-multiple-dates-separator=" ~ " data-language="zh" type="text" name="period">
                </div>
            </div>
            <div class="modal-footer">
                <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-primary">确定添加</button>
            </div>
        </form>
    </div>
</div>
<% } %>
<!--审批流程/结果-->
<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">
                                <li class="list-group-item"><i class="fa fa fa-play-circle fa-rotate-90"></i> 布尔  <small class="text-muted">施工</small></li>
                                <li class="list-group-item"><i class="fa fa-chevron-circle-down"></i> 张三  <small class="text-muted">监理</small></li>
                                <li class="list-group-item"><i class="fa fa-chevron-circle-down"></i> 王五 <small class="text-muted">监理</small></li>
                                <li class="list-group-item"><i class="fa fa fa-stop-circle"></i> 李四 <small class="text-muted">监理</small></li>
                            </ul>
                        </div>
                    </div>
                    <div class="col-8 modal-height-500" style="overflow: auto">
                        <div class="card mt-3">
                            <ul class="list-group list-group-flush">
                                <li class="list-group-item">
                                    <span class="text-success pull-right">上报</span>
                                    <h5 class="card-title"><i class="fa fa-play-circle fa-rotate-90 text-success"></i> 布尔 <small class="text-muted">施工</small></h5>
                                    <p class="card-text">2017-11-25</p>
                                </li>
                                <li class="list-group-item">
                                    <span class="text-success pull-right">审批通过</span>
                                    <h5 class="card-title"><i class="fa fa-chevron-circle-down text-success"></i> 张三 <small class="text-muted">监理</small></h5>
                                    <p class="card-text">审批意见。2017-11-25</p>
                                </li>
                                <li class="list-group-item">
                                    <span class="text-success pull-right">审批通过</span>
                                    <h5 class="card-title"><i class="fa fa-chevron-circle-down text-success"></i> 王五 <small class="text-muted">监理</small></h5>
                                    <p class="card-text">审批通过。2017-11-26</p>
                                </li>
                                <li class="list-group-item">
                                    <span class="text-warning pull-right">审批退回 布尔</span>
                                    <h5 class="card-title"><i class="fa fa-stop-circle text-warning"></i> 李四 <small class="text-muted">监理</small></h5>
                                    <p class="card-text">审批退回，审批意见文本。2017-11-27</p>
                                </li>
                            </ul>
                        </div>
                        <!--退回原报重新上报-->
                        <div class="card mt-3">
                            <ul class="list-group list-group-flush">
                                <li class="list-group-item">
                                    <span class="text-success pull-right">重新上报</span>
                                    <h5 class="card-title"><i class="fa fa-play-circle fa-rotate-90 text-success"></i> 布尔 <small class="text-muted">施工</small></h5>
                                    <p class="card-text">2017-12-01</p>
                                </li>
                                <li class="list-group-item">
                                    <span class="text-success pull-right">审批通过</span>
                                    <h5 class="card-title"><i class="fa fa-chevron-circle-down text-success"></i> 张三 <small class="text-muted">监理</small></h5>
                                    <p class="card-text">审批通过 2017-12-02</p>
                                </li>
                                <li class="list-group-item">
                                    <span class="text-warning pull-right">审批退回 张三</span>
                                    <h5 class="card-title"><i class="fa fa-chevron-circle-down text-warning"></i> 王五 <small class="text-muted">监理</small></h5>
                                    <p class="card-text">审批退回 2017-12-02</p>
                                </li>
                                <!--王五退回上一审批人 张三，张三重新审批-->
                                <li class="list-group-item">
                                    <span class="pull-right">审批中</span>
                                    <h5 class="card-title"><i class="fa fa-chevron-circle-down"></i> 张三 <small class="text-muted">监理</small></h5>
                                    <p class="card-text"></p>
                                </li>
                                <li class="list-group-item">
                                    <h5 class="card-title"><i class="fa fa-stop-circle"></i> 李四 <small class="text-muted">监理</small></h5>
                                </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 (stages.length > 0 && stages[0].status === auditConst.status.uncheck && stages[0].user_id === ctx.session.sessionUser.accountId) { %>
<!--设置-->
<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>期</label>
                    <input class="form-control" value="第 <%- stages[0].order %> 期" type="text" readonly="" name="name">
                </div>
                <div class="form-group">
                    <label>计量年月</label>
                    <input class="datepicker-here form-control" name="edit-date" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text" value="<%- stages[0].s_time %>">
                </div>
                <div class="form-group">
                    <label>开始-截止日期</label>
                    <input class="datepicker-here form-control" name="edit-period" placeholder="点击选择时间" data-range="true" data-multiple-dates-separator=" ~ " data-language="zh" type="text" value="<%- stages[0].period %>">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="edit-ok" s-order="<%- stages[0].order%>">确定修改</button>
            </div>
        </div>
    </div>
</div>
<% } %>
<script src="/public/js/datepicker/datepicker.min.js"></script>
<script src="/public/js/datepicker/datepicker.zh.js"></script>
<script>
    $('#edit-ok').click(function () {
        const data = {
            order: parseInt($(this).attr('s-order')),
            date: $('input[name=edit-date]').val(),
            period: $('input[name=edit-period]').val(),
        };
        if (data.date === '' || data.period === '') {
            return;
        }
        const tenderId = window.location.pathname.split('/')[2];
        postData('/tender/' + tenderId + '/measure/stage/save', data, function () {
            $('#edit').modal('hide');
        });
    });
</script>