<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <%@include file="../../../../../frame/assets/header-all.jsp"%> 
    <link rel="stylesheet" type="text/css" href="../../../../resource/css/map.frame.css">
</head>
<body>
<body class="easyui-layout" >
    <div data-options="region:'north'" id='north' style="height: 112px;border: none">
        <div class="left-box fl">     
            <div>
                <span class="text-content">开始时间：</span>
                <input class="easyui-datetimebox" id="LIKEzpsj1" >
            </div>     
            <div>
                <span class="text-content">结束时间：</span>
                <input class="easyui-datetimebox" id="LIKEzpsj2" >
            </div>
            <div>
                <span class="text-content">号牌号码：</span>
                <input class="easyui-textbox" id="LIKEhphm" >
            </div> 
            <div>
            	<span class="text-content"></span>
                <a onclick = 'clickCheTravel();' class = 'ahref'>过车轨迹</a>
            </div> 
        </div>
        <div class="right-box fl" style="line-height:112px;">                
            <button id="search" onclick="doSearch();">查询</button>
        </div>
    </div>
    <div data-options="region:'center',split:false" class="easyui-layout"  style="border: none">
        <table id="chetravel-tab-grid"></table>
     </div>   
	<div id="chetravel-contextMenu" class="easyui-menu" style="width:100px;display: none">   
	      <div iconCls="icon-shouc" onclick="getdata();">加入所选</div>
	</div>
<script type="text/javascript">
var datagrid = null;
$(function(){
    $.fn.pagination.defaults.beforePageText = '';
    $.fn.pagination.defaults.afterPageText = '';
    $.fn.pagination.defaults.showPageList= false;
    $.fn.pagination.defaults.showRefresh= false;
    initDefault();
    textboxEnter();
    $('#LIKEhphm').history({
		containerId:'LIKEhphm',
		triggerId:'search',
		storeKey:'hphm'
	});
})
//表格
function initGrid(){    
	datagrid = $('#chetravel-tab-grid').datagrid({
        url : 'clxsjlAction!listClxsjlByPage.do',
        queryParams : getQueryParams(),
        onDblClickRow : function (index, records) { 
			cheTravelQuery(records.hphm); 
		},
        rownumbers:true,
        columns : [[
            {field:'channelId',title:'操作',hidden:false,width:80,
            	formatter:function showClick(value, record, num) {
            		return "<a  href='javascript:void(0);' class='ahref' onclick='opendialog("+num+")'>详情</a>&nbsp;&nbsp; <a  href='javascript:void(0);' class='ahref' onclick='locate("+num+")'>定位</a>";
            	}	
            },
            {field:'hphm',title:'号牌号码',align:'center',width:80 },
            {field:'zpsj',title:'过车时间',align:'center',width:150}
        ]],
        onRowContextMenu: function (e, rowIndex, rowData) {  
        	$('#chetravel-tab-grid').datagrid('selectRow', rowIndex);
        	$('#chetravel-contextMenu').menu('show', { 
        		left: e.pageX, 
        		top: e.pageY 
        	}); 
        	e.preventDefault();
        }
    });
}
//加入所选
function getdata(){
	var records = $("#chetravel-tab-grid").datagrid("getSelected");
	var title=parent.$('#main-tab').tabs('getSelected').panel('options').title;
	parent.MapMain.setSelectedFrameGridData(records,title);
}
//默认
function initDefault(){
    var datenow = new Date();
    $("#LIKEzpsj1").datetimebox("setValue",datenow.format("yyyy-MM-dd")+" 00:00:00");
    $("#LIKEzpsj2").datetimebox("setValue",datenow.format("yyyy-MM-dd")+" 23:59:59");
    initGrid();
}
//查询
function doSearch(){    
    $('#chetravel-tab-grid').datagrid('load', getQueryParams());     
}
//查询条件
function getQueryParams(){
    var sParam = {};
    var LIKEzpsj1 = $("#LIKEzpsj1").datetimebox("getValue");//开始时间
    var LIKEzpsj2 = $("#LIKEzpsj2").datetimebox("getValue");//结束时间
    sParam.LIKEhphm = $('#LIKEhphm').textbox('getText');//号牌号码
    var tableparam = "";
    if(!!LIKEzpsj1){
        tableparam += " AND zpsj > '" +LIKEzpsj1 + "'";
    }else{
        $.dlg.alertWarning("请输入开始时间！");
        return ; 
    }
    if(!!LIKEzpsj2){
        tableparam += " AND zpsj < '" +LIKEzpsj2 + "'";
    }else{
        $.dlg.alertWarning("请输入结束时间！");
        return ; 
    }
    if(sParam.LIKEhphm && sParam.LIKEhphm.length<7 && sParam.LIKEhphm.lastIndexOf("*")==-1 ){
        sParam.LIKEhphm =sParam.LIKEhphm+"*";
        var pchar = sParam.LIKEhphm.charAt(0);
        if(!$.checkChinese(pchar)){
            sParam.LIKEhphm ="*"+sParam.LIKEhphm;
            $('#LIKEhphm').textbox('setValue',sParam.LIKEhphm.toUpperCase());
        }else{
            $('#LIKEhphm').textbox('setValue',sParam.LIKEhphm.toUpperCase());
        }
    }
    sParam.tableparam = tableparam;
    sParam.order = "order by zpsj desc ";
    return sParam;
}
//textbox回车查询
function textboxEnter(){
	$('#LIKEhphm').textbox('textbox').keydown(function (e) {
        if (e.keyCode == 13) {
        	$("#search").click();
        }
    });  
}

