<%@ 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"%> 
    <script type='text/javascript' src='../../../main/MapMain.js'></script>
    <script type='text/javascript' src='../../../main/MapToolBar.js'></script>
    <link rel="stylesheet" type="text/css" href="../../../../resource/css/map.frame.css">

</head>
<body  onselectstart="return false">
<body class="easyui-layout" >
    <div data-options="region:'center',split:false" class="easyui-layout"  style="border: none">
        <table id="chegps-tab-grid"></table>
     </div>   
	<div id="chegps-contextMenu" class="easyui-menu" style="width:100px;display: none">   
	      <div iconCls="icon-actMode" onclick="startvideo()">实时视频</div>   
	      <div iconCls="icon-info-look" onclick="openWindow()">查看详情</div>
	      <div iconCls="icon-location" onclick="locate();">地图定位</div>    
	</div>
	<OBJECT ID="ocx" style="LEFT: 0px; TOP: 0px;"  width="0" height="0"
            CLSID="{308F1C9C-98B6-41A7-8320-FA601ABD7341}" TYPE="application/x-itst-activex">  
   	</OBJECT>
<script type="text/javascript">

var maingrid = null;

function getGrid (){
	return maingrid;
}
//加入所选，插入行数据
function addtGridData(record,clear){
	var grid = getGrid();
	var rows = grid.datagrid('getData').rows;
	if(grid){
		if(clear){
			grid.datagrid('loadData',{ total: 0, rows: [] });
		}
		if(rows.length != 0){
			for(var i = 0;i<rows.length;i++){
				if(rows[i] == record){
					$.showMsg("已加入所选！");
					return;
				}
			}
		}
		grid.datagrid('appendRow',record);
	}
	return;
}
$(function(){
   initGrid();
})

