<?php if(count($items)>0): ?>
    <?php if(isset($items[1])): ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list3')">更换清单<span id="list3_title">▼</span></h3>
        </div>
        <div id="list3">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>零件名</td>
                    <td width="100" align="center" class="bg_tr" nowrap>报案号</td>
                    <td width="80" align="center" class="bg_tr" nowrap>保险定价</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[1] as $index => $item): ?>
                    <?php $store = \common\models\StoreRoom::findOne($item['fk_id']); ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $store->category->name ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($reports) && count($reports) > 0): ?>
                                <select onchange="changeReport($(this),<?= $item['id'] ?>)">
                                    <?php foreach($reports as $report): ?>
                                        <option value="<?= $report->id ?>" <?= $item['report_id'] === $report->id ? 'selected' : '' ?>><?= $report->report_no ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php else: ?>
                                --
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" nowrap><?= $item['insurance_price'] ?>元</td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= number_format($store->price * ($store->fixCarScale->scale/100+1),2) ?>元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
    <?php if(isset($items[2])): ?>
        <?php $group_name =[1=>'微伤',2=>'轻度',3=>'中度',4=>'重度'] ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list4')">维修清单<span id="list4_title">▼</span></h3>
        </div>
        <div id="list4">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>修理项目</td>
                    <td width="100" align="center" class="bg_tr" nowrap>报案号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>修理分组</td>
                    <td width="100" align="center" class="bg_tr" nowrap>损伤程度</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[2] as $index => $item): ?>

                    <?php $project = \common\models\FixCarProject::findOne($item['fk_id']) ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $project->category->name ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($reports) && count($reports) > 0): ?>
                                <select onchange="changeReport($(this),<?= $item['id'] ?>)">
                                    <?php foreach($reports as $report): ?>
                                        <option value="<?= $report->id ?>" <?= $item['report_id'] === $report->id ? 'selected' : '' ?>><?= $report->report_no ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php else: ?>
                                --
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $project->group->name ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= 7 == $project->group_id ? $group_name[$project->car_price] : '--' ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $project->price ?>元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
    <?php if(isset($items[3])): ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list5')">辅料清单<span id="list5_title">▼</span></h3>
        </div>
        <div id="list5">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>辅料名</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[3] as $index => $item): ?>
                    <?php $store = \common\models\StoreRoom::findOne($item['fk_id']); ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $store->category->name ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $store->price ?>元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
    <?php if(isset($items[4])): ?>
        <?php $group_name =[1=>'微伤',2=>'轻度',3=>'中度',4=>'重度'] ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list6')">待定清单<span id="list6_title">▼</span></h3>
        </div>
        <div id="list6">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>零件名/维修项目</td>
                    <td width="100" align="center" class="bg_tr" nowrap>修理分组</td>
                    <td width="100" align="center" class="bg_tr" nowrap>损伤程度</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[4] as $index => $item): ?>
                    <?php $store = $project = null; ?>
                    <?php if(1 == $item['mark_wait_list']): ?>
                        <?php $store = \common\models\StoreRoom::findOne($item['fk_id']) ?>
                    <?php elseif(2 == $item['mark_wait_list']): ?>
                        <?php $project = \common\models\FixCarProject::findOne($item['fk_id']) ?>
                    <?php endif; ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($store)): ?>
                                <?= $store->category->name ?>
                            <?php elseif(isset($project)): ?>
                                <?= $project->category->name ?>
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($store)): ?>
                                --
                            <?php elseif(isset($project)): ?>
                                <?= $project->group->name ?>
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($store)): ?>
                                --
                            <?php elseif(isset($project)): ?>
                                <?php if(7 == $project->group_id): ?>
                                    <?= $group_name[$project->car_price] ?>
                                <?php else: ?>
                                    --
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($store)): ?>
                                <?= $store->price ?>
                            <?php elseif(isset($project)): ?>
                                <?= $project->price ?>
                            <?php endif; ?>
                            元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
    <?php if(isset($items[6])): ?>
        <?php $group_name =[1=>'微伤',2=>'轻度',3=>'中度',4=>'重度'] ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list7')">保养清单<span id="list7_title">▼</span></h3>
        </div>
        <div id="list7">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>零件名/维修项目</td>
                    <td width="100" align="center" class="bg_tr" nowrap>报案号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>修理分组</td>
                    <td width="100" align="center" class="bg_tr" nowrap>损伤程度</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[6] as $index => $item): ?>
                    <?php $store = $project = null; ?>
                    <?php $project = \common\models\FixCarProject::findOne($item['fk_id']) ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->category->name ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?php if(isset($reports) && count($reports) > 0): ?>
                                <select onchange="changeReport($(this),<?= $item['id'] ?>)">
                                    <?php foreach($reports as $report): ?>
                                        <option value="<?= $report->id ?>" <?= $item['report_id'] === $report->id ? 'selected' : '' ?>><?= $report->report_no ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php else: ?>
                                --
                            <?php endif; ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->group->name ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">--</td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->price ?>
                            元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
    <?php if(isset($items[5])): ?>
        <?php $group_name =[1=>'微伤',2=>'轻度',3=>'中度',4=>'重度'] ?>
        <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
            <h3 onclick="show('list8')">美容装饰<span id="list8_title">▼</span></h3>
        </div>
        <div id="list8">
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>零件名/维修项目</td>
                    <td width="100" align="center" class="bg_tr" nowrap>修理分组</td>
                    <td width="100" align="center" class="bg_tr" nowrap>损伤程度</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <?php foreach ($items[5] as $index => $item): ?>
                    <?php $store = $project = null; ?>
                    <?php $project = \common\models\FixCarProject::findOne($item['fk_id']) ?>
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->category->name ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->group->name ?>
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all">--</td>
                        <td align="center" class="td_bg" style="word-break: break-all">
                            <?= $project->price ?>
                            元</td>
                        <td align="center" class="td_bg" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="deleteItem(<?= $item['id'] ?>,<?= $item['fix_group'] ?>,$(this))">删除</a>]
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>
<?php endif; ?>
<script>
    function changeReport(obj,id){
        var report_id = obj.val();
        if(id < 1 || report_id < 1) return false;
        $.post('/fix-car-item/change-item-report',{id:id,report_id:report_id},function(data){
            alert(data.msg);
        },'json');
    }
    function deleteItem(id,gid,obj){
        if(!confirm('确定要删除吗?')) return false;
        obj.parents('tr').addClass('del_' + id);
        $.post('/fix-car-item/delete',{id:id,gid:gid},function(data){
            alert(data.msg);
            if(data.success){
                $('.del_' + id).remove();
            }
        },'json');
    }
</script>
