//屏蔽鼠标右键
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;
	}
}
//初始化函数
$(function(){
	//加载其他诊断名称鼠标滑过显示全部文本
	//loadQtip('.otherDiagName');
	//加载病案信息
	loadRecord();
	//加载iframe
	$("#iframe").prop("src",path+"/commom/showRecordIframeBlood?patientId="+$("#patientId").val()
	+"&flag=home_addr");
})
/*//封装其他诊断名称鼠标滑过显示全部文本
function loadQtip(selector){
	$(selector).qtip({
		content: {text:$('#otherDiagName').val()},
		show: {
			effect: function() {
				$(this).slideDown();
			}
		},
		hide: {
			effect: function() {
				$(this).slideUp();
			}
		}
	});
}*/

//加载病案信息
function loadRecord(){
	$.ajax({
		type:'get',
		url:path+'/commom/getRecord',
		data:{patientId:$("#patientId").val()},
		async:false,
		dataType:'json',
		success:function (data) {
			if(null != data && data != ''){
				$("#inpatientNo").val(data.inpatientNo);
				$("#name").val(data.name);
				$("#admissTimes1").val(data.admissTimes);
				$("#inpatientNo1").val(data.inpatientNo);
				$("#name1").val(data.name);
				$("#admissTimesValue").val(data.admissTimes);
				$("#disDate").val(data.disDate);
				$("#disDeptName").val(data.disDept);
				$("#diagName").val(data.mainDiagName);
				$("#otherDiagName").val(data.otherDiagName);
				$("#admissId").val(data.admissId);
				$("#mainDisThing").val(data.mainDisThing);
			}
		}
	})
}

/**********************************模态框内业务操作******************************************************/
/**********************************模态框1操作******************************************************/
	//加载类别树
	//树操作
