<%@ 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 class="easyui-layout" onselectstart="return false">
    <div data-options="region:'north'" id='north' style="height: 78px;border: none">
        <div class="left-box fl">
            <div>
                <span class="text-content">行政目录：</span>
                <input id="LIKExzmc" class="easyui-combotree" >
            </div>      
            <div>
                <span class="text-content">摄像头筛选：</span>
                <input class="easyui-textbox" id="LIKEtdmc"  prompt='请输入编号或名称' >
            </div>
        </div>
        <div class="right-box fl">                
            <button id="search" class="button-search" onclick="doSearch()">查询</button>
        </div>
    </div>
    <div data-options="region:'center',split:false" class="easyui-layout"  style="border: none">
        <table id="monitor-tab-grid"></table>
     </div>   
	<div id="monitor-contextMenu" class="easyui-menu" style="width:100px;display: none">   
	      <div iconCls="icon-actMode" onclick="startvideo();">实时视频</div>   
	      <div iconCls="icon-video" onclick="startrecord();">录像倒查</div>  
	      <div iconCls="icon-info-look" onclick="openWindow()">详细信息</div>   
	      <div iconCls="icon-location" onclick="locate();">地图定位</div> 
	      <div iconCls="icon-shouc" onclick="getdata();">加入所选</div>
	</div>
	
<script type="text/javascript">
var datagrid = null ;
window.ocx = top.ocx || null;

$(function(){
    $.fn.pagination.defaults.beforePageText = '';
    $.fn.pagination.defaults.afterPageText = '';
    $.fn.pagination.defaults.showPageList= false;
    $.fn.pagination.defaults.showRefresh= false;
    initGrid();
    initXzmcTree();
    textboxEnter();
})
//查询
function doSearch(){    
    $('#monitor-tab-grid').datagrid('load', getQueryParams());     
}
//查询条件
function getQueryParams(){
    var sParam = {};
    sParam.layerSeq = 1;
    sParam.LIKExzbh = $('#LIKExzmc').combotree('getValue');
    sParam.LIKEsbbh = $('#LIKEsbbh').val()||'';
    sParam.LIKEtdmc = $('#LIKEtdmc').textbox('getText');
//    console.log(sParam);
    return sParam;
}
//加载列表
function initGrid(){	
	datagrid = $('#monitor-tab-grid').datagrid({
        url:'szMapHttpAction!getMapGridData.do',
        queryParams:getQueryParams(),
        rownumbers:true,
        columns : [[
            {field:'tdmc',title:'摄像头名称',width:310,
                formatter:function showClick(value,record,index){ 
                return "<span title="+value+" >"+value+"</span>";
               }
            }
        ]],
        onRowContextMenu: function (e, rowIndex, rowData) {  
        	$('#monitor-tab-grid').datagrid('selectRow', rowIndex);
        	$('#monitor-contextMenu').menu('show', { 
        		left: e.pageX, 
        		top: e.pageY 
        		}); 
        	e.preventDefault();
        },
        onDblClickRow: function(index,row){
        	locate();
        },
        
        onLoadSuccess:function(){


        //	$(parent.window.frames[0].document).find("#iframe-jklk-tab")[0].contentWindow
        	// 获取当前页数据
        	/* console.log("0000:",$(parent.parent.window.frames[0].document));
        	console.log("iframe：",$(parent.parent.window.frames[0].document).find("iframe"));
       		var ff = parent.window.frames[0];
			console.log(ff);
			 */
        	/* var rows=$('#monitor-tab-grid').datagrid("getRows");

			 rows.forEach(function(item){
				 
			
				console.log(item);
			}) */
		}
    });	
}
//加入所选
function getdata(){
	var records = $("#monitor-tab-grid").datagrid("getSelected");
	var title=parent.$('#main-tab').tabs('getSelected').panel('options').title;
	parent.MapMain.setSelectedFrameGridData(records,title);
}
//行政树
function initXzmcTree(){
	$.ajax({
		type:'post',
		dataType : 'json',
		url:'ptxzsAction!query_Ptxzs.do',
		data:{
			order : " order by jdpx asc "
		},
		success:function(data){
			data.unshift({xzbh: "", xzmc: "全部目录"});
		    selectTree = $('#LIKExzmc').combotree({
            	checkbox:false,
             	border:false,
             	parentField:"sjxzbh",
             	textFiled:"xzmc",
             	idFiled:"xzbh",
             	data:data,
             	value: "",
             	panelWidth:200,
             	onLoadSuccess:function(node,data){
                	if(data){
                        $('#LIKExzmc').combotree("setValue",data[0].xzbh).combotree("setText", data[0].xzmc);
                    }
             	},	
             	onClick: function(node){
                	$('#LIKExzmc').combotree("setValue",node.xzbh).combotree("setText", node.xzmc);
             	}
        	});
		}
	});	
}
//查看详情
function openWindow(){
	var records = $("#monitor-tab-grid").datagrid('getSelected');
 	windowid = top.$.createWin({
		 title	: 	'摄像头详情',
		 width  :  600,
		 height :  300,
		 data	:  records,
		 url	:  top.sysUrl+"/szmap/business/base/item/iframe/monitor-tab_show.jsp"
	 });
}

//地图定位
function locate(){
	var records = $("#monitor-tab-grid").datagrid('getSelected');
	var point = {jd:records.jd, wd:records.wd};
	//var point = {jd:"121.66478727848529", wd:"31.071842277640442"};
	var graphic=parent.MapUtil.getGraphic(point);
	if(graphic!=null){
		parent.MapAPI.getMap().centerAt(graphic.geometry).then(function(){
			parent.MapAPI.getMap().infoWindow.setTitle(graphic.getInfoTemplate().title);
			parent.MapAPI.getMap().infoWindow.setContent(graphic.getInfoTemplate().content);
			parent.MapAPI.getMap().infoWindow.show(graphic.geometry, parent.MapAPI.getMap().getInfoWindowAnchor(graphic.geometry));
			parent.MapAPI.getMap().infoWindow.setFeatures([graphic]);
			});
	}
}
//实时视频
function startvideo(){
	var records = $("#monitor-tab-grid").datagrid('getSelected');
    if(!ocx) {
        $.log("ocx is undefined...");
        return ;
    } 
    var sbbh      = records.sbbh;
    var tdbh = records.tdbh;
    try {       
        ocx.iSeeOcxNewWindow(3);
        ocx.iSeeOcxSetPopupWndProperties('',300,200);
        ocx.iSeeOcxSetScreenModeEx(0,1);
        ocx.iSeeOcxMonitorStartEx2(0,0,sbbh,tdbh,0);
    } catch(e) {
        $.showMsg("视频播放异常！");
    }
}
//录像回查
function startrecord(){
	var datenow = new Date();
	var records = $("#monitor-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 textboxEnter(){
	$('#LIKEtdmc').textbox('textbox').keydown(function (e) {
        if (e.keyCode == 13) {
        	doSearch();
        }
    });   
}
</script>
</body>
</html>	
