<?php
use \common\libs\MyLib;
?>
<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>
<script type="text/javascript" language="javascript">
    //详情
    function edit(id) {
        var params = $('#searchForm').serialize();
        window.location.href = '/gift2/edit?id=' + id + '&back_params=' + encodeURIComponent(params);
    }
    //删除
    function del(id) {
        if(confirm('是否确认删除?')) {
            $.post('/gift2/delete',{id:id},function(obj){
                alert(obj.msg);
                if(obj.success) {
                    window.location.reload();
                }
            },'json');
        }
    }
    $(function(){
        $("#search-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/gift2/gift1-index?" + params;
        });
        $('#input-btn').click(function(){
            window.location.href = '/gift2/add';
        });
        $('#output-btn').click(function(){
            window.location.href = '/gift2/output';
        });
    });
</script>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="searchForm">
    <tr>
        <td class="td_bg">
            编号：<input name="code" type="text" value="<?=$code?>">
            车牌：<input name="car_no" type="text" value="<?=$car_no?>">
            状态：<select name="status">
                <option value="6" <?=$status==6?'selected':''?>>全部状态</option>
                <option value="0" <?=$status==0?'selected':''?>>未使用</option>
                <option value="1" <?=$status==1?'selected':''?>>已出库</option>
                <option value="2" <?=$status==2?'selected':''?>>已使用</option>
            </select>
            分类：<select name="type_id">
                <option value="0">---请选择---</option>
                <?php
                foreach($type_items as $item) {
                    echo '<option value="'.$item->id.'"';
                    if($type_id == $item->id)
                        echo ' selected ';
                    echo '>'.$item->name.'</option>';
                }
                ?>
            </select>
            <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
            <input type="button" class="act_btn" id="input-btn" name="input-btn" value="入库">
            <input type="button" class="act_btn" id="output-btn" name="output-btn" value="出库">
        </td>
    </tr>
    </form>
</table>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
        <td width="30" align="center" class="bg_tr" nowrap>序号</td>
        <td width="120" align="center" class="bg_tr" nowrap>礼券编号</td>
        <td width="60%" align="center" class="bg_tr" nowrap>礼券</td>
        <td width="120" align="center" class="bg_tr" nowrap>车牌号</td>
        <td width="120" align="center" class="bg_tr" nowrap>使用时间</td>
        <td width="120" align="center" class="bg_tr" nowrap>状态</td>
        <td width="120" align="center" class="bg_tr" nowrap>操作员</td>
        <td width="120" align="center" class="bg_tr" nowrap>操作</td>
    </tr>
    <?php
    foreach($items as $index => $item) {
        $start_index = ($page - 1) * 20 + $index;
        ?>
        <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
            <td align="center" class="td_bg"n owrap ><?=$start_index + 1?></td>
            <td class="td_bg" nowrap><?=sprintf("%07d",$item->code)?></td>
            <td class="td_bg" nowrap><?=$item->type->name?></td>
            <td class="td_bg" nowrap><?=$item->car_no?></td>
            <td class="td_bg" nowrap><?=$item->use_date?></td>
            <td class="td_bg" ><?=$item->getStatus()?>&nbsp;</td>
            <td class="td_bg" ><?php
                if($item->status > 0)
                    echo $item->user?$item->user->getShowName():''
                ?></td>
            <td align="center" class="td_bg" nowrap>
                [<a href="javascript:void(0);" onclick="edit(<?=$item->id?>)">操作</a>]
                [<a href="javascript:void(0);" onclick="del(<?=$item->id?>)">删除</a>]
            </td>
        </tr>
        <?php
    }
    ?>
    <tr >
        <td height="25" colspan="14" align="center" class="td_bg"><?=$page_info?></td>
    </tr>
</table>
