nvsrecord.js 24.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991



var layer = null;

//////////////////////////////////////////////////////////////////////////////////
///树节点逻辑
///////////////////////////////////////////////////////////////////////////////////		
var setting = {
	check: {
		enable: true,
		chkboxType:{
			"Y" : "ps", 
			"N" : "ps"
		}
	},
	view: {
		dblClickExpand: false,
		fontCss: getFont,
		nameIsHTML: true
		
	},
	edit: {
		enable: true,
		showRemoveBtn: false,
		showRenameBtn: false,
		drag: {
			prev: false,
			next: false,
			inner: false
		}
	},
	data: {
		simpleData: {
			enable: true, //设置是否使用简单数据模式(Array)
			idKey: "id", //设置节点唯一标识属性名称
			pIdKey: "pid" //设置父节点唯一标识属性名称
		},
		key: {
			name: "name", //zTree 节点数据保存节点名称的属性名称
			title: "name" //zTree 节点数据保存节点提示信息的属性名称		
		}
	},
	async: {
		enable: false //开启异步加载
	},
	callback: {
		onClick: zTreeOnClick,           //节点被点击的事件回调函数
		onDblClick: zTreeOnDblClick ,
		onDrop: zTreeOnDrop,
		beforeDrag: zTreeOnBeforeDrag,
		//onDragMove: zTreeOnDragMove,
		onRightClick: OnRightClick

	}
};

function getFont(treeId, node) {
	try {
		return node.font ? node.font : {};
	} catch(e) {
	}
	
	return {};
}




///构造目录树
function initExistTree(jsonData) {

    var treeNodes = jsonData;
	
	$.fn.zTree.init($("#treeDemo"), setting, treeNodes);
	fuzzySearch('treeDemo','#namekey',true,true); //初始化模糊搜索方法
    zTree = $.fn.zTree.getZTreeObj("treeDemo");

	zTree.expandAll(true);
}





function nodeParentFilter(treeNode) {
    if (!treeNode.isParent) { //判断是否为父节点
		return false;
	} 
	
	zTree.expandNode(treeNode, true);
	
	try{
		if(treeNode.level == 0){
			return false;
		}
		
		var children = treeNode.children;
		for (var i = 0; i < children.length; i++) {
			if(children[i].isHidden == false){
				return false;
			}
		}

	}catch(e){
		return true;
	}
	return true;
}

///不显示空父节点
function noShowEmptyParent(){
	var nodes = zTree.getNodesByFilter(nodeParentFilter); // 查找节点集合
	zTree.hideNodes(nodes);
}

///显示所有节点
function showAllItem(){
	var nodes = zTree.getNodesByParam("isHidden", true);
	zTree.showNodes(nodes);
	zTree.expandAll(true);
	//getChildCount();
}

///显示所有在线节点
function showOnlineItem(){
	showAllItem();
	var nodes = zTree.getNodesByParam("status", 0);
	if (nodes.length == 0) {
		return false;
	}
	zTree.hideNodes(nodes);
	
	noShowEmptyParent();
	
	zTree.expandAll(true);
	
	//getChildCount();
}

///显示所有不在线节点
function showOfflineItem(){
	showAllItem();
	var nodes = zTree.getNodesByParam("status", 1);
	if (nodes.length == 0) {
		return false;
	}
	
	zTree.hideNodes(nodes);
	
	noShowEmptyParent();
	
	zTree.expandAll(true);
	
	//getChildCount();
}


///单击
function zTreeOnClick(event, treeId, treeNode) {
	//var objToStr = JSON.stringify(treeNode);
	//console.log(objToStr);
	zTree.expandNode(treeNode);
};

///双击
function zTreeOnDblClick(event, treeId, treeNode) {
	
	return true;
};

function zTreeOnCheck(event, treeId, treeNode) {
	
}



///////////////////////////////////////////////////////////////////////////////////////////////
//////拖拽
///////////////////////////////////////////////////////////////////////////////////