var zNodes;
var menu = {
	setting: {
		view:{
			fontCss : {"font-family": "微软雅黑","color":"blue"}
		},
		data:{
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "parentId",
			},
		},
		callback: { //回调函数
			onClick: zTreeOnClick }
	},
	loadMenuTree:function(patientId){
		$.ajax({
			type: "post",
			url:path+"/commom/getCodeTypeTree",
			data:{patientId:patientId},
			dataType:"json",
			success:function(data){
				$.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);
				}
				zNodes = data;
			}
		})
	}
};
//树点击事件
function zTreeOnClick(event, treeId, treeNode) {
    //赋值当前节点id
	$("#typeFlag").empty();
    $("#treeId").val(treeNode.id);
	if(treeNode.level == 0){
		//分类
		$("#codeTypeBtn").show();
		var roleId = $("#roleId").val();
		if(treeNode.typeFlag == 'operate' || treeNode.typeFlag == 'diag' || treeNode.typeFlag == 'herbDiag'){
			$("#codeTypeBtn").hide();
		}
		if(roleId == 0){
			$("#codeTypeBtn").show();
		}
		showThisDiv(1);
		$("#codeTypeId").val(treeNode.selfId);
		$("#typeFlag").val(treeNode.typeFlag);
		$("#typeName").val(treeNode.typeName);
		$("#typeEffective").val(treeNode.effective);
	}else{
		if(treeNode.operateName != '' && treeNode.operateName != null){
			showThisDiv(2);
			$("#currentOperateNo").val(treeNode.operateNo);
			$("#operateNo").val(treeNode.operateNo);
			$("#operateCode").selectpicker('val',treeNode.operateCode);
			$("#operateName").selectpicker('val',treeNode.operateName);
			$("#operateDate").val(treeNode.operateDateStr);
			$("#operator").val(treeNode.operator);
			$("#assistant1").val(treeNode.assistant1);
			$("#assistant2").val(treeNode.assistant2);
			$("#anaesthesiaType").selectpicker('val',treeNode.anaesthesiaType);
			$("#cut").selectpicker('val',treeNode.cut);
			$("#anaesthesiaName").val(treeNode.anaesthesiaName);
			$("#operateClass").val(treeNode.operateClass);
			$("#operCode").val(treeNode.operCode);
			$("#operName").val(treeNode.operName);
			$("#operDate").val(treeNode.operDateStr);
			refrashOperForm();
		}else if(treeNode.diagNo != '' && treeNode.diagNo != null){
			showThisDiv(3);
			$("#currentDiagNo").val(treeNode.diagNo);
			$("#diagNo").val(treeNode.diagNo);
			$("#diagCode").selectpicker('val',treeNode.diagCode);
			$("#diagName1").selectpicker('val',treeNode.diagName);
			$("#diagType").val(treeNode.diagType);
			$("#disThing").val(treeNode.disThing);
			$("#pathologyCut").val(treeNode.pathologyCut);
			$("#xRay").val(treeNode.xRay);
			$("#diagOperCode").val(treeNode.operCode);
			$("#diagOperName").val(treeNode.operName);
			$("#diagOperDate").val(treeNode.operDateStr);
			refrashDiagForm();
		}else if(treeNode.herbNo != '' && treeNode.herbNo != null) {
			showThisDiv(4);
			$("#currentHerbDiagNo").val(treeNode.herbNo);
			$("#herbNo").val(treeNode.herbNo);
			$("#herbCode").selectpicker('val', treeNode.herbCode);
			$("#herbName").selectpicker('val', treeNode.herbName);
			$("#herbType").val(treeNode.herbType);
			$("#herbThing").val(treeNode.herbThing);
			$("#herbDiagOperCode").val(treeNode.operCode);
			$("#herbDiagOperName").val(treeNode.operName);
			$("#herbDiagOperDate").val(treeNode.operDateStr);
			refrashHerbOperForm();
		}
	}
}
//封装刷新手术编码表单的多选下拉框
function refrashOperForm(){
	$("#operateCode").selectpicker('refresh');
	$("#operateName").selectpicker('refresh');
	$("#anaesthesiaType").selectpicker('refresh');
	$("#cut").selectpicker('refresh');
}
//封装模态框内四个div的动态显示
function showThisDiv(index){
	for (var i = 1; i <= 4; i++) {
		if(i == index){
			$("#div"+i).show();
		}else{
			$("#div"+i).hide();
		}
	}
	if(index != -1){
		reSetForm(index);
	}
}
//封装刷新四个form表单
function reSetForm(index){
	document.forms[index-1].reset()
}
function loadTree(){
	var patientId = $("#iframe").contents().find("#patientId").val();
	menu.loadMenuTree(patientId);
    //初始化模糊搜索方法
	fuzzySearch('ztree','#key',null,true,menu.setting,zNodes);
}
//选中原来选中的节点
function selectCurrentNode(){
    var currentId = $("#treeId").val();
    var zTree = $.fn.zTree.getZTreeObj("ztree");
    var node = zTree.getNodeByParam("id",currentId);
    zTree.selectNode(node);
}
//加载模态框1
function loadDiag1(){
	//加载树
	loadTree();
	showThisDiv(-1);
	$("#codeTypeId").val("");
}
//编码录入按钮功能
function insertCode(){
	$("#iFrame1").prop("src",path+"/commom/codeTable?patientId="+$("#patientId").val());
	/*loadDiag1();
	//加载字典
	loadDiagDictionary();*/
}
//添加编码类别按钮功能
function addCodeType(){
	$("#codeTypeBtn").show();
	$("#codeTypeId").val("");
	$("#treeId").val("");
	showThisDiv(1);
	//取消树选中
    var treeObj = $.fn.zTree.getZTreeObj("ztree");
    treeObj.cancelSelectedNode();
}
//保存添加编码类型
function saveCodeType(){
	var index = $("#iframe").contents().find("#iframe1").contents().find("#pageNumber").val();
	var patientId = $("#iframe").contents().find("#patientId").val();
	var assortIds = $("#iframe").contents().find("#assortIds").val();
	if($("#typeFlag").val() != '' && $("#typeFlag").val() != null){
		$.ajax({
			type:'post',
			url:path+"/commom/addCodeType",
			data:{
				id:$("#codeTypeId").val(),
				typeFlag:$("#typeFlag").val(),
				typeName:$("#typeName").val(),
				effective:$("#typeEffective").val(),
				index:index,
				patientId:patientId,
				assortIds:assortIds,
			},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					toastr.success("保存成功！")
					//加载模态框1
					loadDiag1();
				}else{
					toastr.warning(data.msg)
				}
			}
		})
        setTimeout(function(){
            if($("#treeId").val()==''){
                //选中新增的类别
                var newId = "";
                for (var i = 0; i < zNodes.length; i++) {
                    if(zNodes[i].parentId == 0){
                        newId = zNodes[i].id;
                    }
                }
                var zTree = $.fn.zTree.getZTreeObj("ztree");
                var node = zTree.getNodeByParam("id",newId);
                zTree.selectNode(node);
            }else{
                selectCurrentNode();
            }
        },1000);
    }else{
		toastr.warning("类别标志不能空，或者无可添加的类别标志！");
	}
}
//删除编码类别
function delCodeType(){
    Common.confirm({
        title: "提示",
        message: "确认是否删除这条数据?",
        operate: function (reselt) {
            if (reselt) {
                var id = $("#treeId").val();
                var node = zTree.getNodeByParam("id", id);
                var childrenNode = node.children;
                if (childrenNode != undefined) {
                    toastr.warning("请先删除子集！");
                } else {
                    $.ajax({
                        type: 'post',
                        url: path + "/commom/delCodeTypeById/" + $("#codeTypeId").val(),
                        dataType: 'json',
                        success: function (data) {
                            if (data.code == 0) {
                                toastr.success("删除成功！")
                                //加载模态框1
                                loadDiag1();
                            } else {
                                toastr.error("删除失败！");
                            }
                        }
                    })
                }
            }
        }
	})
}
//添加编码按钮功能
function addCode(){
	setFormToken();
	var codeTypeId = $("#codeTypeId").val();
	if(codeTypeId != ''){
		var typeFlag = $("#typeFlag").val();
		if(typeFlag == 'operate'){
			//手术
			showThisDiv(2);
			//置空该手术序号
			$("#currentOperateNo").val("");
			if($("#operDate").val() == ''){
				$("#operDate").val(currentDate);
			}
			refrashOperForm();
		}else if(typeFlag == 'diag'){
			//西医诊断
			showThisDiv(3);
			//置空西医诊断序号
			$("#currentDiagNo").val("");
			if($("#diagOperDate").val() == ''){
				$("#diagOperDate").val(currentDate);
			}
		}else if(typeFlag == 'herbDiag'){
			//中医诊断
			showThisDiv(4);
			//置空中医诊断序号
			$("#currentHerbDiagNo").val("");
			if($("#herbDiagOperDate").val() == ''){
				$("#herbDiagOperDate").val(currentDate);
			}
		}
	}else{
		toastr.warning('请选中类别！');
	}
}
/***************************************************手术编码*********************************************************/
//验证手术序号是否存在
$("#operateNo").blur(function(){
	var operateNo = $("#operateNo").val();
	var currentOperateNo = $("#currentOperateNo").val();
	if(currentOperateNo == '' && operateNo != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/checkOperateNo',
			data:{
				patientId:$("#iframe").contents().find("#patientId").val(),
				operateNo:operateNo
			},
			dataType:'json',
			success:function(data){
				if(data.code != 0){
					toastr.warning("该手术序号已存在！");
					$("#operateNo").val("");
					$("#operateNo").focus();
				}
			}
		})
	}
})
//手术编码级联手术名称
$("#operateCode").change(function(){
	var code = $("#operateCode").val();
	if(code != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/getOperByCodeOrName',
			data:{
				code:code,
			},
			dataType:'json',
			success:function(data){
				if(data != null){
					$("#operateName").selectpicker('val',data[0].name);
					$("#operateName").selectpicker('refresh');
				}
			}
		})
	}
})
//手术名称级联手术编码
$("#operateName").change(function(){
	var name = $("#operateName").val();
	if(name != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/getOperByCodeOrName',
			data:{
				name:name,
			},
			dataType:'json',
			success:function(data){
				if(data != null && data != ''){
					if(data.length == 1){
						$("#operateCode").selectpicker('val',data[0].code);
						$("#operateCode").selectpicker('refresh');
					}else{
						var str = '';
						for (var i = 0; i < data.length; i++) {
							if(i != data.length -1){
								str += data[i].code + ",";
							}else{
								str += data[i].code
							}
						}
						toastr.warning("该手术名称对应的手术编码有多个，分别为"+str+"建议手动选择编码");
					}
				}else{
					toastr.warning("无对应的编码！");
				}
			}
		})
	}
})
//保存手术编码
function saveOperCode(){
	var currentOperateNo = $("#currentOperateNo").val();
	var operateNo = $("#operateNo").val();
	if(operateNo != ''){
		//是否修改该手术序号
		var isUpdateOperNo;
		if(currentOperateNo != ''){
			if(currentOperateNo == operateNo){
				isUpdateOperNo = 0;
			}else{
				isUpdateOperNo = 1;
			}
		}
		$.ajax({
			type:'post',
			url:path+'/commom/saveOperCode',
			data:{
				currentOperateNo:currentOperateNo,
				isUpdateOperNo:isUpdateOperNo,
				patientId:$("#iframe").contents().find("#patientId").val(),
				operateNo:$("#operateNo").val(),
				operateCode:$("#operateCode").val(),
				operateName:$("#operateName").val(),
				operateDate:$("#operateDate").val(),
				operator:$("#operator").val(),
				assistant1:$("#assistant1").val(),
				assistant2:$("#assistant2").val(),
				anaesthesiaType:$("#anaesthesiaType").val(),
				cut:$("#cut").val(),
				anaesthesiaName:$("#anaesthesiaName").val(),
				operateClass:$("#operateClass").val(),
				operCode:$("#operCode").val(),
				operName:$("#operName").val(),
				operDate:$("#operDate").val(),
				formToken:$("#formToken1").val()
			},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					toastr.success("保存成功！");
					//加载模态框1
					loadDiag1();
				}else{
					toastr.error(data.msg);
				}
			}
		})
        setTimeout(function(){
            selectCurrentNode();
        },1000);
	}else{
		$("#operateNo").focus();
		toastr.warning("手术序号不能为空！");
	}
}
//删除手术编号
function delOperCode() {
    Common.confirm({
        title: "提示",
        message: "确实是否删除此条数据?",
        operate: function (reselt) {
            if (reselt) {
                $.ajax({
                    type: 'post',
                    url: path + "/commom/deleteOperCodeByPatientIdAndOperNo",
                    data: {
                        operateNo: $("#currentOperateNo").val(),
                        patientId: $("#iframe").contents().find("#patientId").val()
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 0) {
                            toastr.success("删除成功！")
                            //加载模态框1
                            loadDiag1();
                        } else {
                            toastr.error("删除失败！");
                        }
                    }
                })
            }
        }
	})
}
/**************************************西医诊断字典******************************************************/
//封装刷新西医编码表单的多选下拉框
function refrashDiagForm(){
	$("#diagCode").selectpicker('refresh');
	$("#diagName1").selectpicker('refresh');
}
//加载诊断字典
function loadDiagDictionary(){
	$("#diagCode").empty();
	$("#diagName1").empty();
	$("#diagType").empty();
	$("#disThing").empty();
	$("#herbCode").empty();
	$("#herbName").empty();
	$("#herbType").empty();
	$("#herbThing").empty();
	//加载诊断编码和诊断名称
	$.ajax({
		type:'post',
		url:path+'/commom/getIcdCodeList',
		dataType:'json',
		success:function(data){
			if(data != null){
				var codeHtml = '';
				var nameHtml = '';
				for (var i = 0; i < data.length; i++) {
					codeHtml += '<option value='+data[i].code+'>'+data[i].code+'</option>';
					nameHtml += '<option value='+data[i].name+'>'+data[i].name+'</option>';
				}
				$("#diagCode").append(codeHtml);
				$("#diagCode").selectpicker('refresh');
				$("#diagName1").append(nameHtml);
				$("#diagName1").selectpicker('refresh');
				$("#herbCode").append(codeHtml);
				$("#herbCode").selectpicker('refresh');
				$("#herbName").append(nameHtml);
				$("#herbName").selectpicker('refresh');
			}
		}
	})
	//加载诊断类型
	$.ajax({
		type: 'post',
		url: path + '/commom/getDictionaryByTypeCode',
		data: {typeCode: 'dis_diag_type'},
		dataType: 'json',
		success: function (data) {
			if (data != null) {
				var html = '';
				for (var i = 0; i < data.length; i++) {
					html += '<option value=' + data[i].code + '>' + data[i].name + '</option>';
				}
				$("#diagType").append(html);
				$("#herbType").append(html);
			}
		}
	})
	//加载转归情况
	$.ajax({
		type: 'post',
		url: path + '/commom/getDictionaryByTypeCode',
		data: {typeCode: 'dis_diag_status'},
		dataType: 'json',
		success: function (data) {
			if (data != null) {
				var html = '';
				for (var i = 0; i < data.length; i++) {
					html += '<option value=' + data[i].code + '>' + data[i].name + '</option>';
				}
				$("#disThing").append(html);
				$("#herbThing").append(html);
			}
		}
	})
}
//诊断编码级联诊断名称
$("#diagCode").change(function(){
	codeChangeToName('diagCode','diagName1');
})
//诊断名称级联诊断编码
$("#diagName1").change(function(){
	nameChangeToCode('diagCode','diagName1');
})
//检查诊断序号是否存在
$("#diagNo").blur(function(){
	var diagNo = $("#diagNo").val();
	var currentDiagNo = $("#currentDiagNo").val();
	if(currentDiagNo == '' && diagNo != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/checkDiagNo',
			data:{
				patientId:$("#iframe").contents().find("#patientId").val(),
				diagNo:diagNo
			},
			dataType:'json',
			success:function(data){
				if(data.code != 0){
					toastr.warning("该诊断序号已存在！");
					$("#diagNo").val("");
					$("#diagNo").focus();
				}
			}
		})
	}
	//序号为1,选中主要诊断。不是1把主要诊断禁用
	if(diagNo != ''){
		if(diagNo == 1){
			$("#diagType").val(1);
			$('#diagType option:eq(0)').prop('disabled',false);
		}else{
			$("#diagType").val(2);
			$('#diagType option:eq(0)').prop('disabled',true);
		}
	}
})
//编码级联名称方法
function codeChangeToName(code,name){
	var code = $("#"+code).val();
	if(code != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/getIcdCodeByCodeOrName',
			data:{
				code:code,
			},
			dataType:'json',
			success:function(data){
				if(data != null){
					$("#"+name).selectpicker('val',data[0].name);
					$("#"+name).selectpicker('refresh');
				}
			}
		})
	}
}
//名称级联编码方法
function nameChangeToCode(code,name){
	var name = $("#"+name).val();
	if(name != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/getIcdCodeByCodeOrName',
			data:{
				name:name,
			},
			dataType:'json',
			success:function(data){
				if(data != null && data != ''){
					if(data.length == 1){
						$("#"+code).selectpicker('val',data[0].code);
						$("#"+code).selectpicker('refresh');
					}else{
						var str = '';
						for (var i = 0; i < data.length; i++) {
							if(i != data.length -1){
								str += data[i].code + ",";
							}else{
								str += data[i].code
							}
						}
						toastr.warning("该诊断术名称对应的idc编码有多个，分别为"+str+"建议手动选择编码");
					}
				}else{
					toastr.warning("无对应的编码！")
				}
			}
		})
	}
}
//保存西医诊断编码
function saveDiag(){
	var currentDiagNo = $("#currentDiagNo").val();
	var diagNo = $("#diagNo").val();
	if(diagNo != ''){
		if(diagNo == 1 && $("#diagType").val() != 1){
			toastr.warning("诊断序号为1,诊断类型必须是主要诊断!");
		}else{
			//是否修改该诊断序号
			var isUpdateOperNo;
			if(currentDiagNo != ''){
				if(currentDiagNo == diagNo){
					isUpdateOperNo = 0;
				}else{
					isUpdateOperNo = 1;
				}
			}
			$.ajax({
				type:'post',
				url:path+'/commom/saveDiag',
				data:{
					currentDiagNo:currentDiagNo,
					isUpdateOperNo:isUpdateOperNo,
					patientId:$("#iframe").contents().find("#patientId").val(),
					diagNo:$("#diagNo").val(),
					diagCode:$("#diagCode").val(),
					diagName:$("#diagName1").val(),
					diagType:$("#diagType").val(),
					disThing:$("#disThing").val(),
					pathologyCut:$("#pathologyCut").val(),
					xRay:$("#xRay").val(),
					operCode:$("#diagOperCode").val(),
					operName:$("#diagOperName").val(),
					operDate:$("#diagOperDate").val(),
					formToken:$("#formToken2").val()
				},
				dataType:'json',
				success:function(data){
					if(data.code == 0){
						toastr.success("保存成功！");
						//加载模态框1
						loadDiag1();
					}else{
						toastr.error(data.msg);
					}
				}
			})
			setTimeout(function(){
				selectCurrentNode();
			},1000);
		}
	}else{
		$("#diagNo").focus();
		toastr.warning("诊断序号不能为空！");
	}
}
//删除西医诊断编号
function deleteDiag() {
    Common.confirm({
        title: "提示",
        message: "确实是否删除此条数据?",
        operate: function (reselt) {
            if (reselt) {
                $.ajax({
                    type: 'post',
                    url: path + "/commom/deleteCodeByPatientIdAndDiagNo",
                    data: {
                        diagNo: $("#currentDiagNo").val(),
                        patientId: $("#iframe").contents().find("#patientId").val()
                    },
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 0) {
                            toastr.success("删除成功！")
                            //加载模态框1
                            loadDiag1();
                        } else {
                            toastr.error("删除失败！");
                        }
                    }
                })
            }
        }
	})
}
/*********************************************中医诊断操作************************************************/
//封装刷新中医编码表单的多选下拉框
function refrashHerbOperForm(){
	$("#herbCode").selectpicker('refresh');
	$("#herbName").selectpicker('refresh');
}
//诊断编码级联诊断名称
$("#herbCode").change(function(){
	codeChangeToName('herbCode','herbName');
})
//诊断名称级联诊断编码
$("#herbName").change(function(){
	nameChangeToCode('herbCode','herbName');
})
//检查诊断序号是否存在
$("#herbNo").blur(function(){
	var herbNo = $("#herbNo").val();
	var currentHerbDiagNo = $("#currentHerbDiagNo").val();
	if(currentHerbDiagNo == '' && herbNo != ''){
		$.ajax({
			type:'post',
			url:path+'/commom/checkHerbNo',
			data:{
				patientId:$("#iframe").contents().find("#patientId").val(),
				herbNo:herbNo
			},
			dataType:'json',
			success:function(data){
				if(data.code != 0){
					toastr.warning("该诊断序号已存在！");
					$("#herbNo").val("");
					$("#herbNo").focus();
				}
			}
		})
	}
	//序号为1,选中主要诊断。不是1把主要诊断禁用
	if(herbNo != ''){
		if(herbNo == 1){
			$("#herbType").val(1);
			$('#herbType option:eq(0)').prop('disabled',false);
		}else{
			$("#herbType").val(2);
			$('#herbType option:eq(0)').prop('disabled',true);
		}
	}
})
//保存中医诊断编码
function saveHerbDiag(){
	var currentHerbDiagNo = $("#currentHerbDiagNo").val();
	var herbNo = $("#herbNo").val();
	if(herbNo != ''){
		//是否修改该诊断序号
		var isUpdateOperNo;
		if(currentHerbDiagNo != ''){
			if(currentHerbDiagNo == herbNo){
				isUpdateOperNo = 0;
			}else{
				isUpdateOperNo = 1;
			}
		}
		$.ajax({
			type:'post',
			url:path+'/commom/saveHerbDiag',
			data:{
				currentHerbDiagNo:currentHerbDiagNo,
				isUpdateOperNo:isUpdateOperNo,
				patientId:$("#iframe").contents().find("#patientId").val(),
				herbNo:$("#herbNo").val(),
				herbCode:$("#herbCode").val(),
				herbName:$("#herbName").val(),
				herbType:$("#herbType").val(),
				herbThing:$("#herbThing").val(),
				operCode:$("#herbDiagOperCode").val(),
				operName:$("#herbDiagOperName").val(),
				operDate:$("#herbDiagOperDate").val(),
				formToken:$("#formToken3").val()
			},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					toastr.success("保存成功！");
					//加载模态框1
					loadDiag1();
				}else{
					toastr.error(data.msg);
				}
			}
		})
		setTimeout(function(){
			selectCurrentNode();
		},1000);
	}else{
		$("#herbNo").focus();
		toastr.warning("诊断序号不能为空！");
	}
}
//删除中医诊断编号
function deleteHerbDiag() {
    Common.confirm({
        title: "提示",
        message: "确实是否删除此条数据?",
        operate: function (reselt) {
            if(reselt){
                $.ajax({
                    type:'post',
                    url:path+"/commom/deleteCodeByPatientIdAndHerbNo",
                    data:{
                        herbNo:$("#currentHerbDiagNo").val(),
                        patientId:$("#iframe").contents().find("#patientId").val()
                    },
                    dataType:'json',
                    success:function(data){
                        if(data.code == 0){
                            toastr.success("删除成功！")
                            //加载模态框1
                            loadDiag1();
                        }else{
                            toastr.error("删除失败！");
                        }
                    }
                })
            }
        }
	})
}
/*********************************************模态框2*****************************************************/
	//当前时间
