{include file="public/head"}
<div class="layui-fluid layui-rg-bg">
    <div class="layui-card">
        <div class="layui-card-header">
            <div class="layui-inline">
                <div class="layui-input-inline"><button class="layui-btn layui-btn-primary layui-btn-sm layui-btn-disabled countnum"></button></div>
            </div>
            <div class="layui-inline" style="float:right;">
                <div class="layui-input-inline"><a class="layui-btn layui-btn-primary layui-btn-sm refresh"><i class="layui-icon layui-icon-refresh-3"></i></a></div>
                <div class="layui-input-inline"><a class="layui-btn layui-btn-sm" onclick="openlayer('{:url("groupadd")}','{:lang("add")}','s')">{:lang("add")}</a></div>
            </div>
        </div>
        <div class="layui-card-body"><table id="data_table" class="layui-table" lay-filter="data_table"></table>{:pagedebug()}</div>
    </div>
</div>
{include file="public/foot"}
<script type="text/html" id="action">
    {{# if(d.id > 1){ }}
    <div class="layui-input-inline"><a class="layui-btn layui-btn-xs" lay-event="edit"><i class='layui-icon layui-icon-edit'></i>{:lang("edit")}</a></div>
    {{# if(d.admin_count > 0){ }}
    <div class="layui-input-inline"><a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled"><i class='layui-icon layui-icon-delete'></i>{:lang("del")}</a></div>
    {{# } else { }}
    <div class="layui-input-inline"><a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class='layui-icon layui-icon-delete'></i>{:lang("del")}</a></div>
    {{# } }}
    {{# } }}
</script>
<script type="text/html" id="status">
    {{# if(d.id > 1){ }}
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
    {{# } else { }}
    <font color='#FF5722'>-</font>
    {{# } }}
</script>
<script type="text/javascript">
    layui.use(['table', 'form', 'element'], function () {
        var table = layui.table, form = layui.form, $ = layui.jquery;
        loading = layer.load(1, {shade: [0.1, '#fff']});
        table.render({
            elem: '#data_table',
            url: '{:url("grouplist")}',
            method: 'POST',
            cols: [[
            {type:'numbers'}
            ,{field:'title', title:'角色'}
            ,{field:'admin_count',align: 'center', title:'成员数'}
            ,{field:'create_time', width: 165, title:'创建时间'}
            ,{field:'update_time', width: 165, title:'修改时间'}
            ,{field: 'status',width: 80, align: 'center', title: '{:lang("state")}', templet: '#status'}
            ,{toolbar: '#action', width: 140, align: 'center', title: '{:lang("act")}', fixed: 'right'}
            ]],
            limit: {:config('app.admin.pagelimit')},
            page: true,
            done: function (res) {
                $('.countnum').text('记录数：' + res.count + '条');
                layer.close(loading);
            }
        });
        //点击事件
        table.on('tool(data_table)', function(obj) {
            var data = obj.data;
            var event = obj.event;
            if(event === 'del'){
                layer.confirm('确认{:lang("del")}('+ data.title +')吗？',{title:'{:lang("del")}'},function(){
                    table_ajax(data,'{:url("groupdel")}',10);
                })
                return false;
            }else if(event === 'edit'){
                var url = "{:url('groupedit')}?id="+data.id;
                openlayer(url,'{:lang("edit")}','s');
            }
        });
        //监听开关操作
        form.on('switch(status)', function(obj){
            var data = {};
            data[obj.elem.name] = obj.elem.checked ? 1 : 0;
            data['id'] = obj.value;
            data['list_switch'] = true;
            table_ajax(data,'{:url("groupedit")}',11);
        });
    })
</script>