{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("add")}','{:lang("add")}','xs')">{: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">
    <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.user_count > 0){ }}
    <div class="layui-input-inline"><a class="layui-btn layui-btn-disabled layui-btn-xs layui-btn-danger"><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">
    <input type="checkbox" name="status" lay-skin="switch" value="{{d.id}}" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</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("index")}',
            method: 'POST',
            cols: [[
            {type:'numbers'},
            {field:'title', title:'组名称', edit:'text'},
            {field:'user_count', title:'会员数'},
            {field:'point', title:'组值', edit:'text'},
            {field:'status',align: 'center', title: '状态',width:80, templet: '#status'},
            {toolbar: '#action', width: 150, 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('rowDouble(data_table)', function(obj){
            var url = "{:url('edit')}?id="+obj.data.id;
            openlayer(url,'{:lang("edit")}','xs');
        });
        //点击事件
        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("del")}',10);
                })
                return false;
            }else if(event === 'edit'){
                var url = "{:url('edit')}?id="+data.id;
                openlayer(url,'{:lang("edit")}','xs');
            }
        });
        //监听开关操作
        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("edit")}',11);
        });
        //监听单元格编辑
        table.on('edit(data_table)', function(obj){
            var value = obj.value //得到修改后的值
            ,data = obj.data //得到所在行所有键值
            ,field = obj.field; //得到字段
            table_ajax(data,'{:url("edit")}',11);
        });
    })
</script>