function initGrid(){   
	var toolbar = [{
        text:'视频',
        iconCls:'icon-actMode',
        handler:videoSelectAll
    },{
        text:'录像',
        iconCls:'icon-video',
        handler:startrecord
    },{
        text:'删除',
        iconCls:'icon-delete',
        handler:deleteRows
    },{
        text:'清空',
        iconCls:'icon-clear',
        handler:clearGrid
    }];
	maingrid =  $('#chegps-tab-grid').datagrid({
        queryParams:'',
        toolbar:toolbar,
        singleSelect:false,
        columns : [[
            {field: 'A',checkbox:'true',width:30},
            {field:'hphm',title:'号牌号码',hidden:false,width:120},
            {field:'bmmc',title:'所属部门',hidden:false,width:130}
        ]],
        onRowContextMenu: function (e, rowIndex, rowData) {  
        	$('#chegps-tab-grid').datagrid('selectRow', rowIndex);
        	$.data(document.body, "selectData", rowData);
        	$('#chegps-contextMenu').menu('show', { 
        		left: e.pageX, 
        		top: e.pageY 
        	}); 
        	e.preventDefault();
        },
        onDblClickRow: function(index,row){
        	locate(row);
        }
    });
}
//查看详情
function openWindow(){
	var records = $("#chegps-tab-grid").datagrid('getSelected');
 	windowid = top.$.createWin({
		 title	: 	'车辆详情',
		 width  :  600,
		 height :  380,
		 data	:  records,
		 url	:  top.sysUrl+"/szmap/business/base/item/iframe/chegps-tab_show.jsp"
	 });
}
//地图定位
function locate(row){
	if(!row){
		var records = $.data(document.body, "selectData");
	}else{
		var records = row;
	}
	parent.MapAPI.centerAtLatLngZoom(records.jd,records.wd,top.ditu.mapLevel );
	parent.MapMain.getLayer(parent.MapConst.LAYER_CHEGPS).locateMarker(records);
	$.data(document.body, "selectData","");
}
//实时视频
function startvideo(){
	var records = $("#chegps-tab-grid").datagrid('getSelected');
    if(!ocx) {
        $.log("ocx is undefined...");
        return ;
    } 
    var vdId      = records.vdId;
    var channelId = records.channelId;
    try {       
        ocx.iSeeOcxNewWindow(3);
        ocx.iSeeOcxSetPopupWndProperties('',300,200);
        ocx.iSeeOcxSetScreenModeEx(0,1);
        ocx.iSeeOcxMonitorStartEx2(0,0,vdId,channelId,0);
    } catch(e) {
        $.showMsg("视频播放异常！");
    }
}
//录像回查
function startrecord(){
	var datenow = new Date();
	var records = $("#chegps-tab-grid").datagrid("getSelected");
    if(!ocx) {
        $.log("ocx is undefined...");
        return ;
    } 
    var snapTime = datenow.format("yyyy-MM-dd hh:mm:ss");
        snapTime = snapTime.replace(new RegExp("-","gm"),"/");
    var startTime = (new Date(snapTime)).getTime()-(1000*60*60*24*12);
    var endTime = (new Date(snapTime)).getTime();
    startTime = ($.formatDate(new Date(startTime),"yyyy-MM-dd hh:mm:ss")); 
    endTime = ($.formatDate(new Date(endTime),"yyyy-MM-dd hh:mm:ss")); 
    try {       
        ocx.iSeeOcxNewWindow(3);
        ocx.iSeeOcxSetPopupWndProperties('',300,200);
        ocx.iSeeOcxSetScreenModeEx(0,1);
        var ret = ocx.iSeeOcxDoPlaybackByTime(0,records.sbbh,records.tdbh, startTime, endTime);
        console.log('startrecord: ret:' + ret );
    } catch(e) {
    	$.showMsg("录像播放异常！");
    }
}
//一键视频
function videoSelectAll(){
	var resource = $("#chegps-tab-grid").datagrid("getChecked");
 	if(resource==""||resource==null||resource==undefined){
 		$.showMsg("暂无在线数据！");
		return;
	}
 	try {       
 		ocx.iSeeOcxNewWindow(3);
 		if(resource.length==1){
 			ocx.iSeeOcxSetPopupWndProperties('',300,200);
 			ocx.iSeeOcxSetScreenModeEx(0,1);
 		}
 		if(resource.length>1&&resource.length<=4){
 			ocx.iSeeOcxSetPopupWndProperties('',400,300);
 			ocx.iSeeOcxSetScreenModeEx(0,4);
 		}
 		if(resource.length>4&&resource.length<=9){
 			ocx.iSeeOcxSetPopupWndProperties('',600,400);
 			ocx.iSeeOcxSetScreenModeEx(0,9);
 		}
 		if(resource.length>9&&resource.length){
 			ocx.iSeeOcxSetPopupWndProperties('',800,600);
 			ocx.iSeeOcxSetScreenModeEx(0,16);
 		}
 		for(var i=0;i<resource.length;i++){	
 			if(resource[i].vdId && resource[i].channelId){
 				ocx.iSeeOcxMonitorStartEx2(0,i,resource[i].vdId, resource[i].channelId, 0);
 			}
 		} 
    } catch(e) {
    	$.showMsg("视频播放异常！");
    }
 	
}
//删除勾选数据
function deleteRows(){
	 var selRows = $('#chegps-tab-grid').datagrid('getSelections'),j=0,rowIndex;
	 if(selRows.length==0){
		 $.showMsg('请先选择一行! ');
		 return;
	 }else{
		top.$.dlg.confirm('确认删除勾选数据吗?',function(){ 
		    for(var i=0;i<selRows.length;i++){
		    	rowIndex = $('#chegps-tab-grid').datagrid('getRowIndex',selRows[i]);
		    	$('#chegps-tab-grid').datagrid('deleteRow',rowIndex);
		    }
		}); 
	}
}
//清空数据
function clearGrid(){
	var data=$('#chegps-tab-grid').datagrid('getData').rows;
	if(data.length==0){
		$.showMsg('暂无数据！ ');
		return;
	}else{
		top.$.dlg.confirm('确认清空所有数据吗?',function(){ 
			$("#chegps-tab-grid").datagrid('loadData',{total:0,rows:[]});
		});
	}
	
}
</script>
</body>
</html> 
