//初始化函数
var effectOption = '';
$(function(){
	//bootstap时间插件
	$('.date').datepicker({
		language: "zh-CN",
		format: "yyyy-mm-dd",
		autoclose: true//选中之后自动隐藏日期选择框
	})
	//加载放疗方式
	getRadiotherapyType();
	//加载放疗程式
	getRadiotherapyProgram();
	//加载放疗装置
	getRadiotherapyDevice();
	//加载化疗方式
	getChemotherapyType();
	//加载化疗方法
	getChemotherapyMethod();
    //加载化疗信息
    loadChemotherapyInfo();
	setTimeout(function(){
        //加载肿瘤基本信息
        loadTumourInfo();
    },500)
	$.ajax({
		type:'get',
		url:path+'/tumour/getCurativeEffects',
		dataType:'json',
		async:false,
		success:function(d){
			if(null != d && d != ''){
				effectOption = d;
			}
		}
	})
	/*$(".icdCodes").select2();
	$(".operateCode").select2();
	$(".operateName").select2();
	$(".cutHealGrades").select2();
	$(".anaesthesias").select2();*/
	/*$(".operateCode").selectpicker({"height":20});
	$(".operateCode").selectpicker('refresh');*/
	/*$.ajaxSetup({
		async : false
	});
	//加载手术编号名称集合
	loadCM3();*/
})
/*function loadCM3(){
	$.ajax({
		type:'get',
		url:path+'/commom/loadCM3',
		dataType:'json',
		success:function (data) {
			var html = '<option></option>';
			var html1 = '<option></option>';
			if(null != data){
				for (var i = 0; i < data.length; i++) {
					html += '<option value="'+data[i].code+'">'+data[i].code+'</option>';
					html1 += '<option value="'+data[i].name+'">'+data[i].name+'</option>';
				}
			}
			$(".operateCode").append(html);
			$(".operateName").append(html1);
			$(".operateCode").selectpicker('refresh');
			$(".operateName").selectpicker('refresh');
		}
	})
}*/
toastr.options.positionClass = 'toast-top-right';
//判断邻节点是否选中
function checkBoxCheck(checkBox){
	var checkbox = $(checkBox);
	var siblings = checkbox.parent().parent().children().find('input[type="checkbox"]');
	var checkedCount = 0;
	siblings.each(function() {
		if ($(this).is(":checked")) {
			checkedCount++;
		}
	})
	//超过一个提示且取消选中
	if(checkedCount > 1){
		checkbox.prop("checked",false);
		toastr.warning("只能选择一个!")
	}
}
var diagsLength = 1;
if($("#diagsLength").val() != 0){
	diagsLength = $("#diagsLength").val();
}
//表格1添加行
function addtr(){
	diagsLength++;
	var table = $("#table1");
	var tr= $('<tr>'
		+'<input type="hidden" name="diagNo">'
		+'<input type="hidden" name="trIndex" value="'+diagsLength+'">'
		+'<td class="notRigheBorder"><span style="font-weight: bold">其他诊断:</span></td>'
		+'<td><input type="text" id="diag_name'+diagsLength+'" onkeyup="getDiagNameContents(\'diag_name'+diagsLength+'\')" onfocus="getDiagNameContents(\'diag_name'+diagsLength+'\')" onblur="clearContent(\'diag_name'+diagsLength+'\')" maxlength="100" name="diagName">'
		+'<div id="diag_name'+diagsLength+'Div"><table id="diag_name'+diagsLength+'Content_table" bgcolor="#FFFAFA" border="0" cellspacing="0" cellpadding="0">'
		+'<tbody id="diag_name'+diagsLength+'Content"> </tbody></table></div></td>'
		+'<td>'
		+'<input type="text" id="diag_code'+diagsLength+'" onkeyup="getDiagCodeContents(\'diag_code'+diagsLength+'\')" onfocus="getDiagCodeContents(\'diag_code'+diagsLength+'\')" onblur="clearContent(\'diag_code'+diagsLength+'\')" maxlength="16" name="diagCode">'
		+'<div id="diag_code'+diagsLength+'Div"><table id="diag_code'+diagsLength+'Content_table" bgcolor="#FFFAFA" border="0" cellspacing="0" cellpadding="0">'
		+'<tbody id="diag_code'+diagsLength+'Content"> </tbody></table></div></td>'
		+'<td><input type="checkbox" onclick="checkBoxCheck(this)" value="1" name="checkbox'+diagsLength+'"></td>'
		+'<td><input type="checkbox" onclick="checkBoxCheck(this)" value="2" name="checkbox'+diagsLength+'"></td>'
		+'<td><input type="checkbox" onclick="checkBoxCheck(this)" value="3" name="checkbox'+diagsLength+'"></td>'
		+'<td><input type="checkbox" onclick="checkBoxCheck(this)" value="4" name="checkbox'+diagsLength+'"></td>'
		+'<td align="center" class="pointerTd" onclick="deletetr(this)"><span class="glyphicon glyphicon-remove"></span></td>'
		+'</tr>');
	table.append(tr);
}

