<!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="s_deviceid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">消息类型</label>
                            <div class="layui-input-inline">
                                <select name="n_msgtype" id="msg_type" lay-search="">
                                    <option value="">全部</option>
                                    <option th:each="item : ${type_map}" th:text="${item.value}" th:value="${item.key}"></option>
                                </select>
                            </div>
                        </div><div class="layui-inline">
                            <label class="layui-form-label">范围</label>
                            <div class="layui-input-inline">
                                <input type="text" name="dgt_createtime" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
                            </div>
                            <div class="layui-input-inline">
                                <input type="text" name="dlt_createtime" 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: '/gnss/msg/list_all',
            toolbar: '#toolbarDemo',//开启头部工具栏
            defaultToolbar: ['filter'],
            cols: [[
                {field: 'deviceid', title: '设备号'},
                {field: 'createtime', title: '上报时间', templet: "<div>{{layui.util.toDateString(d.createtime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'msgtype', title: '消息类型', templet: "<div>{{d.msgtype.toString(16)}}</div>"},
                {field: 'msglen', title: '消息长度'},
                {field: 'tx', title: '收发', templet: "<div>{{d.tx==1?'发':'收'}}</div>"},
                {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 = "/gnss/msg/export?" + result;
            window.open(u, "_blank");
            return false;
        });

    });
</script>

</body>
</html>