//屏蔽鼠标右键
document.oncontextmenu = function(e) {
	var e = e || window.event;
	e.returnValue = false;
	return false;
}
//禁止快捷键打印
function disabledPrint(){
	if(event.keyCode==80 && event.ctrlKey){
		event.keyCode=0;
		event.returnValue=false;
	}
	if (event.ctrlKey && event.keyCode == 83) {
		event.preventDefault();
		event.returnValue = false;
		return false;
	}
}
//树操作
var menu = {
	setting: {
		view:{
			fontCss : {"font-family": "微软雅黑","color":"blue"}
		},
		data:{
			key:{
				name:"assortName"
			},
			simpleData: {
				chkStyle: "checkbox",
				enable: true,
				idKey: "id",
				pIdKey: "parentId",
			},
		},
		check:{
			enable:true
		},
		callback: { //回调函数
			onCheck: onCheck }
	},
	loadMenuTree:function(){
		$.ajax({
			type: "post",
			url:path+"/commom/getRecordTypeTree",
			data:{patientId:$("#patientId").val(),typeId:$("#typeId").val()},
			dataType:"json",
			success:function(data){
				$("#assortIds").val("");
				if(data != null){
					var assortIds = '';
					for (var i = 0; i < data.length; i++) {
						if(data[i].checked != null && data[i].checked == 'true'){
							assortIds += "'"+data[i].assortId+"',";
						}
					}
					if(assortIds != ''){
						assortIds = assortIds.substring(0,assortIds.length-1);
						$("#assortIds").val(assortIds);
					}
					$.fn.zTree.init($("#ztree"), menu.setting, data);
					zTree = $.fn.zTree.getZTreeObj("ztree");
					var nodes = zTree.getNodes();
					for (var i = 0; i < nodes.length; i++) { //设置节点展开
						zTree.expandNode(nodes[i], true, false, true);
					}
					//加载pdf
					onloadPdf();
				}
			}
		})
	}
};
//加载树
$().ready(function(data){
	menu.loadMenuTree();
});

//树选中事件
function onCheck(e, treeId, treeNode) {
	var treeObj=$.fn.zTree.getZTreeObj("ztree");
	nodes=treeObj.getCheckedNodes(true);
	var assortIds = '';
	for (var i = 0; i < nodes.length; i++) {
		if(nodes[i].level == 1){
			if(i != (nodes.length-1)){
				assortIds += "'"+nodes[i].assortId+"',";
			}else{
				assortIds += "'"+nodes[i].assortId+"'";
			}
		}
	}
	$("#assortIds").val(assortIds);
};
//打印分类变更事件
$("#typeId").change(function(){
	menu.loadMenuTree();
})
//加载pdfan按钮功能
function onloadPdf(){
	var patientId = $("#patientId").val();
	var assortIds = $("#assortIds").val();
	$("#iframe1").attr("src",path+"/static/pdfjs/web/viewer.html?file="+path+"/commom/showRecordContent/"+patientId+"/"+assortIds);
	$("#errorShowMore").hide();
	$("#iframe1").css("height",$("body")[0].offsetHeight)
}
//确定按钮功能
function sure(){
	Common.confirm({
		title: "提示",
		message: "确认是否重新归页?",
		operate: function (reselt) {
			if (reselt) {
				//pdf页数
				var index = $("#iframe1").contents().find("#pageNumber").val();
				var newAssortId = $("#newAssortId").val();
				if (newAssortId != '') {
					if (index != '' && index != null) {
						var patientId = $("#patientId").val();
						var assortIds = $("#assortIds").val();
						$.ajax({
							type: 'post',
							url: path + '/commom/updateScanAssort',
							data: {patientId: patientId, assortIds: assortIds, index: index, newAssortId: newAssortId},
							dataType: 'json',
							success: function (data) {
								if (data.code == 0) {
									toastr.success("重新归页成功！");
								}
								//重新加载
								menu.loadMenuTree();
							}
						})
					}
				} else {
					toastr.warning("要重新分页，需选中其中下拉框其中一项！")
				}
			}
		}
	})
}