/****************************************************************************
* 고객 상담차트 정보 상세 조회
****************************************************************************/
function fn_selectUserConsultingChart(){
	let formData = new FormData();
	formData.append("menuClass", menuClass);
	formData.append("muUserConsultingChartId", muUserConsultingChartId);
	formData.append("muUserId", muUserId);
	
	$.ajax({
		url: encodeURI('/webuserconsultingchart/selectUserConsultingChart.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_updateUserConsultingChart(){
	let content          = $("#content").val();
	
	if("Y"!=updateUseYn){
		modalEvent.warning("수정", "수정 권한이 없습니다.");
		return false;
	}
	
	if(true != fn_emptyCheck(muUserConsultingChartId)){
		modalEvent.warning("수정", "상담차트 정보가 없습니다.");	
		return;
	}
	
	if(true != fn_emptyCheck(content)){
		modalEvent.warning("수정", "상세 내용 정보가 없습니다.");	
		return;
	}

	modalEvent.info("수정", "상담차트 정보를 수정하시겠습니까?", function(){
		let formData = new FormData();
		formData.append("menuClass", menuClass);
		formData.append("muUserConsultingChartId", muUserConsultingChartId);
		formData.append("content", content);
		
		$.ajax({
			url: encodeURI('/webuserconsultingchart/updateUserConsultingChart.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_userConsultingChartOk();
					});
				}
				else{
					modalEvent.danger("수정 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("수정 오류", "수정 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	});
}
/****************************************************************************
 * 고객 상담차트 인쇄
 ****************************************************************************/
function fn_printUserConsultingChart(){
	if("Y"!=selectUseYn){
		modalEvent.warning("", "조회 권한이 없습니다.");
		return false;
	}

	let reqParam =  {"muUserConsultingChartId":muUserConsultingChartId};
	consultingSelectModal.popup(function(obj, reqParam) {
		fn_userConsultingChartOk();
	}, reqParam);
}

function fn_userConsultingChartOk(){
	let pagingParam = "?menuClass="+menuClass;
	pagingParam    += "&userConsultingChartSearchKeywordParam="+userConsultingChartSearchKeywordParam;
	pagingParam    += "&userConsultingChartSort="+userConsultingChartSort;
	pagingParam    += "&userConsultingChartDir="+userConsultingChartDir;
	pagingParam    += "&userConsultingChartStart="+userConsultingChartStart;
	pagingParam    += "&userConsultingChartLimit="+userConsultingChartLimit;
	pagingParam    += "&userConsultingChartTreatmentId="+userConsultingChartTreatmentId;
	pagingParam    += "&userConsultingChartTreatmentProcedureId="+userConsultingChartTreatmentProcedureId;
	pagingParam    += "&userConsultingChartReserveMemberId="+userConsultingChartReserveMemberId;
	pagingParam    += "&muUserId="+muUserId;
	
	fn_leftFormAction("/webuserconsultingchart/selectListUserConsultingChartIntro.do"+pagingParam);
}

function fn_userConsultingChartCancel(){
	let pagingParam = "?menuClass="+menuClass;
	pagingParam    += "&userConsultingChartSearchKeywordParam="+userConsultingChartSearchKeywordParam;
	pagingParam    += "&userConsultingChartSort="+userConsultingChartSort;
	pagingParam    += "&userConsultingChartDir="+userConsultingChartDir;
	pagingParam    += "&userConsultingChartStart="+userConsultingChartStart;
	pagingParam    += "&userConsultingChartLimit="+userConsultingChartLimit;
	pagingParam    += "&userConsultingChartTreatmentId="+userConsultingChartTreatmentId;
	pagingParam    += "&userConsultingChartTreatmentProcedureId="+userConsultingChartTreatmentProcedureId;
	pagingParam    += "&userConsultingChartReserveMemberId="+userConsultingChartReserveMemberId;
	pagingParam    += "&muUserId="+muUserId;
	
	fn_leftFormAction("/webuserconsultingchart/selectListUserConsultingChartIntro.do"+pagingParam);
}

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

/****************************************************************************
* 페이지 event
****************************************************************************/
function fn_pageEvent(){
	// 수정 버튼
	$("#btnUpdateUserConsultingChart").click(function () {
		fn_updateUserConsultingChart();
	});
	
	// 차트 인쇄 버튼
	$("#btnPrintUserConsultingChart").click(function () {
		fn_printUserConsultingChart();
	});
}

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