var opersLength = 1;
if($("#opersLength").val() != 0){
	opersLength = $("#opersLength").val();
}
//表格2添加行
function addtr1(){
	//手术级别下拉框值
	var operateClasses = '';
	$("#operateClasses option").each(function () {
		var val = $(this).val();
		var text = $(this).text();
		operateClasses += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';
	})
	//切口愈合下拉框值
	var cut = '';
	$("#cuts option").each(function () {
		var val = $(this).val();
		var text = $(this).text();
		cut += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';
	})
	//择期手术下拉框值
	var chossurg = '';
	$("#chossurgs option").each(function () {
		var val = $(this).val();
		var text = $(this).text();
		chossurg += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';
	})
	//麻醉方式下拉框值
	var anaesthesiaType = '';
	$("#anaesthesiaTypes option").each(function () {
		var val = $(this).val();
		var text = $(this).text();
		anaesthesiaType += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';
	})

	var table = $("#table2");
	var tr= $('<tr>'
		+'<input type="hidden" name="operNos">'
		+'<input type="hidden" name="operIndex" value="'+opersLength+'">'
		+'<td><input type="text" class="date" name="operDate"></td>'
		+'<td><input type="text"  id="operate_code" onkeyup="getOperateCodeContents(\'operate_code\')" onfocus="getOperateCodeContents(\'operate_code\')" onblur="clearContent(\'operate_code\')" maxlength="16" name="operCode">'
		+'<div id="operate_codeDiv">'
		+'<table id="operate_codeContent_table" bgcolor="#FFFAFA" border="0" cellspacing="0" cellpadding="0">'
		+'<tbody id="operate_codeContent"> </tbody>'
		+'</table></div></td>'
		+'<td><input type="text"  id="operate_name" onkeyup="getOperateNameContents(\'operate_name\')" onfocus="getOperateNameContents(\'operate_name\')" onblur="clearContent(\'operate_name\')" maxlength="100" name="operName">'
		+'<div id="operate_nameDiv">'
		+'<table id="operate_nameContent_table" bgcolor="#FFFAFA" border="0" cellspacing="0" cellpadding="0">'
		+'<tbody id="operate_nameContent"> </tbody></table></div></td>'
		+'<td><select class="operateClasses form-control input-sm" name="operateClasses">'
		+operateClasses
		+'</select></td>'
		+'<td><input type="text" name="operators" maxlength="16"></td>'
		+'<td><input type="text" name="assistant1s" maxlength="16"></td>'
		+'<td><input type="text" name="assistant2s" maxlength="16"></td>'
		+'<td><select class="cutHealGrades form-control input-sm" name="cuts">'
		+cut
		+'</select></td>'
		+'<td><select class="cutHealGrades form-control input-sm" name="chossurgs">'
		+ chossurg
		+'</select></td>'
		+'<td><select class="anaesthesias form-control input-sm" name="anaesthesiaTypes">'
		+ anaesthesiaType
		+'</select></td>'
		+'<td><input type="text" name="anaesthesiaNames" maxlength="16"></td>'
		+'<td align="center" class="pointerTd" onclick="deletetr(this)"><span class="glyphicon glyphicon-remove"></span></td>'
		+'</tr>');
	table.append(tr);
	$('.date').datepicker({
		language: "zh-CN",
		format: "yyyy-mm-dd",
		autoclose: true//选中之后自动隐藏日期选择框
	})
}
//删除表格
function deletetr(tdobject){
	var td=$(tdobject);
	td.parents("tr").remove();
}

