<!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">
		<div class="layui-card top-panel">
			<div class="layui-card-header">基本参数</div>
			<div class="layui-card-body">
				<table class="layui-hide" id="baseParaTableId" lay-filter="baseParaTableFilter"></table>
			</div>
		</div>
		
		<div class="layui-card top-panel">
			<div class="layui-card-header">解算参数</div>
			<div class="layui-card-body">
				<table class="layui-hide" id="calcParaTableId" lay-filter="calcParaTableFilter"></table>
			</div>
		</div>

	</div>
	
	<script type="text/html" id="currentTableBar">
	    <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
	    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
	</script>
	
	<script type="text/html" id="toolbarTable">
	    <div class="layui-btn-container" th:if="${role=='SUPER_ADMIN' || role=='ADMIN'}">
	        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
	    </div>
	</script>

</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="javascript">
    layui.use(['form', 'table'], function () {
        var $ = layui.$,
            form = layui.form,
            table = layui.table;

		var cfg_cols = [
			{field: 'id', title: '组号', sort: true},
			{field: 'work_cycle', title: '工作周期(分钟)'},
			{field: 'active_time', title: '激活时长(分钟)'},
			{field: 'active_offset', title: '偏置(分钟)'},
			{field: 'rs_adv', title: '基准站提前时间（分钟）'},
			{field: 'power_mode', title: '功耗模式',templet: "<div>{{d.power_mode==0?'低功耗':'普通'}}</div>"},
			{field: 'device_num', title: '关联设备数'},
			{title: '操作', toolbar: '#currentTableBar', align: "center"}
		];
		if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN") {
			cfg_cols[3].hide = true;
			cfg_cols[4].hide = true;
			cfg_cols[7].hide = true;
		}


		/**
		**   基本参数组
		 **/
        table.render({
            elem: '#baseParaTableId',
            url: '/gnss/group/list',
            toolbar: '#toolbarTable',
			defaultToolbar: [],
			cols: [
					cfg_cols
			],
            limit: 10,
            page: true,
            skin: 'line'
        });

		table.on('toolbar(baseParaTableFilter)', function (obj) {
			if (obj.event === 'add') {
				var index = layer.open({
					title: '新增分组',
					type: 2,
					shade: 0.2,
					maxmin:true,
					shadeClose: true,
					area: ['100%', '100%'],
					content: '../page/table/gnss_add_group'
				});
				$(window).on("resize", function () {
					layer.full(index);
				});
			}
		});

		table.on('tool(baseParaTableFilter)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				var index = layer.open({
					title: '修改分组',
					type: 2,
					shade: 0.2,
					maxmin:true,
					shadeClose: true,
					area: ['100%', '100%'],
					content: '../page/table/gnss_add_group',
					success: function(layero, index) {
						var iframe = window['layui-layer-iframe' + index];
						iframe.setParams(data);
					}
				});
				$(window).on("resize", function () {
					layer.full(index);
				});
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('确定删除参数组'+data.id+"?", function(index){
					$.ajax({
						type:"POST",
						url:"/gnss/group/delete",
						data:{
							'del_id':data.id
						},
						success: function (data) {
							//data是cotroller相应处理函数的返回值
							table.reload('baseParaTableId');
						},
						error: function () {
							console.log("ajax error");
						}
					});
					layer.close(index);
				});
			}
		});

		/**
		 **   解算参数组
		 **/
		var cfg2_cols = [
			{field: 'id', title: '组号', sort: true},
			{field: 'ver', title: '算法版本'},
			{field: 'filter_hour', title: '滤波周期(小时)'},
			{field: 'xy_threshold', title: '水平异常门限(mm)'},
			{field: 'z_threshold', title: '垂直异常门限(mm)'},
			{field: 'adv_filter', title: '增强异常过滤', templet: "<div>{{d.adv_filter==1?'启用':'禁用'}}</div>"},
			{field: 'auto_filter', title: '自适应滤波', templet: "<div>{{d.auto_filter==1?'启用':'禁用'}}</div>"},
			{field: 'filter_min_hour', title: '最小滤波周期'},
			{field: 'auto_threshold', title: '触发门限(mm)'},
			{field: 'auto_upload', title: '自动补传', templet: "<div>{{d.auto_upload==1?'启用':'禁用'}}</div>"},
			{field: 'device_num', title: '关联设备数'},
			{title: '操作', toolbar: '#currentTableBar', align: "center"}
		];
		if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN") {
			cfg2_cols[9].hide = true;
		}
		table.render({
		    elem: '#calcParaTableId',
		    url: '/gnss/group/list_calc',//假数据
			toolbar: '#toolbarTable',
			defaultToolbar: [],
			cols: [
				cfg2_cols
			],
		    limit: 10,
		    page: true,
		    skin: 'line'
		});

		table.on('toolbar(calcParaTableFilter)', function (obj) {
			if (obj.event === 'add') {
				var index = layer.open({
					title: '新增解算参数组',
					type: 2,
					shade: 0.2,
					maxmin:true,
					shadeClose: true,
					area: ['100%', '100%'],
					content: '../page/table/gnss_add_group_calc'
				});
				$(window).on("resize", function () {
					layer.full(index);
				});

			}
		});

		table.on('tool(calcParaTableFilter)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				var index = layer.open({
					title: '修改分组',
					type: 2,
					shade: 0.2,
					maxmin:true,
					shadeClose: true,
					area: ['100%', '100%'],
					content: '../page/table/gnss_add_group_calc',
					success: function(layero, index) {
						var iframe = window['layui-layer-iframe' + index];
						iframe.setParams(data);
					}
				});
				$(window).on("resize", function () {
					layer.full(index);
				});
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('确定删除参数组'+data.id+"?", function(index){
					$.ajax({
						type:"POST",
						url:"/gnss/group/delete_calc",
						data:{
							'del_id':data.id
						},
						success: function (data) {
							//data是cotroller相应处理函数的返回值
							table.reload('calcParaTableId');
						},
						error: function () {
							console.log("ajax error");
						}
					});
					layer.close(index);
				});
			}
		});
    });

	function onBaseParaUpdated(){
		layui.table.reload('baseParaTableId');
	}
	function onCalcParaUpdated(){
		layui.table.reload('calcParaTableId');
	}
</script>


</body>
</html>