<%@ 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() {
		datagrid = $('#datagrid').datagrid({
			url : 'readinfo!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',
            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 edit() {
		var rows = datagrid.datagrid('getSelections');
		if (rows.length == 1) {
			var p = parent.dj
					.dialog({
						title : '修改历史记录',
						href : '${pageContext.request.contextPath}/readinfo!readinfoEdit.do?id='
								+ rows[0].id,
						width : 500,
						height : 450,
						buttons : [ {
							text : '修改',
							handler : function() {
								var f = p.find('form');
								f
										.form({
											url : '${pageContext.request.contextPath}/readinfo!edit.do',
											success : function(d) {
												var json = $.parseJSON(d);
												if (json.success) {
													datagrid.datagrid('reload');
													p.dialog('close');
												}
												parent.dj.messagerShow({
													msg : json.msg,
													title : '提示'
												});
											}
										});
								f.submit();
							}
						} ],
						onLoad : function() {
							var f = p.find('form');
							f.find('input[name=id]').val(rows[0].id);
							f.find('input[name=cardcode]')
									.val(rows[0].cardcode);
							f.find('input[name=senid]').val(rows[0].senid);
							f.find('input[name=type]').val(rows[0].type);
							f.find('input[name=dl]').val(rows[0].dl);
							f.find('input[name=rssi]').val(rows[0].rssi);
							f.find('input[name=state]').val(rows[0].state);
							f.find('textarea[name=readtime]').val(
									rows[0].readtime);

						}
					});
		} else if (rows.length > 1) {
			parent.dj.messagerAlert('提示', '同一时间只能编辑一条记录！', 'error');
		} else {
			parent.dj.messagerAlert('提示', '请选择要编辑的记录！', 'error');
		}
	}
	function append() {
		var p = parent.dj
				.dialog({
					title : '增加基站',
					href : '${pageContext.request.contextPath}/readinfo!readinfoAdd.do',
					width : 500,
					height : 250,
					buttons : [ {
						text : '增加',
						handler : function() {
							var f = p.find('form');
							f
									.form({
										url : '${pageContext.request.contextPath}/readinfo!add.do',
										success : function(d) {
											var json = $.parseJSON(d);
											if (json.success) {
												datagrid.datagrid('reload');
												p.dialog('close');
											}
											parent.dj.messagerShow({
												msg : json.msg,
												title : '提示'
											});
										}
									});
							f.submit();
						}
					} ],
					onLoad : function() {
						var f = p.find('form');
						var editor = f
								.find('textarea[name=cdesc]')
								.xheditor(
										{
											tools : 'full',
											html5Upload : true,
											upMultiple : 4,
											upLinkUrl : '${pageContext.request.contextPath}/readinfo!upload.do',
											upLinkExt : 'zip,rar,txt,doc,docx,xls,xlsx',
											upImgUrl : '${pageContext.request.contextPath}/readinfo!upload.do',
											upImgExt : 'jpg,jpeg,gif,png'
										});
					}
				});
	}
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.dj
					.messagerConfirm(
							'请确认',
							'您要删除当前所选项目？',
							function(r) {
								if (r) {
									for ( var i = 0; i < rows.length; i++) {
										ids.push(rows[i].cid);
									}
									$
											.ajax({
												url : '${pageContext.request.contextPath}/readinfo!delete.do',
												data : {
													ids : ids.join(',')
												},
												dataType : 'json',
												success : function(d) {
													datagrid.datagrid('load');
													datagrid
															.datagrid('unselectAll');
													parent.dj.messagerShow({
														title : '提示',
														msg : d.msg
													});
												}
											});
								}
							});
		} else {
			parent.dj.messagerAlert('提示', '请勾选要删除的记录！', 'error');
		}
	}
	function _search() {
		datagrid.datagrid('load', dj.serializeObject($('#searchForm')));
	}
	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><input name="zddz" style="width:160px;" /></td>

					<th>人员编号：</th>
					<td><input name="personcode" style="width:160px;" /></td>
					<th>姓名：</th>
					<td><input name="personname" style="width:160px;" /></td>
				</tr>
				<tr>
					<th>时间起：</th>
					<td><input class="easyui-datetimebox" name="readtimeStart"
						style="width:160px;" />
					<th>止：</th>
					<td><input class="easyui-datetimebox" name="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>
