<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../../common.jsp"/>

    <style>
        .layui-table th {
            text-align: center;
        }
    </style>
</head>
<body>
<div class="row animated fadeInRight" style="margin: 0;">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head clearfix lgraybg pt5 pb10 pl10 bdbd">
                    <!-- 顶部按钮 -->
                    <div class="fl">
                        查询条件
                    </div>
                    <div class="tools fr">
                        <a href="javascript:void(0);" class="collapse dblock f14 dgray mr5">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>

            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" action="" style="margin-top: 10px" lay-filter="formCondition">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">名称：</label>
                            <div class="layui-input-inline">
                                <input type="text" id="name" name="name" placeholder="请输入名称" class="layui-input">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <table class="layui-hide" id="roleInfoTab" lay-filter="roleInfoTab"></table>
</div>
</body>
<script id="toolbar" type="text/html">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="search">
            <i class="layui-icon  layui-icon-search"></i>查询
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="add">
            <i class="layui-icon layui-icon-add-circle-fine"></i>添加
        </a>
    </div>
</script>

<script id="lineBar" type="text/html">
    <a class="layui-btn layui-btn-xs" lay-event="edit">
        <i class="layui-icon layui-icon-edit"></i>编辑
    </a>
    <a class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="config">
        <i class="layui-icon layui-icon-edit"></i>配置菜单
    </a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
        <i class="layui-icon layui-icon-delete"></i>删除</a>

</script>

<script>
    let table;
    let layer;

    layui.use(["table", "layer"], function () {
        table = layui.table;
        layer = layui.layer;

        table.render({
            elem: "#roleInfoTab"
            , id: 'tabId'
            , url: ctx + '/roleInfo/page'
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //默数据列表的字段名称，认：data
                , statusCode: 200
            }
            , where: {
                column: 'createTime'
                , asc: false
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
            , title: '通知'
            , cols: [[
                {field: 'numbers', title: '序号', minWidth: 80, type: 'numbers'}
                , {field: 'id', title: 'id', minWidth: 180, align: "center"}
                , {field: 'name', title: '角色名称', minWidth: 200, align: "center"}
                , {field: 'createTime', title: '创建时间', minWidth: 180, align: "center"}
                , {field: 'updateTime', title: '更新时间', minWidth: 180, align: "center"}
                , {fixed: 'right', title: '操作', minWidth: 238, toolbar: '#lineBar', align: "center"}
            ]]
            , page: true
        })

        table.on("toolbar(roleInfoTab)", function (obj) {
            switch (obj.event) {
                case 'add':
                    editOrNew()
                    break;
                case 'search':
                    layer.msg('查询');
                    break;
            }
        });

        table.on('tool(roleInfoTab)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            if (layEvent === 'del') { //查看
                del(data);
            } else if (layEvent === 'config') { //删除
                config(data);
            } else if (layEvent === 'edit') { //编辑
                editOrNew(data)
            }
        });
    })

    function tabReload() {
        table.reload('tabId', {}, true)
    }

    function editOrNew(data) {
        let url = ctx + '/roleInfo/detail';
        if (data != null && data.id != null) {
            url += '?id=' + data.id;
        }
        layer.open({
            type: 2
            , title: '角色信息'
            , content: url
            , area: '400px'
            , success: function (layero, index) {
                layer.iframeAuto(index);
            }
        })
    }

    function del(data) {

    }

    function config(data) {
        let url = ctx + '/roleInfo/configDetail?id=' + data.id;
        layer.open({
            type: 2
            , title: '角色信息'
            , content: url
            , area: ['400px', '600px']
        })
    }
</script>
</html>

