<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CustomerSecedePopupForm.html
 * @desc    : 회원탈퇴처리 화면 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.26   jsshin     최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="800">
	<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong>회원탈퇴처리</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupCustSecedeForm')"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->
		<!-- CONTENT -->
		<div class="panelContent">
			<div class="panelStyle">
				<form id="custSecedeForm" name="custSecedeForm">
					<input type="hidden" name="custNo"/>
					<table class="frmStyle">
						<colgroup>
							<col style="width:10%;"/>
							<col style="width:20%;"/>
							<col style="width:10%;"/>
							<col style="width:15%;"/>
							<col style="width:10%;"/>
							<col style="width:20%;"/>
							<col/>
						</colgroup>
						<tbody>
						<tr>
							<th class="dashR">탈퇴사유</th>
							<td class="dashR" colspan="5">
								<select name="secedeRsn" > <!-- 탈퇴사유 (공통코드G102) -->
									<option value="">전체</option>
									<option th:if="${secedeRsnList}" th:each="oneData, status : ${secedeRsnList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
								</select>
							</td>
						</tr>
						<tr>
							<th class="dashR">탈퇴 상세 사유</th>
							<td class="dashR" colspan="5">
								<input type="text" class="w600" id="secedeDtlRsn" name="secedeDtlRsn" />
							</td>
						</tr>
						</tbody>
					</table>
				</form>
			</div>
			<ul class="panelBar">
				<li class="right">
					<button type="button" id="btnSaveSecede" class="btn btn-success btn-lg">탈퇴처리</button>
				</li>
			</ul>
		</div>
		<!-- //CONTENT -->
	</div>
</div>
<script th:inline="javascript">
	/*<![CDATA[*/
	const elementCustNo = [[${elementCustNo}]];

	// 회원탈퇴
	$("#btnSaveSecede").on("click",function() {
		let custSecedeForm = $('#custSecedeForm').serializeObject();

		if(gagajf.isNull(custSecedeForm.secedeRsn)){
			mcxDialog.alert("탈퇴 사유를 선택해주세요.");
			return;
		}

		mcxDialog.confirm('회원 탈퇴를 진행하시겠습니까?', {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function(){
				gagajf.ajaxFormSubmit('/customer/secede/save', '#custSecedeForm', fnSaveCall);
			}
		});

	});

	var fnSaveCall = function (result) {
		console.log(result);
		if (result.isSuccess) {
			mcxDialog.alertC("정상적으로 탈퇴되었습니다.", {
				sureBtnText: "확인",
				sureBtnClick: function() {
					uifnPopupClose('popupCustSecedeForm');
					uifnPopupClose('popupCustomerDetail');
				}
			});
		} else {
			let message;
			if (result.resultType === 'ALREADY_SECEDE') {
				message = '이미 탈퇴처리된 회원 입니다.';
			} else if (result.resultType === 'PROGRESS_ORDER') {
				message = '진행중인 거래가 있습니다. <br> 진행중인 거래를 완료 후 탈퇴 신청을 해주세요.';
			} else {
				message = '탈퇴가 정상적으로 처리되지 않았습니다. 다시 시도해 주세요.'
			}
			mcxDialog.alert(message);
			return;
		}
	}

	var fnInitDataSet = function () {
		let custNo = $(elementCustNo).val();
		if(!gagajf.isNull(custNo)) {
			$('#custSecedeForm input[name=custNo]').val(custNo);
		}
	}

	$(document).ready(function() {

		fnInitDataSet();

	});
	/*]]>*/
</script>
</html>
