<div class="layui-layout layui-layout-admin" style="padding-left: 20px;">
    <div class="layui-row" style="margin-top: 20px;">
        <div class="layui-col-xs6">
            <a class="layui-btn layui-btn-sm" data-type="tabAdd" id="tabAdd" href="javascript:void(0)">新增</a>
        </div>
        <div class="layui-col-xs6 search_text">
            <form class="layui-form" action="" onsubmit="javascript:return false;">
                <div class="demoTable">
                    <div class="layui-inline" style="width: 40%">
                        <input class="layui-input" name="code" id="code" autocomplete="off" placeholder="禁用命令" >
                    </div>
                    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button>
                </div>
            </form>

        </div>
    </div>

    <table class="layui-hide" id="table_list" lay-filter="table_filter">
    </table>

    <script type="text/html" id="bar">
        <!--  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a> -->
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

    </script>
</div>
<script>

    layui.use(['table','form','element'], function(){
        var table = layui.table;
        var form = layui.form;
        var element = layui.element;
        var error_info = "{{.flash.error}}";
        if(error_info){
            layer.msg(error_info,{icon: 2,shade:0.3},function () {
                window.history.go(-1)
            })
            return;
        }
        //方法级渲染
        table.render({
            elem: '#table_list'
            ,url: '/ban/table'
            ,size: 'sm' //小尺寸的表格
            ,cols: [[
                // {checkbox: true, fixed: true},
                {field:'id', title: 'ID', align:'center',sort: true, width:150}
                ,{field:'code',title: '禁用命令'}
                ,{field:'create_time', title: '创建时间'}
                ,{fixed: 'right', width:160, align:'center', toolbar: '#bar'}
            ]]
            ,id: 'listReload'
            ,page: true
            ,height: "full-130"
        });

        var $ = layui.$, active = {
            reload: function(){
                table.reload('listReload', {
                    where: {
                        code: $('#code').val(),
                    },
                    page: 1
                });
            }
        };


        $("#tabAdd").on("click",function() {
            layer.open({
                type: 2,
                shade: 0.3,
                id:1,
                title:"新增禁用命令",
                content: '/ban/add',
                area:['500px','250px'],
                cancel:function(index){
                    window.location.reload();
                    layer.close(index);
                }
            });
        })

        //监听工具条
        table.on('tool(table_filter)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    shade: 0.3,
                    id:1,
                    title:"编辑禁用命令",
                    content: '/ban/edit?id='+data.id,
                    area:['500px','250px'],
                    cancel:function(index){
                        window.location.reload();
                        layer.close(index);
                    }
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除【'+data.code+'】命令么', function(index){
                    var jsData = {'id':data.id,'status':status}
                    $.post('{{urlfor "BanController.AjaxDel"}}', jsData, function (out) {
                        if (out.status == 0) {
                            layer.alert(out.message, {icon: 1},function(index){
                                layer.close(index);
                                window.location.reload();
                            });
                        } else {
                            layer.msg(out.message)
                        }
                    }, "json");
                    // obj.del();
                    layer.close(index);
                })

            }else{
                layer.msg('操作不存在');
            }
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

</script>