<?php if(count($items)>0): ?>
    <style>
        .color1 {
            background-color: #299AD6;
            color: white;
        }
    </style>
    <?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="5%" align="center" class="td_bg" nowrap></td>
                    <td width="5%" align="center" class="td_bg" nowrap><input type="checkbox" onclick="batchChoice($(this))"></td>
                    <td width="10%" align="center" class="td_bg" nowrap><input type="button" value="批量确认" class="color1" onclick="batchSave($(this),4)"></td>
                    <td align="center" class="td_bg" nowrap colspan="6"></td>
                </tr>
                <tr>
                    <td width="5%" align="center" class="bg_tr" nowrap>序号</td>
                    <td align="center" class="bg_tr" nowrap>选</td>
                    <td 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" nowrap><input type="checkbox" class="one-choice" value="<?= $item['id'] ?>"></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="confirmFix($(this),<?= $item['id'] ?>,4)" style="color: green;">确认</a>]
                            [<a href="javascript:void(0)" onclick="returnFix($(this),<?= $item['id'] ?>,<?= $item['fix_group'] ?>)" style="color: red;">退回</a>]
                        </td>
                        <td align="center" class="td_bg" style="word-break: break-all"><?= $store->category->name ?></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 st" nowrap>
                            <?php if(1 === $item['fix_status']): ?>
                                <span class="red_1">未检查</span>
                            <?php elseif(2 === $item['fix_status']): ?>
                                <span class="green_1">合格</span>
                            <?php elseif(3 === $item['fix_status']): ?>
                                <span class="red_1">不合格</span>
                            <?php endif; ?>
                        </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="5%" align="center" class="td_bg" nowrap></td>
                    <td width="5%" align="center" class="td_bg" nowrap><input type="checkbox" onclick="batchChoice($(this))"></td>
                    <td width="10%" align="center" class="td_bg" nowrap><input type="button" value="批量确认" class="color1" onclick="batchSave($(this),4)"></td>
                    <td align="center" class="td_bg" nowrap colspan="8"></td>
                </tr>
                <tr>
                    <td width="5%" align="center" class="bg_tr" nowrap>序号</td>
                    <td align="center" class="bg_tr" nowrap>选</td>
                    <td 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 if(7 === $item['fix_group'] || 13 === $item['fix_group']): ?>
                        <?php continue ?>
                    <?php endif; ?>
                    <?php $project = \common\models\FixCarProject::findOne($item['fk_id']) ?>
                    <input type="hidden" class="item_id" value="<?= $item['id'] ?>">
                    <tr>
                        <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                        <td align="center" class="td_bg" nowrap><input type="checkbox" class="one-choice" value="<?= $item['id'] ?>"></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="confirmFix($(this),<?= $item['id'] ?>,4)" style="color: green;">确认</a>]
                            [<a href="javascript:void(0)" onclick="returnFix($(this),<?= $item['id'] ?>,<?= $item['fix_group'] ?>)" style="color: red;">退回</a>]
                        </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"><?= is_null($item['report_id']) ? '--' : \common\models\FixCarReport::findOne($item['report_id'])->report_no ?></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><?= 1 == $item['pay_type'] ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg st" nowrap>
                            <?php if(1 === $item['fix_status']): ?>
                                <span class="red_1">未检查</span>
                            <?php elseif(2 === $item['fix_status']): ?>
                                <span class="green_1">合格</span>
                            <?php elseif(3 === $item['fix_status']): ?>
                                <span class="red_1">不合格</span>
                            <?php endif; ?>
                        </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="5%" 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="5%" 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 count" nowrap><?= $item['count'] ?></td>
                        <td align="center" class="td_bg" nowrap><?= $item['pay_type'] == 1 ? '保险理赔' : '自费维修' ?></td>
                        <td align="center" class="td_bg" nowrap>
                            <?php if($item['count'] <= 0): ?>
                                [<a href="javascript:void(0)">使用</a>]
                            <?php else: ?>
                                [<a href="javascript:void(0)" onclick="confirmFix($(this),<?= $item['id'] ?>,2)">使用</a>]
                            <?php endif; ?>
                        </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="5%" align="center" class="td_bg" nowrap></td>
                    <td width="5%" align="center" class="td_bg" nowrap><input type="checkbox" onclick="batchChoice($(this))"></td>
                    <td width="10%" align="center" class="td_bg" nowrap><input type="button" value="批量确认" class="color1" onclick="batchSave($(this),4)"></td>
                    <td align="center" class="td_bg" nowrap colspan="7"></td>
                </tr>
                <tr>
                    <td width="5%" align="center" class="bg_tr" nowrap>序号</td>
                    <td align="center" class="bg_tr" nowrap>选</td>
                    <td 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" nowrap><input type="checkbox" class="one-choice" value="<?= $item['id'] ?>"></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="confirmFix($(this),<?= $item['id'] ?>,4)" style="color: green;">确认</a>]
                            [<a href="javascript:void(0)" onclick="returnFix($(this),<?= $item['id'] ?>,<?= $item['fix_group'] ?>)" style="color: red;">退回</a>]
                        </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 st" nowrap>
                            <?php if(1 === $item['fix_status']): ?>
                                <span class="red_1">未检查</span>
                            <?php elseif(2 === $item['fix_status']): ?>
                                <span class="green_1">合格</span>
                            <?php elseif(3 === $item['fix_status']): ?>
                                <span class="red_1">不合格</span>
                            <?php endif; ?>
                        </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="5%" align="center" class="td_bg" nowrap></td>
                    <td width="5%" align="center" class="td_bg" nowrap><input type="checkbox" onclick="batchChoice($(this))"></td>
                    <td width="10%" align="center" class="td_bg" nowrap><input type="button" value="批量确认" class="color1" onclick="batchSave($(this),4)"></td>
                    <td align="center" class="td_bg" nowrap colspan="7"></td>
                </tr>
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td align="center" class="bg_tr" nowrap>选</td>
                    <td 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" nowrap><input type="checkbox" class="one-choice" value="<?= $item['id'] ?>"></td>
                        <td align="center" class="td_bg" nowrap>
                            [<a href="javascript:void(0)" onclick="confirmFix($(this),<?= $item['id'] ?>,4)" style="color: green;">确认</a>]
                            [<a href="javascript:void(0)" onclick="returnFix($(this),<?= $item['id'] ?>,<?= $item['fix_group'] ?>)" style="color: red;">退回</a>]
                        </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 st" nowrap>
                            <?php if(1 === $item['fix_status']): ?>
                                <span class="red_1">未检查</span>
                            <?php elseif(2 === $item['fix_status']): ?>
                                <span class="green_1">合格</span>
                            <?php elseif(3 === $item['fix_status']): ?>
                                <span class="red_1">不合格</span>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
        </div>
        <div style="clear: both"></div>
    <?php endif; ?>