//保存诊断编码
function saveDiag(){
	//判断诊断名称不为空
	var diagNameFlag = true;
	//拼接诊断名称
	var diagNames = '';
	$("input[name='diagName']").each(function(){
		var diagName = $(this).val();
		if(diagName == ''){
			diagNameFlag = false;
			return ;
		}else{
			diagNames += diagName + ",";
		}
	})
	if(!diagNameFlag){
		toastr.warning("诊断名称不能为空!");
		return ;
	}

	//判断诊断名称不为空
	var diagCodeFlag = true;
	//拼接诊断名称
	var diagCodes = '';
	$("input[name='diagCode']").each(function(){
		var diagCode = $(this).val();
		if(diagCode == ''){
			diagCodeFlag = false;
			return ;
		}else{
			diagCodes += diagCode + ",";
		}
	})
	if(!diagCodeFlag){
		toastr.warning("诊断编号不能为空!");
		return ;
	}

	//拼接diagNos
	var diagNos = '';
	$("input[name='diagNo']").each(function(){
		var diagNo = $(this).val();
		if(diagNo == ''){
			diagNo = 'null';
		}
		diagNos += diagNo + ",";
	})

	//拼接入院行情inhospstats
	var inhospstats = '';
	$("input[name='trIndex']").each(function(){
		var trIndex = $(this).val();
		var checkboxIndex = 'checkbox' + trIndex;
		var val = 'null';
		$("input[name="+checkboxIndex+"]:checked").each(function(i){
			val = $(this).val();
		});
		inhospstats += val + ",";
	})
	$.ajax({
		type:'post',
		url:path+'/commom/addDiagCode',
		data:{patientId:$("#patientId").val(),diagNos:diagNos,diagNames:diagNames,diagCodes:diagCodes,inhospstats:inhospstats},
		dataType:'json',
		success:function(data){
			if(data.code == 0){
				toastr.success("保存成功");
				setTimeout(function () {
					window.location.reload();
				},500)
			}else{
				toastr.error(data.msg);
			}
		}
	})
}


