<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../../inc.jsp"></jsp:include>
<script type="text/javascript" charset="utf-8">
	var datagrid;
	$(function() {
		$.ajax({
			url: "personinfo!findAllPerson.do",
			type: "post",
			method: "json",
			success: function(val){
				$.each(JSON.parse(val), function(index, v){
					$("#positionPathName").append("<option value='"+v.cardcode+"'>"+v.personname+"</option>")
				})
			}
		})

		datagrid = $('#datagrid').datagrid({
			//url : 'positionpath!datagrid.do',
			iconCls : 'icon-save',
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 20,
			pageList : [ 20, 40, 60, 80, 100, 120, 140, 160, 200 ],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : false,
			idField : 'id',
			sortName : 'id',
			sortOrder : 'desc',
			/*frozenColumns : [ [ {
				title : '序号',
				field : 'id',
				width : 150,
				sortable : true,
				checkbox : true
			} ] ],*/
			columns : [ [  {
				title : '编号',
				field : 'personcode',
				width : 70
			}, {
				title : '姓名',
				field : 'personname',
				width : 150
			}, {
					title : '中段',
					field : 'layer',
					width : 150,
					formatter : function(value, row, index) {
						if (value == "0") {
							return "平硐";

						} else {
							return value;
						}
					}
			},{
				title : '人员卡号',
				field : 'zddz',
				width : 150
			}, {
				title : '基站',
				field : 'senid',
				width : 150
			}, {
				title : '进入时间',
				field : 'readtime',
				width : 150
			}, {
				title : '离开时间',
				field : 'outtime',
				width : 150
			}  ] ],
			/*toolbar : [ {
				text : '导出',
				iconCls : 'icon-edit',
				handler : function() {
					exportd();
				}
			}, '-', {
				text : '取消选中',
				iconCls : 'icon-undo',
				handler : function() {
					datagrid.datagrid('unselectAll');
				}
			}, '-' ],*/
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});
	});
	function _search() {
		// datagrid.datagrid('load', dj.serializeObject($('#searchForm')));
		var start = $('#readtimeStart').datetimebox('getValue');
		var end = $('#readtimeEnd').datetimebox('getValue');
		compareTime(start, end)
	}


	//判断日期，时间大小
	function compareTime(startDate, endDate) {
		if (startDate.length > 0 && endDate.length > 0) {
			var startDateTemp = startDate.split(" ");
			var endDateTemp = endDate.split(" ");

			var arrStartDate = startDateTemp[0].split("-");
			var arrEndDate = endDateTemp[0].split("-");

			var arrStartTime = startDateTemp[1].split(":");
			var arrEndTime = endDateTemp[1].split(":");

			var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
			var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);

			if (allStartDate.getTime() >= allEndDate.getTime()) {
				alert("开始时间不能大于结束时间，不能通过");
				return false;
			} else {
				var name = $('#positionPathName option:selected').val()
				console.log(name)
				$.ajax({
					url : 'positionpath!datagrid.do',
					type: "post",
					data: {
						name : name,
						startDate : startDate,
						endDate : endDate
					},
					success: function(val) {
						var jsonModle = JSON.parse(val).total;
						if (JSON.stringify(jsonModle) > 0) {
							$.each(JSON.parse(val), function(index, v){

								// datagrid.datagrid("loadData", v);
								console.log(v)
								$('#datagrid').datagrid("loadData", v);
							})
						}else {
							alert("没有数据")
						}
					}
				})
				return true;
			}
		} else {
			alert("时间不能为空");
			return false;
		}
	}

	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}

	function exportd() {
		Export('人员定位历史记录', $('#datagrid'))
	}

</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false,title:'过滤条件'"
		style="height: 110px;overflow: hidden;" align="left">
		<form id="searchForm">
			<table class="tableForm datagrid-toolbar"
				style="width: 100%;height: 100%;">
				<tr>
					<th>姓名：</th>
					<td><select id="positionPathName"> </select></td>
				</tr>
				<tr>
					<th>时间起：</th>
					<td><input class="easyui-datetimebox" id="readtimeStart"
						style="width:160px;" />
					<th>止：</th>
					<td><input class="easyui-datetimebox" id="readtimeEnd"
						style="width:160px;" /></td>
					<th></th>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						onclick="_search();">过滤</a><a href="javascript:void(0);"
						class="easyui-linkbutton" onclick="cleanSearch();">取消</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',border:false"
		style="overflow: hidden;">
		<table id="datagrid"></table>
	</div>

	<div id="menu" class="easyui-menu" style="width:120px;display: none;">
		<!--  <div onclick="edit();" data-options="iconCls:'icon-edit'">编辑</div>-->
		<div onclick="exportd();" data-options="iconCls:'icon-edit'">导出</div>
	</div>
</body>
</html>