var currentDate = getNowFormatDate();
//加载收藏类别
function loadCollectType() {
	$.ajax({
		type:'get',
		url:path+'/collect/getCollectType',
		dataType:'json',
		async:false,
		success:function (data) {
			if(null != data && data != ''){
				$("#parentId").empty();
				var html = '';
				for (var i = 0; i < data.length; i++) {
					html += '<option value="'+data[i].id+'">'+data[i].collectTypeName+'</option>';
				}
				$("#parentId").append(html);
			}
		}
	})
}
//新增图片资料按钮方法
function addPic(){
    loadPicAssort();
    //清楚选中图片
    $(".up-section").remove();
}
//加载收藏对象
function loadCollect() {
	$.ajax({
		type:'get',
		url:path+'/collect/getCollectById',
		data:{patientId:$("#patientId").val()},
		dataType:'json',
		async:false,
		success:function (data) {
			$("#collectId").val('');
			$("#collectForm")[0].reset();
			if(null != data && data != ''){
				$("#collectId").val(data.id);
				$("#title").val(data.title);
				$("#collectTime").val(data.collectTime);
				$("#parentId").val(data.parentId);
				$("#content").val(data.content);
			}
		}
	})
}
//点击收藏按钮功能
function collect(){
	//加载收藏类别
	loadCollectType();
	//加载收藏对象
	loadCollect();
	setFormToken();
	//未收藏过给收藏时间赋值当前时间
	if($("#collectTime").val() == ''){
		$("#collectTime").val(currentDate);
	}
}
//添加收藏
function saveCollect(){
	var parentId = $("#parentId").val();
	if(parentId != '' && parentId != null){
		$.ajax({
			type:'post',
			url:path+"/collect/addCollectBlood",
			data:{
				id:$("#collectId").val(),
				title:$("#title").val(),
				collectTime:$("#collectTime").val(),
				parentId:$("#parentId").val(),
				content:$("#content").val(),
				admissId:$("#admissId").val(),
				inpatientNo:$("#inpatientNo").val(),
				admissTimes:$("#admissTimes").val(),
				index:$("#iframe").contents().find("#iframe1").contents().find("#pageNumber").val(),
				patientId:$("#iframe").contents().find("#patientId").val(),
				assortIds:$("#iframe").contents().find("#assortIds").val(),
				name:$("#name1").val()
			},
			dataType:'json',
			success:function(data){
				if(data.code == 0){
					toastr.success("收藏成功！")
					$('#myModal2').modal('hide')
				}else{
					toastr.error(data.msg);
				}
			}
		})
	}else{
		toastr.warning("收藏失败，收藏类别不能为空，如若没有为添加收藏类别请先到个人收藏页面添加类别！");
	}
}
//清空收藏表单
function clearCollect(){
	$("#title").val("");
	$("#parentId").val("");
	$("#content").val("");
}
//bootstap时间插件
$('.datepicker').datepicker({
	format: 'yyyy-mm-dd',
	autoclose: true
})
//获取当前时间
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = year + seperator1 + month + seperator1 + strDate;
	return currentdate;
}

