<!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_t.deviceid" id="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_t.tenantid" id="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">
								<input type="text" name="dgt_t.createtime" autocomplete="off" id="ID-laydate-start-date" class="layui-input" placeholder="开始日期">
							</div>
							<div class="layui-input-inline">
								<input type="text" name="dlt_t.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">&#xe615;</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="cmd">命令行</a>
		</script>
		
    </div>
	<div class="layuimini-main">
		<div class="layui-row layui-col-space15">
		    <div id="echarts-gnss" style="background-color:#ffffff;min-height:300px;padding: 10px"></div>
		</div>
	</div>
</div>

<script src="../js/lay-module/echarts/echartsTheme.js" charset="utf-8"></script>
<script src="../js/lay-module/echarts/echarts.js" charset="utf-8"></script>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="javascript">
    layui.use(['form', 'table','laydate','element'], function () {
        var $ = layui.$,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        var searchDeviceId = false;
        var data_cols = [
            {field: 'deviceid', title: '设备号'},
            {field: 'createtime', title: '产生时间', width:'18%', templet: "<div>{{layui.util.toDateString(d.createtime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
            {field: 'updatetime', title: '上报时间', width:'18%', templet: "<div>{{d.updatetime==null?'':layui.util.toDateString(d.updatetime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
            {field: 'b562e', title: '原始东', templet: "<div>{{d.b562e.toFixed(2)}}</div>"},
            {field: 'b562n', title: '原始北', templet: "<div>{{d.b562n.toFixed(2)}}</div>"},
            {field: 'b562d', title: '原始天', templet: "<div>{{d.b562d.toFixed(2)}}</div>"},
            {field: 'rpose', title: '相对东', templet: "<div>{{d.rpose==null?'':d.rpose.toFixed(2)}}</div>"},
            {field: 'rposn', title: '相对北', templet: "<div>{{d.rposn==null?'':d.rposn.toFixed(2)}}</div>"},
            {field: 'rposd', title: '相对天', templet: "<div>{{d.rposd==null?'':d.rposd.toFixed(2)}}</div>"},
            //{field: 'auxe', title: '辅助东', templet: "<div>{{d.auxe==null?'':d.auxe.toFixed(2)}}</div>"},
            //{field: 'auxn', title: '辅助北', templet: "<div>{{d.auxn==null?'':d.auxn.toFixed(2)}}</div>"},
            //{field: 'auxd', title: '辅助天', templet: "<div>{{d.auxd==null?'':d.auxd.toFixed(2)}}</div>"},
            {field: 'enabled', title: '有效',templet: '#enabledTrans'},
            {field: 'pps', title: '平均延迟'}
        ];
        if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN" &&
            !([[${role}]] == "MANAGER" && [[${tenant_id}]] == 0)) {
            data_cols[9].hide = true;
            data_cols[10].hide = true;
            data_cols[11].hide = true;
        }
		/**
		 * 初始化表单，要加上，不然刷新部分组件可能会不加载
		 */
		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/data/list_calc',
            toolbar: '#toolbarDemo', //开启头部工具栏
            defaultToolbar: ['filter'],
            cols: [
                data_cols
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line',
            done: function (result, curr, count) {
                if(searchDeviceId){
                    showChart(result.data);
                }
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            var deviceId = $('#deviceid').val();
            searchDeviceId = !isNaN(parseFloat(deviceId));
            //执行搜索重载
            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/data/calc/export?" + result;
            window.open(u, "_blank");
            return false;
        });

        function showChart(chartData){
            var echartsDevice = echarts.init(document.getElementById('echarts-gnss'), 'walden');
            var t = [];
            var e = [];
            var n = [];
            var d = [];
            var fe = [];
            var fn = [];
            var fd = [];
            var count = 0;
            var isBaseSet = false;
            var baseE = 0;
            var baseN = 0;
            var baseD = 0;
            var baseFE = 0;
            var baseFN = 0;
            var baseFD = 0;

            for(var i=chartData.length-1; i>=0; i--){
                if(chartData[i].rpose!=null) {
                    if(isBaseSet) {
                        t[count] = chartData[i].createtime;
                        e[count] = chartData[i].b562e-baseE;
                        n[count] = chartData[i].b562n-baseN;
                        d[count] = chartData[i].b562d-baseD;
                        fe[count] = Number(chartData[i].rpose) - baseFE;
                        fn[count] = Number(chartData[i].rposn) - baseFN;
                        fd[count] = Number(chartData[i].rposd) - baseFD;
                        count++;
                    }
                    else{
                        isBaseSet = true;
                        baseE = Number(chartData[i].b562e);
                        baseN = Number(chartData[i].b562n);
                        baseD = Number(chartData[i].b562d);
                        baseFE = Number(chartData[i].rpose);
                        baseFN = Number(chartData[i].rposn);
                        baseFD = Number(chartData[i].rposd);
                    }
                }
            }

            var optionDevice = {
                title: {
                    text: '位移曲线'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                legend: {
                    data: ['东', '北', '天','平滑东', '平滑北', '平滑天']
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        boundaryGap: false,
                        data: t
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '东',
                        type: 'line',
                        data: e
                    },
                    {
                        name: '北',
                        type: 'line',
                        data: n
                    },
                    {
                        name: '天',
                        type: 'line',
                        data: d
                    },
                    {
                        name: '平滑东',
                        type: 'line',
                        data: fe
                    },
                    {
                        name: '平滑北',
                        type: 'line',
                        data: fn
                    },
                    {
                        name: '平滑天',
                        type: 'line',
                        data: fd
                    }
                ]
            };
            echartsDevice.setOption(optionDevice);

            // echarts 窗口缩放自适应
            window.onresize = function () {
                echartsDevice.resize();
            }
        }
    });

</script>

<script type="text/html" id="enabledTrans">
    {{#  if(d.enabled == false){ }}
    <span class="layui-badge layui-bg-gray">无效</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-green">有效</span>
    {{#  } }}
</script>

</body>
</html>