/****************************************************************************
* 고객 시술차트 정보 상세 조회
****************************************************************************/
function fn_selectUserMedicalChart(){
	let formData = new FormData();
	formData.append("menuClass", menuClass);
	formData.append("muUserMedicalChartId", muUserMedicalChartId);
	formData.append("muUserId", muUserId);
	
	$.ajax({
		url: encodeURI('/webusermedicalchart/selectUserMedicalChart.do'),
		data: formData,
		dataType: "json",
		processData: false,
		contentType: false,
		type: 'POST',
		async: true,
		success: function(data){
			if('0'==data.msgCode){
				$("#chartNumber").text(data.rows[0].chartNumber);
				$("#userName").text(data.rows[0].userName);
				$("#userBirthday").text(data.rows[0].birthday);
				$("#userGender").text(data.rows[0].gender);
				$("#userNationality").text(data.rows[0].nationality);
				$("#userPhoneNumber").text(data.rows[0].phoneNumber);
				$("#userEtc").val(data.rows[0].etc);
				$("#writeDate").text(data.rows[0].writeDate);
				$("#writeMemberName").text(data.rows[0].writeMemberName);
				$("#treatmentName").val(data.rows[0].treatmentName);
				$("#treatmentProcedureName").val(data.rows[0].treatmentProcedureName);
				$("#reserveMemberName").val(data.rows[0].reserveMemberName);
				$("#reserveDateTime").val(data.rows[0].reserveDate+', '+data.rows[0].reserveTime);
				$("#content").val(data.rows[0].content);
			}
			else{
				modalEvent.danger("조회 오류", data.msgDesc);
			}
		},
		error : function(xhr, status, error) {
			modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
		},
		beforeSend:function(){
			
		},
		complete:function(){
			
		}
	});
}
/****************************************************************************
 * 고객 시술차트 인쇄
 ****************************************************************************/
function fn_printUserMedicalChart(){
	if("Y"!=selectUseYn){
		modalEvent.warning("", "조회 권한이 없습니다.");
		return false;
	}

	let reqParam =  {"muUserMedicalChartId":muUserMedicalChartId};
	medicalSelectModal.popup(function(obj, reqParam) {
		fn_userMedicalChartOk();
	}, reqParam);
}
/****************************************************************************
* 고객 시술차트 수정
****************************************************************************/
function fn_updateUserMedicalChart(){
	let content          = $("#content").val();
	
	if("Y"!=updateUseYn){
		modalEvent.warning("수정", "수정 권한이 없습니다.");
		return false;
	}
	
	if(true != fn_emptyCheck(muUserMedicalChartId)){
		modalEvent.warning("수정", "시술차트 정보가 없습니다.");	
		return;
	}
	
	if(true != fn_emptyCheck(content)){
		modalEvent.warning("수정", "상세 내용 정보가 없습니다.");	
		return;
	}

	modalEvent.info("수정", "시술차트 정보를 수정하시겠습니까?", function(){
		let formData = new FormData();
		formData.append("menuClass", menuClass);
		formData.append("muUserMedicalChartId", muUserMedicalChartId);
		formData.append("content", content);
		
		$.ajax({
			url: encodeURI('/webusermedicalchart/updateUserMedicalChart.do'),
			data: formData,
			dataType: "json",
			processData: false,
			contentType: false,
			type: 'POST',
			async: true,
			success: function(data){
				if('0'==data.msgCode){
					modalEvent.success("수정 성공", data.msgDesc, function(){
						fn_userMedicalChartOk();
					});
				}
				else{
					modalEvent.danger("수정 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("수정 오류", "수정 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	});
}

function fn_userMedicalChartOk(){
	let pagingParam = "?menuClass="+menuClass;
	pagingParam    += "&userMedicalChartSearchKeywordParam="+userMedicalChartSearchKeywordParam;
	pagingParam    += "&userMedicalChartSort="+userMedicalChartSort;
	pagingParam    += "&userMedicalChartDir="+userMedicalChartDir;
	pagingParam    += "&userMedicalChartStart="+userMedicalChartStart;
	pagingParam    += "&userMedicalChartLimit="+userMedicalChartLimit;
	pagingParam    += "&userMedicalChartTreatmentId="+userMedicalChartTreatmentId;
	pagingParam    += "&userMedicalChartTreatmentProcedureId="+userMedicalChartTreatmentProcedureId;
	pagingParam    += "&userMedicalChartReserveMemberId="+userMedicalChartReserveMemberId;
	pagingParam    += "&muUserId="+muUserId;
	
	fn_leftFormAction("/webusermedicalchart/selectListUserMedicalChartIntro.do"+pagingParam);
}

function fn_userMedicalChartCancel(){
	let pagingParam = "?menuClass="+menuClass;
	pagingParam    += "&userMedicalChartSearchKeywordParam="+userMedicalChartSearchKeywordParam;
	pagingParam    += "&userMedicalChartSort="+userMedicalChartSort;
	pagingParam    += "&userMedicalChartDir="+userMedicalChartDir;
	pagingParam    += "&userMedicalChartStart="+userMedicalChartStart;
	pagingParam    += "&userMedicalChartLimit="+userMedicalChartLimit;
	pagingParam    += "&userMedicalChartTreatmentId="+userMedicalChartTreatmentId;
	pagingParam    += "&userMedicalChartTreatmentProcedureId="+userMedicalChartTreatmentProcedureId;
	pagingParam    += "&userMedicalChartReserveMemberId="+userMedicalChartReserveMemberId;
	pagingParam    += "&muUserId="+muUserId;
	
	fn_leftFormAction("/webusermedicalchart/selectListUserMedicalChartIntro.do"+pagingParam);
}

/****************************************************************************
* 페이지 init
****************************************************************************/
function fn_pageInit(){
	fn_selectUserMedicalChart();
}

/****************************************************************************
* 페이지 event
****************************************************************************/
function fn_pageEvent(){
	// 수정 버튼
	$("#btnUpdateUserMedicalChart").click(function () {
		fn_updateUserMedicalChart();
	});
	
	// 차트 인쇄 버튼
	$("#btnPrintUserMedicalChart").click(function () {
		fn_printUserMedicalChart();
	});
}

$(function(){
	// 페이지 init
	fn_pageInit();
	
	// 페이지 event
	fn_pageEvent();
});