//加载分段
function loadPicAssort(){
    $.ajax({
        type:'get',
        url:path+'/commom/getAssortList',
        dataType:'json',
        async:false,
        success:function (data) {
            if(data.code == 0){
                data = data.data;
                $("#assortId").empty();
                var html = '<option value="">请选择分类</option>';
                for (var i = 0; i < data.length; i++) {
                    html += '<option value="'+data[i].assortId+'">'+data[i].assortName+'</option>';
                }
                $("#assortId").append(html);
            }else{
                toastr.warning(data.msg);
            }
        }
    })
}
//保存图片
function save(){
	var formData = new FormData();
    var assortId = $("#assortId").val();
    if(assortId != ''){
        if(file1.length > 0){
            for (var i = 0; i < file1.length; i++) {
                formData.append('files', file1[i]);
            }
            formData.append('patientId',$("#patientId").val());
            formData.append('assortId', assortId);
            $.ajax({
                url:path+'/commom/updatePic',
                data:formData,
                type :  "post",
                processData: false,
                contentType: false,
                dataType:'json',
                success : function(data){
                    if(data.code == 0){
                        toastr.success("上传成功");
                    }else{
                        toastr.error(data.msg);
                    }
                }
            })
        }else{
            toastr.warning("请选择图片!")
        }
    }else{
        toastr.warning("请选择分类!")
    }
}
//监听关闭模态框刷新事件
$('#myModal3').on('hide.bs.modal', function () {
    window.location.reload();
});