<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>操作日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="searchFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sl_user_name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">内容</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sl_content" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">范围</label>
                            <div class="layui-input-inline">
                                <input type="text" name="dgt_op_time" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="dlt_op_time" autocomplete="off" id="ID-laydate-end-date" class="layui-input" placeholder="结束日期">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-export-btn"><i class="layui-icon">&#xe67d;</i>导出</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.$;
        var form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
		/**
		 * 初始化表单，要加上，不然刷新部分组件可能会不加载
		 */
		form.render();

        laydate.render({
            elem: '#ID-laydate-start-date',
            type: 'datetime'
        });
        laydate.render({
            elem: '#ID-laydate-end-date',
            type: 'datetime'
        });

        table.render({
            elem: '#currentTableId',
            url: '/sys/list_oplog',
            toolbar: '#toolbarDemo',//开启头部工具栏
            defaultToolbar: ['filter'],
            cols: [[
                {field: 'user_name', title: '用户名'},
                {field: 'op_time', title: '操作时间', templet: "<div>{{layui.util.toDateString(d.op_time, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'op_type', title: '操作类型', templet: '#opTypeTrans'},
                {field: 'op_object', title: '操作对象', templet: '#objTypeTrans'},
                {field: 'content', title: '内容', width: '50%'}
            ]],
            limits: [10, 20, 50, 100, 150],
            limit: 10,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        // 监听导出操作
        form.on('submit(data-export-btn)', function (data) {
            var result =  $('#searchFrm').serialize();
            var u = "/sys/oplog/export?" + result;
            window.open(u, "_blank");
            return false;
        });

    });
</script>

<script type="text/html" id="opTypeTrans">
    {{#  if(d.op_type == 1){ }}
    <span>增加</span>
    {{# } else if(d.op_type == 2){ }}
    <span>修改</span>
    {{# } else if(d.op_type == 3){ }}
    <span>删除</span>
    {{# } else if(d.op_type == 4){ }}
    <span>发指令</span>
    {{# } else if(d.op_type == 5){ }}
    <span>登录</span>
    {{# } else if(d.op_type == 6){ }}
    <span>退出</span>
    {{# } else { }}
    <span>其他</span>
    {{#  } }}
</script>

<script type="text/html" id="objTypeTrans">
    {{#  if(d.op_object == 1){ }}
    <span>登录</span>
    {{# } else if(d.op_object == 2){ }}
    <span>退出</span>
    {{# } else if(d.op_object == 3){ }}
    <span>用户</span>
    {{# } else if(d.op_object == 4){ }}
    <span>组织</span>
    {{# } else if(d.op_object == 5){ }}
    <span>设备</span>
    {{# } else if(d.op_object == 6){ }}
    <span>参数组</span>
    {{# } else if(d.op_object == 7){ }}
    <span>告警</span>
    {{# } else { }}
    <span>其他</span>
    {{#  } }}
</script>

</body>
</html>