//保存手术编码
function saveOper(){
	//判断手术日期不为空
	var operDateFlag = true;
	var operDates = '';
	$("input[name='operDate']").each(function(){
		var operDate = $(this).val();
		if(operDate == ''){
			operDateFlag = false;
			return ;
		}else{
			operDates += operDate + ',';
		}
	})
	if(!operDateFlag){
		toastr.warning("手术时间不能为空!");
		return ;
	}


	//判断手术编码不为空
	var operCodeFlag = true;
	//拼接手术编码
	var operCodes = '';
	$("input[name='operCode']").each(function(){
		var operCode = $(this).val();
		if(operCode == ''){
			operCodeFlag = false;
			return ;
		}else{
			operCodes += operCode + ",";
		}
	})
	if(!operCodeFlag){
		toastr.warning("手术编码不能为空!");
		return ;
	}

	//判断手术名称不为空
	var operNameFlag = true;
	//拼接手术名称
	var operNames = '';
	$("input[name='operName']").each(function(){
		var operName = $(this).val();
		if(operName == ''){
			operNameFlag = false;
			return ;
		}else{
			operNames += operName + ",";
		}
	})
	if(!operNameFlag){
		toastr.warning("手术名称不能为空!");
		return ;
	}

	//拼接operNos
	var operNos = '';
	$("input[name='operNos']").each(function(){
		var operNo = $(this).val();
		if(operNo == ''){
			operNo = 'null';
		}
		operNos += operNo + ",";
	})

	//拼接手术级别
	var operateClasses = '';
	$("select[name='operateClasses'] option:selected").each(function(){
		if($(this).val() == ''){
			operateClasses += "null,";
		}else{
			operateClasses += $(this).val() + ',';
		}
	})
	//拼接术者
	var operators = '';
	$("input[name='operators']").each(function(){
		if($(this).val() == ''){
			operators += "null,";
		}else{
			operators += $(this).val() + ',';
		}
	})

	//拼接I助
	var assistant1s = '';
	$("input[name='assistant1s']").each(function(){
		if($(this).val() == ''){
			assistant1s += "null,";
		}else{
			assistant1s += $(this).val() + ',';
		}
	})

	//拼接II助
	var assistant2s = '';
	$("input[name='assistant2s']").each(function(){
		if($(this).val() == ''){
			assistant2s += "null,";
		}else{
			assistant2s += $(this).val() + ',';
		}
	})

	//拼接切口/愈合
	var cuts = '';
	$("select[name='cuts'] option:selected").each(function(){
		if($(this).val() == ''){
			cuts += "null,";
		}else{
			cuts += $(this).val() + ',';
		}
	})

	//拼接是否择期手术
	var chossurgs = '';
	$("select[name='chossurgs'] option:selected").each(function(){
		if($(this).val() == ''){
			chossurgs += "null,";
		}else{
			chossurgs += $(this).val() + ',';
		}
	})

	//拼接麻醉方式
	var anaesthesiaTypes = '';
	$("select[name='anaesthesiaTypes'] option:selected").each(function(){
		if($(this).val() == ''){
			anaesthesiaTypes += "null,";
		}else{
			anaesthesiaTypes += $(this).val() + ',';
		}
	})

	//拼接麻醉医师
	var anaesthesiaNames = '';
	$("input[name='anaesthesiaNames']").each(function(){
		if($(this).val() == ''){
			anaesthesiaNames += "null,";
		}else{
			anaesthesiaNames += $(this).val() + ',';
		}
	})
	$.ajax({
		type:'post',
		url:path+'/commom/addOperCode',
		data:{patientId:$("#patientId").val(),operNos:operNos,operDates:operDates,operCodes:operCodes,operNames:operNames,operateClasses:operateClasses,operators:operators,assistant1s:assistant1s,assistant2s:assistant2s,cuts:cuts,chossurgs:chossurgs,anaesthesiaTypes:anaesthesiaTypes,anaesthesiaNames:anaesthesiaNames},
		dataType:'json',
		success:function(data){
			if(data.code == 0){
				toastr.success("保存成功");
				setTimeout(function () {
					window.location.reload();
				},500)
			}else{
				toastr.error(data.msg);
			}
		}
	})
}


