<!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_d.deviceid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" th:if="${tenant_id==0}">
                            <label class="layui-form-label">所属部门</label>
                            <div class="layui-input-inline">
                                <select name="n_d.tenantid" id="n_d.tenantid" lay-search="">
                                    <option value="">全部</option>
                                    <option th:each="item : ${tenant_list}" th:text="${item.name}" th:value="${item.id}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">父设备号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sl_d.parentid" 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_state" lay-search="">
                                    <option value="">全部</option>
                                    <option value="1">工作</option>
                                    <option value="2">休眠</option>
                                    <option value="0">掉线</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">告警级别</label>
                            <div class="layui-input-inline">
                                <select name="n_warning" lay-search="">
                                    <option value="">全部</option>
                                    <option value="0">正常</option>
                                    <option value="1">一般</option>
                                    <option value="2">严重</option>
                                </select>
                            </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>

		<script type="text/html" id="currentTableBar">
		    <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="info">详细</a>
		</script>
		
    </div>
</div>

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

        table.render({
            elem: '#currentTableId',
            url: '/gnss/status/list',
            toolbar: '#toolbarDemo',//开启头部工具栏
            defaultToolbar: ['filter'],
            cols: [[
                {field: 'deviceid', title: '设备号', sort: true},
                {field: 'devicetype', title: '设备类型',templet: '#typeTrans'},
                {field: 'updatetime', title: '更新时间', templet: "<div>{{layui.util.toDateString(d.updatetime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'devicetime', title: '设备时间'},
                {field: 'state', title: '状态',templet: '#stateTrans'},
                {field: 'warning', title: '告警',templet: '#warningTrans'},
                {field: 'longitude', title: '经度'},
                {field: 'latitude', title: '维度'},
                {field: 'voltage', title: '电压'},
                {field: 'temperature', title: '温度'},
                {field: 'humidity', title: '湿度'},
                {field: 'rssi', title: '信号'},
                {field: 'satelliteinuse', title: '使用卫星数'},
                {title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            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');
            table.render();

            return false;
        });

        /**
         * toolbar事件监听
         */
        table.on('tool(currentTableFilter)', function (obj) {
            if (obj.event === 'info') {  // 监听添加操作
                $.ajax({
                    type:"POST",
                    url:"/gnss/status/info",
                    data:{
                        'warningCode':obj.data.warningcode
                    },
                    success: function (data) {
                        layer.alert(data);
                    },
                    error: function () {
                        console.log("ajax error");
                    }
                });
            }
        });

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

    });
</script>

<script type="text/html" id="typeTrans">
    {{#  if(d.devicetype == 1){ }}
    <span>基准站</span>
    {{# } else { }}
    <span>监测站</span>
    {{#  } }}
</script>

<script type="text/html" id="stateTrans">
    {{#  if(d.state == 0){ }}
    <span class="layui-badge layui-bg-gray">掉线</span>
    {{# } else if(d.state == 1){ }}
    <span class="layui-badge layui-bg-green">工作</span>
    {{# } else if(d.state == 3){ }}
    <span class="layui-badge layui-bg-orange">补传</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-blue">休眠</span>
    {{#  } }}
</script>

<script type="text/html" id="warningTrans">
    {{#  if(d.warning == 2 || d.state == 0){ }}
    <span class="layui-badge">严重</span>
    {{# } else if(d.warning == 0){ }}
    <span class="layui-badge layui-bg-green">正常</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-orange">一般</span>
    {{# } }}
</script>

</body>
</html>