
/* ##############################################################
	설  명 : [Modal] 접수 대기 상세 팝업
	작성일 : 2024. 10. 02.
	작성자 : NTsoft
	수정일 	        수정자 	 수정내용
	-------         -------- ---------------------------
	2024. 10. 02.	NTsoft 	 최초 생성
*/
let selectReservePendingModal = {
    callback : null,
    reqParam : null,
    dataList : null,
    /* 모달 초기화 작업 */
    init : function () {
        $('#selectReservePendingModal').remove();
        $('body').append( this.HtmlTemplate);
        //그리드 이벤트
        this.setEvent();

    },
    /* 그리드 이벤트 설정 */
    setEvent:function() {
        $('#selectReservePendingModal .btnCancle').on("click", function(){
            selectReservePendingModal.close();
        });

        $('#selectReservePendingModal .btnSave').on("click", function(){
            selectReservePendingModal.save();
        });
    },
    setData: function() {
        $('#selectReservePendingModal #userName').text(this.reqParam.userName);
        $('#selectReservePendingModal #reserveDate').text(`${this.reqParam.reserveDate}, ${this.reqParam.reserveTime}`);
        $('#selectReservePendingModal #treatmentName').text(this.reqParam.treatmentName);
        $('#selectReservePendingModal #treatmentProcedureName').text(this.reqParam.treatmentProcedureName);
        $('#selectReservePendingModal #status').text(fn_setReserveStatus(this.reqParam.status));
    },
    /* 데이터 선택 */
    setSelect:function(selectNumber) {
        let checkedData = dataList[selectNumber];
        if(dataList==null||checkedData==undefined){
            return ;
        }

        if( selectReservePendingModal.callback )  {
            selectReservePendingModal.callback(checkedData);
        }
        selectReservePendingModal.close();
    },
    // 상세 조회
    search:function(state) {
    },
    /*
     * 팝업
     * callback : 콜백함수, reqParam: 팝업파라미터
     */
    popup:function(callback, reqParam) {
        // 초기화 후 열기
        selectReservePendingModal.init();

        //콜백함수 지정.
        selectReservePendingModal.callback = callback;
        selectReservePendingModal.reqParam = reqParam;
        selectReservePendingModal.dataList = null;

        // 데이터 바인딩
        this.setData();
        setTimeout(function(){
            $('#selectReservePendingModal').modal('show')
        }, 200);

        selectReservePendingModal.search();
    },
    /*
     * 팝업 닫기
     */
    save:function() {
        let muReserveId = selectReservePendingModal.reqParam.muReserveId;

        if(true != fn_emptyCheck(muReserveId)){
		    modalEvent.warning("수정", "예약 정보가 없습니다.");
		    return;
	    }

	    modalEvent.info("수정", "예약을 취소하시겠습니까?", function(){
		let formData = new FormData();
		formData.append("muReserveId", muReserveId);
		formData.append("status", 'TN');

		$.ajax({
			url: encodeURI('/mobilereservation/updateReserveStatus.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(){
						if( selectReservePendingModal.callback )  {
								selectReservePendingModal.callback();
							}
							selectReservePendingModal.close();
					});
				}
				else{
					modalEvent.danger("예약취소 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("예약취소 오류", "취소 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){

			},
			complete:function(){

			}
		});
	});
    },
    /*
     * 팝업 닫기
     */
    close:function() {
        $('#selectReservePendingModal').modal('hide');

		setTimeout(function(){
			$('#selectReservePendingModal').remove();
		},500);
    },
    HtmlTemplate : `
    <div class="modal promise_pending_modal fade" id="selectReservePendingModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <p class="label">
                        안녕하세요 <span id="userName"></span>님!<br/>
                        방문해주셔서 감사합니다.
                    </p>
                </div>
    
                <div class="modal-body">
                    <ul>
                        <li class="first">
                            <p class="label">예약 일시</p>
                            <p id="reserveDate"></p>
                        </li>
                        <li>
                            <p class="label">예약 유형</p>
                            <p id="treatmentName"></p>
                        </li>
                        <li>
                            <p class="label">시술</p>
                            <p id="treatmentProcedureName"></p>
                        </li>
                        <li>
                            <p class="label">상태</p>
                            <p class="blue" id="status"></p>
                        </li>
                    </ul>
                </div>
    
                <div class="modal-footer">
                    <div class="btn_box">
                        <button class="cancel_btn btnSave">예약 취소</button>
                        <button class="ok_btn btnCancle">확인</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    `
};