/***********************************************肿瘤操作*************************************************/
$("#stagesType").change(function(){
	var stagesType = $("#stagesType").val();
    $("#block").empty();
    var difSpan = '';
    if(stagesType == 'T'){
        difSpan='<span class="left">1.原发灶(首次、复次)剂量：</span>';
    }else if(stagesType == 'N'){
        difSpan='<span class="left">2.区域淋巴结(首次、复次)剂量：</span>';
    }else if(stagesType == 'M'){
        difSpan='<span class="left">3.转移灶剂量：</span>';
    }
    var html = '<td colspan="6" id="radiotherapy1">\n' +
        difSpan+
        '                    <input class="left input1" maxlength="16" name="primaryTumorDose" id="primaryTumorDose"/>\n' +
        '                    <span class="left">CY/</span>\n' +
        '                    <input class="left input1" type="number" min="1" maxlength="16" name="primaryTumorTimes" id="primaryTumorTimes"/>\n' +
        '                    <span class="left">次/</span>\n' +
        '                    <input class="left input1" maxlength="16" name="primaryTumorDay" id="primaryTumorDay" />\n' +
        '                    <span class="left">天；起止日期</span>\n' +
        '                    <input class="left date input" name="primaryTumorStarttime" id="primaryTumorStarttime" />\n' +
        '                    <span class="left">至</span>\n' +
        '                    <input class="left date input" name="primaryTumorEndtime" id="primaryTumorEndtime" />\n' +
        '                </td>';
    $("#block").append(html);
    //加载日期控件
    loadDate();
})
//加载放疗方式
function getRadiotherapyType() {
	getAjaxAppendSelect(path+"/tumour/getRadiotherapyType","radiotherapyType");
}
//加载放疗程式
function getRadiotherapyProgram() {
	getAjaxAppendSelect(path+"/tumour/getRadiotherapyProgram","radiotherapyProgram");
}
//加载放疗装置
function getRadiotherapyDevice() {
	getAjaxAppendSelect(path+"/tumour/getRadiotherapyDevice","radiotherapyDevice");
}
//加载化疗方式
function getChemotherapyType() {
	getAjaxAppendSelect(path+"/tumour/getChemotherapyType","chemotherapyType");
}
//加载化疗方法
function getChemotherapyMethod() {
	getAjaxAppendSelect(path+"/tumour/getChemotherapyMethod","chemotherapyMethod");
}

//ajax加载选择框公共方法
function getAjaxAppendSelect(url,id) {
	$.getJSON(url,function (data) {
		if(null != data){
			var html = '<option value="">请选择</option>';
			for (var i = 0; i < data.length; i++) {
				if(data[i].name != ''){
					html += '<option value="'+data[i].name+'">'+data[i].name+'</option>';
				}
			}
			$("#"+id).append(html);
		}
	})
}

