
/* ##############################################################
	설  명 : [Modal]직원 상세 팝업
	작성일 : 2023. 01. 19.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2023. 01. 19.	NTsoft 	 최초 생성
*/
let memberSelectModal = {
	callback : null,
	reqParam : null,
	dataList : null,
	/* 모달 초기화 작업 */
	init : function () {
		$('#memberSelectModal').remove();
		$('body').append( this.HtmlTemplate);
		//그리드 이벤트
		this.setEvent();
	},
	/* 그리드 이벤트 설정 */
	setEvent:function() {
		$('#memberSelectModal .btnCancle').on("click", function(){
			memberSelectModal.close();
		});
	},
	/* 데이터 선택 */
	setSelect:function(selectNumber) {
		let checkedData = dataList[selectNumber];
		if(dataList==null||checkedData==undefined){
			return ;
		}
		
		if( memberSelectModal.callback )  {
			memberSelectModal.callback(checkedData);
		}
		memberSelectModal.close();
	},
	// 상세 조회
	search:function(state) {
		let muMemberId = memberSelectModal.reqParam.muMemberId;
		
		if(true != fn_emptyCheck(muMemberId)){
			modalEvent.warning("조회", "직원 정보가 없습니다.");	
			return;
		}
		
		let formData = new FormData();
		formData.append("menuClass", menuClass);
		formData.append("muMemberId", muMemberId);

		$.ajax({
			url: encodeURI('/webmember/selectMember.do'),
			data: formData,
			dataType: "json",
			processData: false,
			contentType: false,
			type: 'POST',
			async: true,
			success: function(data){
				if('0'==data.msgCode){
					$("#memberSelectModal #modalLoginId").text(data.rows[0].loginId);
					$("#memberSelectModal #modalMemberName").text(data.rows[0].memberName);
					$("#memberSelectModal #modalPhoneNumber").text(fn_setFormatPhone(data.rows[0].phoneNumber));
					$("#memberSelectModal #modalEmail").text(data.rows[0].email);
					$("#memberSelectModal #modalType").text(data.rows[0].typeName);
					$("#memberSelectModal #modalGroupName").text(data.rows[0].groupName);
					$("#memberSelectModal #modalDutyName").text(data.rows[0].dutyName);
					$("#memberSelectModal #modalAuthName").text(data.rows[0].authName);
				}
				else{
					modalEvent.danger("조회 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	},
	/*
	 * 팝업
	 * callback : 콜백함수, reqParam: 팝업파라미터
	 */
	popup:function(callback, reqParam) {
		// 초기화 후 열기
		memberSelectModal.init();
		
		//콜백함수 지정.
		memberSelectModal.callback = callback;
		memberSelectModal.reqParam = reqParam;
		memberSelectModal.dataList = null;
		
		setTimeout(function(){
			$('#memberSelectModal').modal('show')
		}, 200);
		
		memberSelectModal.search();
	},
	/*
	 * 팝업 닫기
	 */
	close:function() {
		$('#memberSelectModal').modal('hide');

		setTimeout(function(){
			$('#memberSelectModal').remove();
		},500);
	},
	HtmlTemplate : `
	<div id="memberSelectModal" class="modal employee_info_modal fade" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<p class="title">직원 정보</p>
				</div>

				<div class="modal-body">
					<p class="title first">직원 정보</p>

					<div class="form_box">
						<div class="input_box">
							<label>아이디</label>
							<div class="input_div" id="modalLoginId"></div>
						</div>

						<div class="input_box">
							<label>이름</label>
							<div class="input_div" id="modalMemberName"></div>
						</div>

						<div class="input_box">
							<label>연락처</label>
							<div class="input_div" id="modalPhoneNumber"></div>
						</div>

						<div class="input_box">
							<label>이메일</label>
							<div class="input_div" id="modalEmail"></div>
						</div>

						<div class="input_box">
							<label>유형</label>
							<div class="input_div" id="modalType"></div>
						</div>
					</div>

					<p class="title">조직 그룹 및 권한</p>

					<div class="form_box">
						<div class="input_box">
							<label>조직</label>
							<div class="input_div" id="modalGroupName"></div>
						</div>

						<div class="input_box">
							<label>직무</label>
							<div class="input_div" id="modalDutyName"></div>
						</div>
						<div class="input_box">
							<label>권한</label>
							<div class="input_div" id="modalAuthName"></div>
						</div>
					</div>
				</div>

				<div class="modal-footer">
					<div class="btn_box">
						<button type="button" class="cancel_btn btnCancle">취소</button>
						<!-- <button type="button" class="disabled_btn">비활성화</button> -->
					</div>
				</div>
			</div>
		</div>
	</div>
    `
};