//上一条
function showPrev(){
	var idx = datagrid.datagrid("getRowIndex",datagrid.datagrid("getSelected"));
	if(idx === 0 ){
		top.$.dlg.alertInfo('已经是第一条记录!');
		return ;
	}
	datagrid.datagrid("selectRow",--idx);
	var frame 	= top.$("#"+windowid).children("iframe")[0];
	var win		=	frame.contentWindow||frame.window;
	win.$("#tabs").tabs("select", 0);
	win.flag=false;
	setTimeout(function(){
		win.setRecord(datagrid.datagrid("getSelected"));
		win.$(".fimglist .pic").load(function(){win.setMargin();});
		win.$(".ftoollist .pic").load(function(){win.setSmallMargin();});},100);
}

//下一条
function showNext(){
	var idx = datagrid.datagrid("getRowIndex" , datagrid.datagrid("getSelected"));
	var total = datagrid.datagrid("getRows").length;
	if(total && idx === total - 1){
		top.$.dlg.alertInfo('已经是最后一条记录!');
		return ;
	}
	datagrid.datagrid("selectRow",++idx);
	var frame 	= top.$("#"+windowid).children("iframe")[0];
	var win		=	frame.contentWindow||frame.window;
	win.$("#tabs").tabs("select", 0);
	win.flag=false;
	setTimeout(function(){
		win.setRecord(datagrid.datagrid("getSelected"));
		win.$(".fimglist .pic").load(function(){win.setMargin();});
		win.$(".ftoollist .pic").load(function(){win.setSmallMargin();});},100);
}

//详情操作
function opendialog(index){
	actionMethod = 'update';
	var h = 500,w = 934;
	var records = datagrid.datagrid('getData').rows[index];
	datagrid.datagrid('selectRow',index);
	windowid = top.$.createWin({
		 title	: 	'过车详情',
		 width	:   w,
		 height	: 	h,
		 //onClose:   onclose,
		 buttons:[{
				text:"上一条",
				handler:showPrev
			},{
				text:"下一条",
				handler:showNext
			}],
		 data	:  records,
		 url	:  top.sysUrl+"/vp/globalPage/cheRecordDetail.jsp"
	 });
}


//过车轨迹点击
function clickCheTravel () {
	var plateNo = $('#LIKEplateNo').textbox('getText');
	if (!plateNo) {
		top.$.dlg.alertInfo('请输入车辆号码！');
		return;
	} else if (plateNo && plateNo.length < 7) {
		top.$.dlg.alertInfo('请输入完整的车辆号码！');
		return;
	}
	cheTravelQuery(hphm);
}

//车辆轨迹查询、打点
function cheTravelQuery (hphm) {
	if (!hphm) {
		return;
	}
	var records;
	var model = {};
	var LIKEzpsj1 = $("#LIKEzpsj1").datetimebox("getValue");//开始时间
  	var LIKEzpsj2 = $("#LIKEzpsj2").datetimebox("getValue");//结束时间
  	var tableparam = "";
  	if(!!LIKEzpsj1){
    	tableparam += " AND zpsj > '" +LIKEzpsj1 + "'";
  	}else{
	    $.dlg.alertWarning("请输入开始时间！");
	    return ; 
  	}
  	if(!!LIKEzpsj2){
      	tableparam += " AND zpsj < '" +LIKEzpsj2 + "'";
  	}else{
	    $.dlg.alertWarning("请输入结束时间！");
	    return ; 
 	}
	model.hphm = hphm;
	model.page = 1;
	model.rows = 200;
	model.tableparam = tableparam;
	model.order = "order by zpsj asc";
	records = queryCheTravel(model);
	console.log(records);
	if (!records || records.length == 0) {
		$.showMsg('暂无轨迹！');
		return;
	}
	parent.CarTrace.clearGpsCarAllTrace();
	parent.CheTravel.stopCarTraceReplay();
	parent.CheTravel.clearPreCarHisTrace();
	parent.CheTravel.cheTravelTrace(records);
	var data = [];
	for (var i = 0; i < records.length; i++) {
		data[i] = records[i];		
	}
	if (data.length > 2) {
		data.splice(0,1);
		data.splice(data.length - 1,1);
		parent.CheTravel.addOverlay(data);
	}
}

function queryCheTravel (model) {
	var records;
	$.ajax({
		type:'post',
		dataType : 'json',
		async:false,//异步还是同步
		data : model,
		url:'clxsjlAction!listClxsjlByPage.do',
		success:function(data){
			console.log(data);
			if(data&&data.rows.length>0){
				records = data.rows;
			}
		}
	});	
	return records;
}

//定位
function locate (index) {
	var records = datagrid.datagrid('getRows')[index];
	var cheTravelLayer = parent.MapMain.getLayer(parent.MapConst.LAYER_CHETRAVEL);
	cheTravelLayer.locateMarker(records);
}
</script>
</body>
</html> 
