<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 width="30" align="center" class="bg_tr">操作</td>
    </tr>
    <?php if (count($items) > 0): ?>
        <?php foreach ($items as $index=>$item): ?>
            <?php $store = \common\models\StoreRoom::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><?= $store->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><?= $store->good_sn ?></td>
                <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                <td align="center" class="td_bg" nowrap><?= $store->selling_price ?>元</td>
                <td align="center" class="td_bg">
                    <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;
    }
    //删除
    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>