<!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">
    <style>
        body {
            background-color: #ffffff;
        }
        .layui-btn-normal {
            background-color: #1aa094;
        }
        .icon-btn {
            /* width: 30px; */
            height: 26px;
            padding: 0;
        }
        .layui-table-fixed-l .layui-table-body {
            box-shadow: none !important;
        }
        .layui-btn-normal:hover {
            background-color: #148e83;
        }
        .layui-table-fixed-l .layui-table-body {
            box-shadow: none !important;
        }
        .layui-table-cell {
            height: auto;
            line-height: 28px;
            padding: 6px 15px;
            position: relative;
            box-sizing: border-box;
        }
        .layui-btn-xs {
            padding: 0 8px;
            font-size: 12px;
            height: 26px;
            line-height: 24px;
        }
        .device-id-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: #4b97d5f5;
            color: white;
            border-radius: 5px;
            padding: 3px 10px;
            cursor: pointer;
            transition: background-color 0.3s;
            width: 100%;
        }
        .device-id-btn:hover {
            background-color: #339af0;
        }
        .device-id-btn i {
            margin-right: 5px;
        }
        .icon-only-btn {
            background: none;
            border: none;
            padding: 0;
            cursor: pointer;
            font-size: 16px;
            color: #1aa094;
        }
        .icon-only-btn:hover {
            color: #148e83;
        }
    </style>
</head>
<body>

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

    <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;
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            form.render();

            table.render({
                elem: '#currentTableId',
                url: '/gnss/q_status/list',
                cols: [[
                    {field: 'deviceid', title: '设备号', width: 120, templet: '#deviceIdTpl', align: 'center',sort: true},
                    {field: 'devicetype', title: '设备类型', templet: '#typeTrans', width: 100},
                    {field: 'project_id', title: '项目号', width: 100},
                    {field: 'name', title: '工点', width: 150},
                    {field: 'updatetime', title: '更新时间', templet: "<div>{{layui.util.toDateString(d.updatetime, 'yyyy-MM-dd HH:mm:ss')}}</div>", width: 170},
                    {field: 'state', title: '状态', templet: '#stateTrans', width: 80, align: 'center'},
                    {field: 'warning', title: '告警', templet: '#warningTrans', width: 80, align: 'center'},
                    {field: 'voltage', title: '电压', width: 80},
                    {field: 'temperature', title: '温度', width: 80},
                    {field: 'humidity', title: '湿度', width: 80},
                    {field: 'rssi', title: '信号', width: 80},
                    {field: 'pitch', title: 'x倾角', width: 80},
                    {field: 'roll', title: 'y倾角', width: 80},
                    {field: 'satelliteinuse', title: '使用卫星数', width: 110},
                    {field: 'latitude', title: '纬度', hide: true},
                    {field: 'longitude', title: '经度', hide: true}
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 15,
                page: true,
                skin: 'line',
                even: true,
                loading: true,
                text: {
                    none: '暂无符合条件的设备'
                }
            });

            table.on('tool(currentTableFilter)', function(obj) {
                var data = obj.data;
                if (obj.event === 'locate') {
                    if (data.latitude && data.longitude) {
                        parent.locateDeviceOnMap(data.deviceid, data.latitude, data.longitude);
                    } else {
                        layer.msg('设备无经纬度信息，无法定位');
                    }
                }
            });

        });

    </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>

    <script type="text/html" id="deviceIdTpl">
        <div class="device-id-btn" lay-event="locate">
            <i class="layui-icon layui-icon-location"></i>{{d.deviceid}}
        </div>
    </script>

</body>
</html>