<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.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="2" cellspacing="1" class="table">
    <tr>
        <td width="50" align="center" align="center" class="bg_tr" nowrap>排序</td>
        <td align="center" align="center" class="bg_tr">修理项目</td>
        <td align="center" align="center" class="bg_tr">修理编码</td>
        <td align="center" align="center" class="bg_tr">修理分组</td>
        <td align="center" align="center" class="bg_tr">程度</td>
        <td align="center" align="center" class="bg_tr">新车购置价</td>
        <td align="center" align="center" class="bg_tr">市场参考费用</td>
        <td align="center" align="center" class="bg_tr">结算类型</td>
        <td align="center" align="center" class="bg_tr">备注</td>
        <td width="30" align="center" class="bg_tr">操作</td>
    </tr>
    <?php if (count($items) > 0): ?>
        <?php foreach ($items as $index => $item): ?>
            <?php $project = \common\models\FixCarProject::findOne(['id' => $item->fk_id]); ?>
            <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
                <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                <td align="center" class="td_bg"
                    nowrap><?= $project->category->name ?>
                    <?php if($item->mark_wait_list > 0 ): ?>
                        <sup style="color:red;">待定</sup>
                    <?php else: ?>
                        <?= (0 == $item->status) ? '<sup style="color:red;">new</sup>' : '' ?>
                    <?php endif; ?>
                </td>
                <td align="center" class="td_bg" nowrap>--</td>
                <td align="center" class="td_bg" nowrap><?= $project->group ? $project->group->name : '' ?></td>
                <td align="center" class="td_bg" nowrap>
                    <?php if(7 == $project->group_id): ?>
                        <select name="level" onchange="levelChange($(this).val(),<?= $project->category_id ?>,<?= $item->id ?>)">
                            <option value="1" <?= 7 == $project->group_id ? (1 == $project->car_price ? 'selected' : '') : '' ?>>微伤</option>
                            <option value="2" <?= 7 == $project->group_id ? (2 == $project->car_price ? 'selected' : '') : '' ?>>轻度</option>
                            <option value="3" <?= 7 == $project->group_id ? (3 == $project->car_price ? 'selected' : '') : '' ?>>中度</option>
                            <option value="4" <?= 7 == $project->group_id ? (4 == $project->car_price ? 'selected' : '') : '' ?>>重度</option>
                        </select>
                    <?php else: ?>
                        --
                    <?php endif; ?>
                </td>
                <td align="center" class="td_bg" nowrap><?= 7 == $project->group_id ? '--' : $project->car_price ?><?= 7==$project->group_id ? '' : '万元' ?></td>
                <!--            <td align="left" class="td_bg" nowrap></td>-->
                <td align="center" class="td_bg" nowrap>0元</td>
                <td align="center" class="td_bg" nowrap>
                    <select onchange="payTypeChange($(this).val(),<?= $item->id ?>)">
                        <option value="1" <?= 1 == $item->pay_type ? 'selected' : '' ?>>保险理赔</option>
                        <option value="2" <?= 2 == $item->pay_type ? 'selected' : '' ?>>自费维修</option>
                    </select>
                </td>
                <td align="center" class="td_bg" nowrap></td>
                <td align="center" class="td_bg" nowrap>
                    [<a href="javascript:void(0);" onclick="del(<?= $item->id ?>,<?= $item->fix_group ?>,$(this))">删除</a>]
                </td>
            </tr>
        <?php endforeach; ?>
    <?php endif; ?>
    <tr>
        <td height="25" colspan="12" align="center" class="td_bg"></td>
    </tr>
</table>
<script type="text/javascript" language="javascript">
    //编辑
    function edit(id) {
        window.location.href = '/store-room/put-in-store-info?id=' + id;
    }
    //损伤程度 change 事件
    function levelChange(level,categoryID,ID){
        if(!level || !categoryID || !ID) return false;
        $.post('/fix-car-item/change-level',{level:level,category_id:categoryID,id:ID},function(data){
            if(data.success){
                location.reload();
            }
        },'json')
    }
    //删除
    function del(id,gid,obj){
        if(!confirm("确定要删除吗？")) return false;
        obj.parents('tr').addClass('js-rm-'+id);
        $.post('/fix-car-item/delete',{id:id,gid:gid},function(data){
            if(data.success){
                $('.js-rm-'+id).remove();
            }
        },'json')
    }
    //结算类型 change 事件
    function payTypeChange(payType,id){
        if(!payType || !id) return false;
        $.post('/fix-car-item/pay-type-change',{pay_type:payType,id:id},function(data){
            alert(data.msg);
        },'json')
    }
</script>