<?php endif; ?>
<script>
    //确认维修
    function confirmFix(obj,itemId,type){
        if(itemId <= 0 || !confirm('确认提交吗？')) {
            return false;
        }
        $.post('/fix-car-item/confirm-fix',{item_id:itemId,type:type},function(data){
            alert(data.msg);
            if(data.success){
                if(4 == type){
                    obj.parents('tr').find('.st').removeClass('red_1').addClass('green_1').text('合格');
                }else if(2 == type){
                    obj.parents('tr').find('.count').text(data.content);
                    if(0 == data.content) obj.on('click',null);
                }
            }
        },'json');
    }
    //批量选择
    function batchChoice(obj){
        obj.parents('table').find('.one-choice').attr('checked',(obj.attr('checked') ? true : false));
    }
    //批量添加
    function batchSave(obj,type){
        if(type < 1 || !confirm('确认完成了吗?')) return false;
        var checkboxObj = obj.parents('table').find('.one-choice:checked'),
            len = checkboxObj.length,
            itemIds = [];
        if(len < 1) return false;

        checkboxObj.each(function(){
            itemIds.push($(this).val());
        });
        if(itemIds.length < 1) return false;
        $.post('/fix-car-item/batch-confirm-fix',{item_id:itemIds,type:type},function(data){
            alert(data.msg);
            if(data.success){
                if(4 == type){
                    checkboxObj.each(function(){
                        $(this).parents('tr').find('.st').removeClass('red_1').addClass('green_1').text('合格');
                    })
                }else{
                    checkboxObj.each(function(i){
                        $(this).parents('tr').find('.count').text(data.content[i]);
                    })
                }
            }
        });
    }
    //不合格
    function returnFix(obj,id,gid) {
        if(id < 1 || gid < 1) return false;
        $.post('/fix-car-item/return',{id:id,gid:gid},function(data){
            alert(data.msg);
            if(data.success){
                obj.parents('tr').find('.st').removeClass('green_1').addClass('red_1').text('不合格');
            }
        },'json');
    }
</script>