//加载肿瘤基本信息
function loadTumourInfo(){
    $.ajax({
        type:'get',
        url:path+'/tumour/loadTumourInfo',
        async:true,
        data:{patientId:$("#patientId").val()},
        dataType:'json',
        success:function(result){
            if(result.code == 0){
                var data = result.data;
                $("#stagesType").val(data.tumorStagingType);
                $("#radiotherapyType").val(data.radiotherapyType);
                $("#radiotherapyProgram").val(data.radiotherapyProgram);
                $("#radiotherapyDevice").val(data.radiotherapyDevice);
				var primaryTumorDose = '';
                if(null != data.primaryTumorDose){
					primaryTumorDose = data.primaryTumorDose;
				}
                var primaryTumorTimes = '';
                if(null != data.primaryTumorTimes){
					primaryTumorTimes = data.primaryTumorTimes;
				}
                var primaryTumorDay = '';
                if(null != data.primaryTumorDay){
					primaryTumorDay = data.primaryTumorDay;
				}
                var primaryTumorStarttime = '';
                if(null != data.primaryTumorStarttime){
					primaryTumorStarttime = data.primaryTumorStarttime;
				}
                var primaryTumorEndtime = '';
                if(null != data.primaryTumorEndtime){
					primaryTumorEndtime = data.primaryTumorEndtime;
				}
                $("#chemotherapyType").val(data.chemotherapyType);
                $("#chemotherapyMethod").val(data.chemotherapyMethod);
                //动态加载放疗服药信息
                var stagingType = data.tumorStagingType;
                $("#block").empty();
                var difSpan = '';
                if(stagingType == 'T'){
                    difSpan='<span class="left">1.原发灶(首次、复次)剂量：</span>';
                }else if(stagingType == 'N'){
                    difSpan='<span class="left">2.区域淋巴结(首次、复次)剂量：</span>';
                }else if(stagingType == 'M'){
                    difSpan='<span class="left">3.转移灶剂量：</span>';
                }
                var html = '<td colspan="6" id="radiotherapy1">\n' +
                    difSpan+
                    '                    <input class="left input1" maxlength="16" name="primaryTumorDose" id="primaryTumorDose" value="'+primaryTumorDose+'"/>\n' +
                    '                    <span class="left">CY/</span>\n' +
                    '                    <input class="left input1" type="number" min="1" maxlength="16" name="primaryTumorTimes" id="primaryTumorTimes" value="'+primaryTumorTimes+'"/>\n' +
                    '                    <span class="left">次/</span>\n' +
                    '                    <input class="left input1" maxlength="16" name="primaryTumorDay" id="primaryTumorDay" value="'+primaryTumorDay+'"/>\n' +
                    '                    <span class="left">天；起止日期</span>\n' +
                    '                    <input class="left date input" name="primaryTumorStarttime" id="primaryTumorStarttime" value="'+primaryTumorStarttime+'"/>\n' +
                    '                    <span class="left">至</span>\n' +
                    '                    <input class="left date input" name="primaryTumorEndtime" id="primaryTumorEndtime" value="'+primaryTumorEndtime+'"/>\n' +
                    '                </td>';
                $("#block").append(html);
                //加载日期控件
                loadDate();
            }
        }
    })
}
//加载日期
function loadDate(){
    $('.date').datepicker({
        language: "zh-CN",
        format: "yyyy-mm-dd",
        autoclose: true//选中之后自动隐藏日期选择框
    })
}
//加载化疗信息
function loadChemotherapyInfo(){
    $.ajax({
        type: 'get',
        url: path + '/tumour/loadChemotherapyInfo',
        async: true,
        data: {patientId: $("#patientId").val()},
        dataType: 'json',
        success: function (result) {
            var html = '';
            var difTd = '<td align="center" class="pointerTd" onclick="deletetr(this)"><span class="glyphicon glyphicon-remove"></span></td>';
			//获取疗效字典
            if (result.code == 0) {
                var data = result.data;
                for (var i = 0; i < data.length; i++) {
					var curativeEffect = '<option value="">请选择</option>';
                    var startTime = '';
                    var endTime = '';
                    var drugNameAndDose = '';
                    var treatmentCourse = '';
                    if(null != data[i].startTime){
                        startTime = data[i].startTime;
                    }
                    if(null != data[i].endTime){
                        endTime = data[i].endTime;
                    }
                    if(null != data[i].drugNameAndDose){
                        drugNameAndDose = data[i].drugNameAndDose;
                    }
                    if(null != data[i].treatmentCourse){
                        treatmentCourse = data[i].treatmentCourse;
                    }
					for (var j = 0; j < effectOption.length; j++) {
						if(effectOption[j].code == data[i].curativeEffect){
							curativeEffect += '<option value="'+effectOption[j].code+'" selected>'+effectOption[j].name+'</option>';
						}else{
							curativeEffect += '<option value="'+effectOption[j].code+'">'+effectOption[j].name+'</option>';
						}
					}
                    html += '<tr>\n' +
                        '                <td><input class="date" name="startTime" value="'+startTime+'"/></td>\n' +
                        '                <td><input class="date" name="endTime" value="'+endTime+'"/></td>\n' +
                        '                <td><input maxlength="16" name="drugNameAndDose" value="'+drugNameAndDose+'"/></td>\n' +
                        '                <td><input maxlength="50" name="treatmentCourse" value="'+treatmentCourse+'"/></td>\n' +
                        '                <td><select class="curativeEffect form-control input-sm" name="curativeEffect">'
						+curativeEffect+
						'</select></td>\n' +
                        difTd +
                        '            </tr>';
                }
            }else{
                if(result.msg == '没有此权限，请联系超管！'){
					var curativeEffect = '<option value="">请选择</option>';
					for (var i = 0; i < effectOption.length; i++) {
						curativeEffect += '<option value="'+effectOption[i].code+'">'+effectOption[i].name+'</option>';
					}
                    html='<tr>\n' +
                        '<td><input class="date" name="startTime"/></td>\n' +
                        '<td><input class="date" name="endTime"/></td>\n' +
                        '<td><input maxlength="16" name="drugNameAndDose"/></td>\n' +
                        '<td><input maxlength="50" name="treatmentCourse"/></td>\n' +
                        '<td><select class="curativeEffect form-control input-sm" name="curativeEffect">'
						+curativeEffect+
						'</select></td>\n' +
                        +difTd+
                        '</tr>';
                }else{
                    toastr.warning(result.msg);
                    return ;
                }
            }
            $("#table3").append(html);
            //加载日期控件
            loadDate();
        },
    })
}

