//屏蔽鼠标右键
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/getBloodRecordTree",
			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].parentId != null && data[i].parentId != 1 && data[i].checked == 'true'){
							assortIds += data[i].assortName+",";
						}
					}
					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();
	//loadFilePath();
});

//加载图片根路径
function loadFilePath(){
	$.ajax({
		type:'get',
		url:path+'/commom/getFilePath',
		data:{patientId:$("#patientId").val()},
		async:false,
		dataType:'json',
		success:function(data){
			if(data.code == 0){
				$("#filePath").val(data.data.homeAddr);
			}else{
				toastr.error(data.msg);
			}
		}
	})
}

//树选中事件
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 == 2){
			if(i == 0){
				assortIds = nodes[i].assortName+",";
			}else{
				if(i != (nodes.length-1)){
					assortIds += nodes[i].assortName+",";
				}else{
					assortIds += nodes[i].assortName;
				}
			}
		}
	}
	$("#assortIds").val(assortIds);
};
//打印分类变更事件
$("#typeId").change(function(){
	menu.loadMenuTree();
})
//加载pdf按钮功能
function onloadPdf(){
	var patientId = $("#patientId").val();
	var filePath = $("#filePath").val();
	var assortIds = $("#assortIds").val()+".emr_record";
	var flag = $("#flag").val();
	$("#iframe1").attr("src",path+"/static/pdfjs/web/viewer1.html?file="+path+"/commom/showRecordContentBlood/"+flag+"/"+patientId+"/"+assortIds);
}
//下载pdf按钮功能
function onloadJpgForPdf(){
	var typeId = $("#typeId").val();
	if(typeId == undefined){
		typeId = '';
	}
    Common.confirm({
        title: "提示",
        message: "确认将左侧树选中的图片下载pdf?",
        operate: function (reselt) {
            if (reselt) {
                var patientId = "'" + $("#patientId").val() + "'";
                var assortIds = $("#assortIds").val();
                var flag = $("#flag").val();
                post(path + '/template/downloadPdfBlood', {
                    "patientIds": patientId,
                    "assortIds": assortIds,
                    "typeId": typeId,
                    "flag": flag
                });
            }
        }
    })
}
//记录打印记录
function printInfoBlood(){
	var patientId = "'"+$("#patientId").val()+"'";
	var assortIds = $("#assortIds").val();
	var typeId = $("#typeId").val();
	if(typeId == undefined){
		typeId = '';
	}
	var flag = $("#flag").val();
	$.ajax({
		type:'post',
		url:path+'/template/printInfoBlood',
		data:{"patientIds":patientId,"assortIds":assortIds,"typeId":typeId,"flag":flag},
		dataType:'json',
		success:function(data){
			if(data.code == 0){
				toastr.success("打印成功")
			}else{
				toastr.success(data.msg)
			}
		}
	})
	//post(path+'/template/printInfoBlood',{"patientIds":patientId,"assortIds":assortIds,"typeId":typeId,"flag":flag});
}
//确定按钮功能
function sure(){
	Common.confirm({
		title: "提示",
		message: "确认将左侧树选中的图片是否重新归页?",
		operate: function (reselt) {
			if (reselt) {
				//pdf页数
				var newAssortId = $("#newAssortId").val();
				if (newAssortId != '') {
					var patientId = $("#patientId").val();
					var assortIds = $("#assortIds").val();
					if(assortIds != ''){
						$.ajax({
							type: 'post',
							url: path + '/commom/updateScanAssortByBlood',
							data: {patientId: patientId, assortIds: assortIds,newAssortId: newAssortId},
							dataType: 'json',
							success: function (data) {
								if (data.code == 0) {
									toastr.success("重新归页成功！");
								}
								//重新加载
								menu.loadMenuTree();
							}
						})
					}else{
						toastr.warning("左侧树至少选中一张图片!")
					}
				} else {
					toastr.warning("要重新分页，需选中其中下拉框其中一项！")
				}
			}
		}
	})
}
function delPic(){
	Common.confirm({
		title: "提示",
		message: "确认将左侧树选中的图片删除,删除就不可恢复?",
		operate: function (reselt) {
			if (reselt) {
				var patientId = $("#patientId").val();
				var assortIds = $("#assortIds").val();
				if(assortIds != '') {
					$.ajax({
						type: 'post',
						url: path + '/commom/delScanAssortByBlood',
						data: {patientId: patientId, assortIds: assortIds},
						dataType: 'json',
						success: function (data) {
							if (data.code == 0) {
								toastr.success("删除成功！");
							}
							//重新加载
							menu.loadMenuTree();
						}
					})
				}
			}
		}
	})
}
/*
//确定按钮功能
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("要重新分页，需选中其中下拉框其中一项！")
				}
			}
		}
	})
}*/
