<?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) {
        window.location.href = '/gift-group/edit?id=' + id;
    }
    //删除
    function del(id) {
        if(confirm('是否确认删除?')) {
            $.post('/gift-group/delete',{id:id},function(obj){
                alert(obj.msg);
                if(obj.success) {
                    window.location.reload();
                }
            },'json');
        }
    }

    $(function(){
        $("#search-btn").click(function(){
            var params = $('#searchForm').serialize();
            window.location.href = "/gift-group/index?" + params;
        });
        $('#add-btn').click(function(){
            edit(0);
        });
    });
</script>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="searchForm">
        <tr>
            <td class="td_bg">
                名称:<input name="name" type="text" value="<?=$name?>">
                <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
                <input type="button" class="act_btn" id="add-btn" name="add-btn" value="添加">
            </td>
        </tr>
    </form>
</table>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
        <td align="center" width="24" align="center" class="bg_tr">ID</td>
        <td width="150" align="center" align="center" class="bg_tr">分类名称</td>
        <td width="50" align="center" align="center" class="bg_tr">是否免费</td>
        <td width="50" align="center" align="center" class="bg_tr">是否车损险</td>
        <td width="100" align="center" align="center" class="bg_tr">最低额度</td>
        <td width="100" align="center" align="center" class="bg_tr">最高额度</td>
        <td width="300" align="center" align="center" class="bg_tr">包含礼品</td>
        <td width="30" align="center" class="bg_tr">操作</td>
    </tr>
    <?php
    foreach($items as $index => $item) {
        ?>
        <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
            <td align="center" class="td_bg"nowrap ><?=$item->id?></td>
            <td align="left" class="td_bg"nowrap ><?=$item->name?></td>
            <td align="center" class="td_bg"nowrap ><?=$item->is_free==1?'是':''?></td>
            <td align="center" class="td_bg"nowrap ><?=$item->is_damage==1?'是':''?></td>
            <td align="center" class="td_bg"nowrap ><?=$item->min_money==0?'无限制':$item->min_money.'元'?></td>
            <td align="center" class="td_bg"nowrap ><?=$item->max_money==0?'无限制':$item->max_money.'元'?></td>
            <td align="left" class="td_bg"nowrap ><?php
            if($item->gifts) foreach($item->gifts as $gift) {
                echo $gift->name.', ';
            }
                ?></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
    }
    ?>
</table>