goods_list.html 5.1 KB
<include file="public@header"/>
</head>
<body>
<style>
    .pagination{text-align:center;margin-top:20px;margin-bottom: 20px;}
    .pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 3px 8px;display: inline-block;}
    .pagination .active{background-color: #dd1a20;color: #fff;}
    .pagination .disabled{color:#aaa;}
</style>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#">商品列表</a></li>
        <li><a href="{:url('Goods/goods_add')}">添加商品</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('Goods/goods_list')}">
        时间:
        <input type="text" class="form-control js-bootstrap-datetime" name="start_time"
               value="{$start_time|default=''}"
               style="width: 140px;" autocomplete="off">-
        <input type="text" class="form-control js-bootstrap-datetime" name="end_time"
               value="{$end_time|default=''}"
               style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
        关键字:
        <input type="text" class="form-control" name="keyword" style="width: 200px;"
               value="{$keyword|default=''}" placeholder="请输入商品名称...">
        分类:
        <select name="classify_id" class="form-control">
            <option value="100">全部</option>
            <option value="0">为空</option>
            <volist name="classif_data" id="vo">
                <option value="{$vo.id}" <eq name="classify_id" value="$vo['id']">selected</eq> >{$vo.name}</option>
            </volist>
        </select>
        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('Goods/goods_list')}">清空</a>
    </form>
    <table class="table table-hover table-bordered table-list">
        <thead>
        <tr>
            <th>序号</th>
            <th>商品名称</th>
            <th>分类</th>
            <th>售价</th>
            <th>销量</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <volist name="data" id="vo">
            <tr class="tr{$vo.id}">
                <td>{$vo.id}</td>
                <td>{$vo.book_name}</td>
                <td>{$vo.classify_name|default='为空'}</td>
                <td>{$vo.price}</td>
                <td>{$vo.sales}</td>
                <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
                <td>
                    <a href="{:url('Goods/goods_edit',array('id'=>$vo.id))}"><button type="button" class="btn btn-default edit{$vo.id}">编辑</button></a>
                    <if condition="$vo.is_out eq 1">
                        <button type="button" class="btn btn-default out{$vo.id}" onclick="sold_out({$vo.id});">下架</button>
                    <else/>
                        <button type="button" class="btn btn-default out{$vo.id}" style="background-color: red" onclick="putaway({$vo.id});">上架</button>
                    </if>
                    <button type="button" class="btn btn-default" onclick="del({$vo.id})">删除</button>
                </td>
            </tr>
        </volist>

        </tbody>
    </table>
    <div class="pagination">
        {$res -> render()}
    </div>
    <div>
        <a href="{:url('Goods/goods_new')}"><button type="button" class="btn btn-primary">推荐新品</button></a>
        <a href="{:url('Goods/goods_hot')}"><button type="button" class="btn btn-primary">推荐热门</button></a>
    </div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    function reloadPage(win) {
        win.location.reload();
    }

    /**
     *点击下架
     */
    function sold_out(id){
        ccc = window.confirm('是否下架商品?');
        if(ccc){
            $.post("{:url('Goods/sold_out')}",{id:id},function(data){
                if(data){
                    $('.out'+id).remove();
                    $('.edit'+id).parent().after("<button type='button' class='btn btn-default out"+id+"' onclick='putaway("+id+");' style='background-color: red'>上架</button>");
                }else{
                    alert('下架失败');
                }
            });
        }
    }

    /**
     *点击上架
     */
    function putaway(id){
        ccc = window.confirm('是否上架商品?');
        if(ccc){
            $.post("{:url('Goods/putaway')}",{id:id},function(data){
                if(data){
                    $('.out'+id).remove();
                    $('.edit'+id).parent().after("<button type='button' class='btn btn-default out"+id+"' onclick='sold_out("+id+");'>下架</button>");
                }else{
                    alert('上架失败');
                }
            });
        }
    }

    /**
     *点击删除 
     */
    function del(id){
        ccc = window.confirm('是否删除这条商品?');
        if(ccc){
            $.post("{:url('Goods/goods_del')}",{id:id},function(data){
                if(data){
                    $('.tr'+id).remove();
                }else{
                    alert('删除失败')
                }
            });
        }
    }
    
</script>
</body>
</html>