<?php if(count($items)>0): ?>
    <style>
        .color1 {
            background-color: #299AD6;
            color: white;
        }
    </style>
    <?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[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),1)"></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'] ?>,1)" style="color: green;">确认</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(0 == $item['fix_status']): ?>
                                <span class="red_1">未确认</span>
                            <?php elseif(1 == $item['fix_status']): ?>
                                <span class="green_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;
        obj.parents('tr').find('.one-choice').attr('checked',true);
        $.post('/fix-car-item/confirm-fix',{item_id:itemId,type:type},function(data){
            alert(data.msg);
            if(data.success){
                if(1 == type){
                    obj.parents('tr').find('.st').removeClass('red_1').addClass('green_1').text('已确认');
                }else{
                    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(1 == 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]);
                    })
                }
            }
        });
    }
</script>