function zTreeOnDrop(event, treeId, treeNodes, targetNode, moveType) {
	event.preventDefault();
	
	
	return true;
}

///拖拽
function zTreeOnDragMove(event, treeId, treeNodes) {
	//$("#zTreeMask_" + 0).remove();
	var objToStr = JSON.stringify(treeNodes);
	console.log("zTreeOnDragMove event:" + event.target.id + " treeId:" + treeId + " treeNodes:" +objToStr);
	return true;
}

///拖拽前
function zTreeOnBeforeDrag(treeId, treeNodes) {
	return !treeNodes[0].isParent;
}





///////////////////////////////////////////////////////////////////////////////////////////////
///右键菜单逻辑
///////////////////////////////////////////////////////////////////////////////////
function OnRightClick(event, treeId, treeNode) {
	if (treeNode && !treeNode.noR) {
		zTree.selectNode(treeNode);
		showRMenu(treeNode, event.clientX, event.clientY);
	}
}

///节点右键菜单事件
var flagRMenuHideparas = false;
$(document).ready(function() { 
	///鼠标移出右键菜单
	$("#rMenu").mouseleave(function(){
         delayHideRMenu(1000);
     });
	 
	 ///鼠标在右键菜单
	$("#rMenu").mouseover(function(){
       flagRMenuHideparas = false;
    });
	
	 ///阻止默认右键菜单
	$("#rMenu").contextmenu(function(e) {
		return false;
	});
 });
 
function showRMenu(treeNode, x, y) {
	var cssfontSize = $("#rMenu ul").css('font-size');
    var fontSize = parseFloat(cssfontSize);
	var value = "" + treeNode.id;
    $('.data-title').attr('data-menutitle', value);
	var rMenu = $("#rMenu");
	$("#rMenu ul").show();
	
	if (!treeNode.isParent) {
		$("#m_refresh").hide();
		$("#m_allnode").hide();
		$("#m_onlinenode").hide();
		$("#m_offlinenode").hide();
	
		$("#m_devinfo").show();
	} else {
		///根节点
		if(treeNode.level === 0) {
			$("#m_refresh").show();
			$("#m_allnode").show();
			$("#m_onlinenode").show();
			$("#m_offlinenode").show();
		} else {
			$("#m_refresh").hide();
			$("#m_allnode").show();
			$("#m_onlinenode").show();
			$("#m_offlinenode").show();
		}
		
		$("#m_devinfo").hide();
	}

	y += document.body.scrollTop;
	x += document.body.scrollLeft;
	
	var w = $("#leftFrames").width();
	 
	if(x > w - fontSize*13) {
		x = w - fontSize*13;
	}
	
	//var objToStr = JSON.stringify(treeNode);
	//console.log(" treeNode:" + objToStr + " x:"+x + " y:"+y + " f:"+fontSize);
	rMenu.css({"top":y+"px", "left":x+"px", "visibility":"visible"});

	$("body").bind("mousedown", onBodyMouseDown);
}

function hideRMenu() {
	var rMenu = $("#rMenu");
	if (rMenu) rMenu.css({"visibility": "hidden"});
	$("body").unbind("mousedown", onBodyMouseDown);
}


function delayHideRMenu(timer) {
    flagRMenuHideparas = true;
    setTimeout(function(){
        if(flagRMenuHideparas){
           hideRMenu();
        };
    },timer);
}


function onBodyMouseDown(event){
	var rMenu = $("#rMenu");
	if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length>0)) {
		rMenu.css({"visibility" : "hidden"});
		console.log("onBodyMouseDown");
	}
}


function rMenuRefreshTree(){
	zTree.destroy() ;
	
	setTimeout(function(){
        initTree();
    },500);
	
	delayHideRMenu(200);
}




