<?php
use \common\libs\MyLib;
?>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <form id="searchForm">
        <tr>
            <td class="td_bg">
                <span>车牌号：<input name="car_no" type="Text" value="<?= $car_no ?>"></span>
                <span style="margin-left:30px;">
                    <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
                </span>
            </td>
        </tr>
    </form>
</table>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
        <td width="50" align="center" align="center" class="bg_tr">序号</td>
        <td width="50" align="center" align="center" class="bg_tr">车牌号</td>
        <td width="50" align="center" align="center" class="bg_tr">客户姓名</td>
        <td width="50" align="center" align="center" class="bg_tr">进厂日期</td>
        <td width="50" align="center" align="center" class="bg_tr">出厂日期</td>
        <td width="50" align="center" align="center" class="bg_tr">状态</td>
        <td width="50" align="center" align="center" class="bg_tr">结算类型</td>
        <td width="50" align="center" align="center" class="bg_tr">报案号</td>
        <td width="50" align="center" align="center" class="bg_tr">操作</td>
    </tr>
    <?php if($car_list): ?>
        <?php foreach($car_list as $k=>$v): ?>
            <?php $query = \common\models\FixCarItemT::find()->where('fix_id='.$v->id)->groupBy('report_id') ?>
            <?php $count = $query->count() ?>
            <?php $items = $query->all() ?>
            <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $k+1 ?></td>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $v->car_no ?></td>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $v->id_man ?></td>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $v->submit_date ?></td>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $v->finish_date ?></td>
                <td width="50" align="center" align="center" class="td_bg" rowspan="<?= $count ?>"><?= $v ? $v->getStatus():'' ?></td>
                <td width="50" align="center" align="center" class="td_bg"><?= count($items) > 0 ? ($items[0]->report_id ? '保险理赔' : '自费维修') : '' ?></td>
                <td width="50" align="center" align="center" class="td_bg"><?= count($items) > 0 ? ($items[0]->report_id ? $items[0]->report->report_no : '--') : '' ?></td>
                <td width="50" align="center" align="center" class="td_bg">
                    <a href="javascript:;" class="acc_detail" onclick="itemInfo(<?= $v->id ?>,<?= count($items) ? $items[0]->report_id : '' ?>)">
                        <?php if( 15 === $v->status): ?>
                            <span style="color: green;">[详情]</span>
                        <?php else: ?>
                            <span style="color: red;">[查看]</span>
                        <?php endif; ?>
                    <a/>
                </td>
            </tr>
            <?php unset($items[0]) ?>
            <?php if(count($items)>0): ?>
                <?php foreach($items as $k=>$item): ?>
                    <tr>
                        <td width="50" align="center" align="center" class="td_bg"><?= $item->report_id ? '保险理赔' : '自费维修' ?></td>
                        <td width="50" align="center" align="center" class="td_bg"><?= $item->report_id ? $item->report->report_no : '--' ?></td>
                        <td width="50" align="center" align="center" class="td_bg">
                            <a href="javascript:;" class="acc_detail" onclick="itemInfo(<?= $v->id ?>,<?= $item->report_id ?>)">
                                <?php if( 15 === $v->status): ?>
                                    <span style="color: green;">[详情]</span>
                                <?php else: ?>
                                    <span style="color: red;">[查看]</span>
                                <?php endif; ?>
                                <a/>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        <?php endforeach; ?>
    <?php endif; ?>
</table>
<script>
    $("#search-btn").click(function(){
        var params = $('#searchForm').serialize();
        window.location.href = "/fix-car-finance/list-accounts?" + params;
    });
//    $(".acc_detail").click(function(){
//        var acc_id = $(this).attr('data');
//        window.location.href = "/fix-car-finance/settle-accounts?acc_id=" + acc_id;
//    });
    function itemInfo(fixId,reportId){
        if(fixId < 1) return false;
        reportId = !reportId ? '' : reportId;
        window.location.href = "/fix-car-finance/settle-accounts?fix_id=" + fixId + "&report_id=" + reportId;
    }
</script>