//保存肿瘤信息
function saveTumour(){
	var startTimes = '';
	$("input[name='startTime']").each(function(){
		if($(this).val() != ''){
			startTimes += $(this).val() + ',';
		}else{
			startTimes += 'null,';
		}
	})
	$("#startTimes").val(startTimes);

	var endTimes = '';
	$("input[name='endTime']").each(function(){
		if($(this).val() != ''){
			endTimes += $(this).val() + ',';
		}else{
			endTimes += 'null,';
		}
	})
	$("#endTimes").val(endTimes);

	var drugNameAndDoses = '';
	$("input[name='drugNameAndDose']").each(function(){
		if($(this).val() != ''){
			drugNameAndDoses += $(this).val() + ',';
		}else{
			drugNameAndDoses += 'null,';
		}
	})
	$("#drugNameAndDoses").val(drugNameAndDoses);

	var treatmentCourses = '';
	$("input[name='treatmentCourse']").each(function(){
		if($(this).val() != ''){
			treatmentCourses += $(this).val() + ',';
		}else{
			treatmentCourses += 'null,';
		}
	})
	$("#treatmentCourses").val(treatmentCourses);

	var curativeEffects = '';
	$("select[name='curativeEffect'] option:selected").each(function(){
		if($(this).val() != ''){
			curativeEffects += $(this).val() + ',';
		}else{
			curativeEffects += 'null,';
		}
	})
	$("#curativeEffects").val(curativeEffects);

	$.ajax({
		type:'post',
		url:path+'/tumour/saveTumour',
		data:$("#form3").serialize(),
		dataType:'json',
		success:function(data){
			if(data.code == 0){
				toastr.success("保存成功");
				setTimeout(function () {
					window.location.reload();
				},500)
			}else{
				toastr.error(data.msg);
			}
		}
	})
}

//表格3添加行
function addtr2(){
	var curativeEffect = '<option value="">请选择</option>';
	for (var i = 0; i < effectOption.length; i++) {
		curativeEffect += '<option value="'+effectOption[i].code+'">'+effectOption[i].name+'</option>';
	}
	var table = $("#table3");
	var tr= $('<tr>'
		  +'<td><input class="date" name="startTime"/></td>'
		  +'<td><input class="date" name="endTime"/></td>'
		  +'<td><input maxlength="16" name="drugNameAndDose"/></td>'
		  +'<td><input maxlength="50" name="treatmentCourse"/></td>'
		  +'<td><select class="curativeEffect form-control input-sm" name="curativeEffect">'
		  +curativeEffect+
			'</select></td>'
		  +'<td align="center" class="pointerTd" onclick="deletetr(this)"><span class="glyphicon glyphicon-remove"></span></td>'
		  +'</tr>');
	table.append(tr);
    //加载日期控件
    loadDate();
}

//上报省厅操作
function saveProvincial(){
	Common.confirm({
		title: "提示",
		message: "是否已全部保存?建议全部保存后再点击提交省厅",
		operate: function (reselt) {
			if (reselt) {
				$("#loading").css("background","url("+path+"/static/img/load.gif) no-repeat 10px 50%");
				$('#myModal').modal('show');
				$.ajax({
					type:'post',
					url:path+'/his/saveProvincial',
					data:{patientId:$("#patientId").val()},
					dataType:'json',
					success:function (data) {
						if(data.code == 0){
							$('#myModal').modal('hide');
							toastr.success("提交成功!");
						}
					}
				})
			}
		}
	})
}