function showDeviceInfo(treeNode) {
	var jsonarray =  [{"id":treeNode.id}];
	var xhr = $.ajax({
		url: "/nvsthird/getencoderinfo",
		type: "post",
		async: true,
		dataType: "json",
		contentType: "application/json",
		data: JSON.stringify({
			token: "",
			group:jsonarray
		}),
		timeout: 3000,
		success: function(res) {
			var objToStr = JSON.stringify(res);
			console.log('res:'+objToStr); 
			if(!isEmpty(res.group)) {
			
				layer.open({
				   type: 2 
				  ,title: '设备信息'
				  ,area: ['500px', '450px']
				  ,shade: 0
				  ,skin:'layui-layer-molv'
				  ,offset: 'auto'
				  ,scrollbar:false
				  ,id:'devinfolayer'
				  ,anim: 0
				  ,maxmin: false
				  ,zIndex: layer.zIndex //重点1
				  ,success: function(layero,index){
					 var iframeWin = window[layero.find('iframe')[0]['name']]; 
					 iframeWin.showtable(treeNode.id,treeNode.name,res.group[0]);
				  }
				  ,content: ['devinfo.html', 'no']
				});
				
			} else {
				layer.msg('获取信息失败',{icon: 2, title:treeNode.id,time: 2000,skin: 'layer-ext-moon' });
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('获取信息超时:' + errorThrown, {icon: 2, title:treeNode.id,time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('获取信息失败', {icon: 2, time: 2000,title:treeNode.id,skin: 'layer-ext-moon' });
			}
  	}
	});
}


function rMenuDeviceInfo(){
	var treeNode = zTree.getSelectedNodes()[0];
	if (treeNode) {
		if (treeNode.isParent) { //判断是否为父节点
			return false;
		} else if (treeNode.status == 0) { //判断摄像头是否在线
			layui.layer.msg('该摄像机不在线', {icon: 5, title:treeNode.id,time: 2000,skin: 'layer-ext-moon' });  
			return false;
		} else {
			showDeviceInfo(treeNode);
		}
	}
	return true;
}

////////////////////////////右键菜单逻辑结束//////////////////////////////////////////////////




var isControlDivMouseDrag = false;
var MAX_LEFT_WIDTH = jQuery(document).width();
var MIN_LEFT_WIDTH = 0;
var controlDivWidth = 6;
var leftDivWidth = 300;


function stopMouseEvent(evt){
  var event = window.event?window.event:evt;
  if (event.preventDefault) {
	 event.preventDefault();
	 event.stopPropagation();
  } else {
	 event.returnValue = false;
  }
} 

function resizeLeftRight(w){
	$("#control").css({ "left":w +"px" });
	$("#rightFrames").css({"margin-left":w + controlDivWidth +2+ "px"});
	$("#leftFrames").css({"width":w +"px"}); 
}

function setupControlMouseEvent(){ 
	$("#control").bind("mouseleave", function(evt){
		console.log("onmousemove:"+evt.clientX + " isControlDivMouseDrag:"+isControlDivMouseDrag);
		if(isControlDivMouseDrag){
			var evt = window.event?window.event:evt;
			if(evt.clientX >= MAX_LEFT_WIDTH){
				resizeLeftRight(MAX_LEFT_WIDTH);
			}else if(evt.clientX <= MIN_LEFT_WIDTH){
				resizeLeftRight(MIN_LEFT_WIDTH);
			}else{
				resizeLeftRight(evt.clientX);
			}
 
			stopMouseEvent(evt);
		}
	} ); 

	$("#control").bind("mouseup", function(evt){
		isControlDivMouseDrag = false;
		var evt = window.event?window.event:evt;
		console.log("onmouseup:" + evt.clientX);
		stopMouseEvent(evt);
		unsetControlMouseEvent();
	});
	
	document.onmousemove = function(evt){
		console.log("onmousemove:"+evt.clientX + " isControlDivMouseDrag:"+isControlDivMouseDrag);
		if(isControlDivMouseDrag){
			
			var evt = window.event?window.event:evt;
			if(evt.clientX >= MAX_LEFT_WIDTH){
				resizeLeftRight(MAX_LEFT_WIDTH); 
			}else if(evt.clientX <= MIN_LEFT_WIDTH){
				resizeLeftRight(MIN_LEFT_WIDTH);
			}else{
				resizeLeftRight(evt.clientX);
			}
 
			stopMouseEvent(evt);
		}
	}  

	document.onmouseup = function(evt){
		isControlDivMouseDrag = false;
		var evt = window.event?window.event:evt;
		console.log("onmouseup:" + evt.clientX);
		stopMouseEvent(evt);
		unsetControlMouseEvent();
	}
}

function unsetControlMouseEvent(){ 
	$("#control").unbind("mouseup");
	$("#control").unbind("mouseleave");
	document.onmousemove = null;
	document.onmouseup = null;
}


function switchLeftRight(){
	var w = $("#leftFrames").width();
    if (w >= 10){
          $("#resize-button").css({ "background": "url('img/left.gif') no-repeat","height":"41px","border":"none"});
		  resizeLeftRight(0);
     }
     else{
        $("#resize-button").css({ "background": "url('img/right.gif') no-repeat","height":"41px","border":"none"});	
		resizeLeftRight(leftDivWidth);
    }
}



function getHt(){
    var all_height = $(window).height();
    var div_height = all_height -  $("#headFrames").height()-4 ;
    $("#record_control").css("height",div_height+"px");
	 $("#mainDiv").css("height",div_height+"px");
	 
    $("#control").css("height",div_height+"px");
	
	var left_height = $("#leftFrames").height() ;
	var split_height = 0 ;
	var treebox_height = left_height -  split_height - split_height  - 4;
    $("#treebox").css("height",treebox_height+"px");
	
	//console.log("div_height:" + div_height + " treebox_height:" +treebox_height + " all_height:"+all_height);
}


///////////////////////录像查询逻辑开始///////////////////////////
///渲染查询时间
function renderSerchTime(initValue){
	var laydate = layui.laydate;
	var timestamp = (new Date()).getTime();
	
	laydate.render({
		 elem: '#record_begin_time' //指定元素
		,type: 'datetime'
		,format:'yyyy-MM-dd HH:mm:ss'
		,theme: 'molv'
		,value: new Date(timestamp-10*60*1000) 
		,isInitValue: initValue 
		,done: function(value, date, endDate){
			
		}
	});
	
	laydate.render({
		 elem: '#record_end_time' //指定元素
		,type: 'datetime'
		,theme: 'molv'
		,format:'yyyy-MM-dd HH:mm:ss'
		,value: new Date(timestamp) 
		,isInitValue: initValue 
		,done: function(value, date, endDate){
			
		}
	});
}


var g_hasRenderRecordTable = false;
///渲染查询结果表格
function reRenderTable(dataArray) {
	var table = layui.table;
	var configObject = {
		elem: '#recordSearchData'
		,skin: 'row ' //行边框风格
		,size: 'bg' //小尺寸的表格
		,data:dataArray
		,title: '查询记录'
		,id:"recordSearchDataId"
		,text: {
			none: '暂无相关数据' //默认:无数据。注:该属性为 layui 2.2.5 开始新增	
		}
		,cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
		,cols: [[
		   {field:'seq', title:'序号',width:80,align:'center',sort: true,style:'background-color: #5FB878; color: #fff;font-weight:bold;'} 
		  ,{field:'path', title:'位置',width:90,align:'center',style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{field:'name', title:'名字',align:'center',sort: true,style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{field:'begintime', title:'开始时间',width:165,align:'center',sort: true,style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{field:'endtime', title:'结束时间',width:165,align:'center',style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{field:'marktext', title:'查询标签',width:220,align:'center',style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{fixed: 'right', title:'操作', align:'center',toolbar: '#barDemo', width:180,style:'background-color: #5FB878; color:white;font-weight:bold;'}
		  ,{field:'resid',hide:true,width:0,align:'center',style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		  ,{field:'recordid',hide:true,width:0,align:'center',style:'background-color: #5FB878; color: #fff;font-weight:bold;'}
		]]
		,page: true
	};
		
		
	if(g_hasRenderRecordTable) {
		table.reload('recordSearchDataId',{data:dataArray});
	} else {
		table.render(configObject);
		g_hasRenderRecordTable = true;
	}
}

function getItemName(ipcArrayNodes,id) {
	//var allNodes = zTree.getNodes();
	for (var i = 0; i < ipcArrayNodes.length; i++) {
		var treeNode = ipcArrayNodes[i];
		if(treeNode.id === id){
			return treeNode.name;
		}
	}
	
	return "";
}

function doSearchRecordByTime(ipcArrayNodes,jsonDataReq) {
	
	var timeoutDefaultValue = getNetTimeout() * 1000;
	
	var xhr = $.ajax({
		url: "/nvsthird/queryListRecord",
		type: "post",
		async: true,
		dataType: "json",
		contentType: "application/json",
		data: jsonDataReq,
		timeout: timeoutDefaultValue,
		success: function(res) {
			
			var dataArray = new Array(); 
			
			if(!isEmpty(res.itemList)) {
				for(var i = 0; i < res.itemList.length; i++){
					var path = "";
					if(res.itemList[i].recordPath == 0) {
						path = "中心录像";
					} else {
						path = "前端录像";
					}
					
					var name = getItemName(ipcArrayNodes,res.itemList[i].resId);
					var item = {"seq":i+1,"path":path,"name":name,"begintime":res.itemList[i].startTime,"endtime":res.itemList[i].endTime,"marktext":"","recordid":res.itemList[i].recordID,"resid":res.itemList[i].resId};
					dataArray.push(item);
					
					layer.msg('录像查询完毕',{icon: 1, title:'录像查询',time: 2000,skin: 'layer-ext-moon' });
				}
				
			} else {
				layer.msg('录像查询结果为空',{icon: 5, title:'录像查询',time: 2000,skin: 'layer-ext-moon' });
			}
			
			reRenderTable(dataArray);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('录像查询超时:' + errorThrown, {icon: 2, title:'录像查询',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('录像查询失败', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			}
  	}
	});
}

///按时间段查询
function serachRecordByTime(ipcArrayNodes,begintime,endtime,path){
	var jsonarray = new Array(); 
	for (var i = 0; i < ipcArrayNodes.length; i++) {
		var treeNode = ipcArrayNodes[i];
		jsonarray.push({"id":treeNode.id});
	}
	
	var jsonDataReq = JSON.stringify({
			startTime: begintime,
			endTime: endtime,
			page: 0,
			recordPath: parseInt(path),
			recordType: 0,
			sn:"123",
			resIdGroup:jsonarray
		});
	
	doSearchRecordByTime(ipcArrayNodes,jsonDataReq);
	
	return true;
}

///按标签查询
function serachRecordByText(ipcArrayNodes,marktext,begintime,endtime,path){
	var dataArray = new Array(); 
	for (var i = 0; i < ipcArrayNodes.length; i++) {
		var treeNode = ipcArrayNodes[i];
		
	}
	
	reRenderTable(dataArray);

	return true;
}

function delimiterConvert(val){
   return val.replace('-','/').replace('-','/')
}

function getUserTreeCheckedNodes(){
	////处理节点勾选
	var ipcArrayNodes = new Array(); 
	
	///获取勾选节点
	var checkNodes = zTree.getCheckedNodes(true);

	for (var i = 0; i < checkNodes.length; i++) {
		var treeNode = checkNodes[i];
		if (treeNode.device_type != 1) { 
			continue;
		}  else if (treeNode.status == 0){
			continue;
		} 
		
		
		ipcArrayNodes.push(treeNode);
	}
	
	return ipcArrayNodes;
}
	
////查询函数
function serachRecord(){
	
	//////////////////////处理查询条件
	var form = layui.form;
	var serachData = form.val('record_find_value');
	
	var record_begin_time = "" + $("#record_begin_time").val();
	var record_end_time	  = "" + $("#record_end_time").val();
	var record_begin_timestamp = Date.parse(delimiterConvert(record_begin_time))/1000;
	var record_end_timestamp = Date.parse(delimiterConvert(record_end_time))/1000;

	///按时间查询
	if(serachData.recordsearchtype === "time") {
		
		////处理节点勾选
		var ipcArrayNodes = getUserTreeCheckedNodes(); 
		if(isEmpty(ipcArrayNodes) || ipcArrayNodes.length == 0 ) {
			layer.msg('请勾选摄像机节点!', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		} else if(ipcArrayNodes.length > 10){
			layer.msg('同时勾选摄像机节点不能超过10个!', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		}
	
		if(isNaN(record_begin_timestamp) || isNaN(record_end_timestamp)){
			layer.msg('查询时间不能为空', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		} else if(record_end_timestamp - record_begin_timestamp > 3 * 24 * 3600) {
			layer.msg('查询时间间隔不能大约3天', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		} else if(record_end_timestamp - record_begin_timestamp <= 0){
			layer.msg('查询时间间隔错误', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		}
		
	
		serachRecordByTime(ipcArrayNodes,record_begin_time,record_end_time,serachData.recordpath);
		
	} else {
		
		////处理节点勾选
		var ipcArrayNodes = getUserTreeCheckedNodes(); 
		
		if(isEmpty(serachData.marktext)) {
			layer.msg('查询标签不能为空', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		}
		
		if(isNaN(record_begin_timestamp) || isNaN(record_end_timestamp)){
			
		} else if(record_end_timestamp - record_begin_timestamp <= 0){
			layer.msg('查询时间间隔错误', {icon: 2, time: 2000,title:'录像查询',skin: 'layer-ext-moon' });
			return false;
		}
		
		serachRecordByText(ipcArrayNodes,serachData.marktext,record_begin_time,record_end_time,serachData.recordpath);
	}
	
	return true;
}


function  handleEditMarkText(nvsurl,jsonDataReq){
	var timeoutDefaultValue = getNetTimeout() * 1000;
	
	var xhr = $.ajax({
		url: nvsurl,
		type: "post",
		async: true,
		dataType: "json",
		contentType: "application/json",
		data: jsonDataReq,
		timeout: timeoutDefaultValue,
		success: function(res) {	
			layer.msg('标记成功',{icon: 1, title:'录像标记',time: 2000,skin: 'layer-ext-moon' });
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			layer.msg('录像标记超时:' + errorThrown, {icon: 2, title:'录像标记',time: 2000,skin: 'layer-ext-moon' });  
			return false;
		},
		complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
    	if(status == 'timeout'){//超时,status还有success,error等值的情况
      	 	xhr.abort();
    	} else if(status == 'error') {
				xhr.abort();
				layer.msg('录像标记失败', {icon: 2, time: 2000,title:'录像标记',skin: 'layer-ext-moon' });
			}
  	}
	});
}



function doEditMarkText(obj){
	var data = obj.data;
	
	var objToStr = JSON.stringify(data);	
	console.log(objToStr);
	
	layer.prompt({
		formType: 2
		,title:"查询标签"
		,value: data.marktext
	}, function(value, index){
	
		var path = 0;
		if(data.path === "前端录像") {
			path = 1;
		} 
		
		if(isEmpty(data.marktext)) {
			var jsonDataReq = JSON.stringify({
				resId : data.resid,
				beginTime: data.begintime,
				endTime: data.endtime,
				recordPath: path,
				recordId: "",
				markText:"",
				description:""
			});
			handleEditMarkText("/nvsthird/delRecordMaskReq",jsonDataReq);
			
		} else {
			var jsonDataReq = JSON.stringify({
				resId : data.resid,
				beginTime: "",
				endTime: "",
				recordPath: -1,
				recordId: "",
				markText:data.marktext,
				description:""
			});
			handleEditMarkText("/nvsthird/delRecordMaskReq",jsonDataReq);
		}
		
		
		
		var jsonDataReq = JSON.stringify({
			resId : data.resid,
			beginTime: data.begintime,
			endTime: data.endtime,
			recordPath: path,
			recordId: data.recordid,
			markText:value,
			description:""
		});
		handleEditMarkText("/nvsthird/addRecordMaskReq",jsonDataReq);
		
		
		obj.update({
			marktext: value
	    });
		
		layer.close(index);
	});
}





function doPlayRecordVideo(sdata){
	var record_begin_timestamp = Date.parse(delimiterConvert(sdata.begintime))/1000;
	var record_end_timestamp = Date.parse(delimiterConvert(sdata.endtime))/1000;
	
	var path = "0";
	if(sdata.path === "前端录像") {
		path = "1";
	} 
	
	var id = sdata.resid + "-" +  record_begin_timestamp + "-" + record_end_timestamp + "-" + path + "-" + "0";
	var videoUrl = getPlaybackUrl(id);
	
	var layer_height = $(window).height()*7/8;
	var layer_width = $(window).width()*2/3;
	layer.open({
		type: 2 
		,title: sdata.name
		,area: [''+layer_width+'px', ''+layer_height+'px']
		,shade: 0
		,skin:'layui-layer-molv'
		,offset: 'auto'
		,scrollbar:false
		,anim: 0
		,maxmin: true
		,anim: 5
		,zIndex: layer.zIndex //重点1
		,success: function(layero,index){
			layer.setTop(layero); //重点2
			//var iframeWin = window[layero.find('iframe')[0]['name']]; 
		//	iframeWin.setRecordInfo(sdata);
		}
		,content: [videoUrl, 'no']
	});
}


function doDownRecordVideo(data){
	layer.msg('功能暂未实现', {icon: 6, time: 2000,title:'录像下载',skin: 'layer-ext-moon' });
}
///////////////////////录像查询逻辑结束///////////////////////////
  
$(function(){
	////动态获取布局宽度
	controlDivWidth = $("#control").width();
	leftDivWidth = $("#leftFrames").width();
	
	///动态设置页面高度
	getHt();
	
	///弹窗初始化
	layui.use('layer', function(){
		layer = layui.layer; 
    });
	
	///左页面布局可拖拽宽度初始化
	$("#control").mousedown( function(){
		var evt = window.event;
		if ((evt.which && evt.which == 1 ) || (evt.button && evt.button == 1)){
			setupControlMouseEvent();
			isControlDivMouseDrag = true;
			console.log("mousedown:"+evt.clientX);
		}
    });
	
	///查询参数表格动态变化
	layui.use('form', function(){
		var form = layui.form;
		form.on('radio', function(data){
			if(data.value === "time"){
				$(".find_expend").hide();
				renderSerchTime(true);
				reRenderTable([]);
			} else {
				$(".find_expend").show();
				$("#record_begin_time").val("");
				$("#record_end_time").val("");
				renderSerchTime(false);
				reRenderTable([]);
			}
			
		}); 
	});

	
	///查询参数日期表格初始化
	layui.use('laydate', function(){
		renderSerchTime(true);
	});
	
	///查询结果表格监听
	layui.use('table', function(){
		var table = layui.table;
		
		reRenderTable([]);
		
		//监听行工具事件
		table.on('tool(recordSearchData)', function(obj){
			var data = obj.data;
			if(obj.event === 'play'){
				doPlayRecordVideo(data);
			} else if(obj.event === 'edit'){
				doEditMarkText(obj);
			} else if(obj.event === 'down'){
				doDownRecordVideo(data);
			}
		});
	});
  


	
	///等待加载目录树
	setTimeout(function(){
		var tempData = getUserTreeFromCache();
		if (tempData) {
			var nodes = JSON.parse(""+tempData);
			initExistTree(nodes);
		} 
    },100);
	
});