<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : CustomerSecedeListForm.html
 * @desc    : 탈퇴회원목록 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.14   jsshin     최초 작성
 *******************************************************************************
 -->
<div id="main">
	<!-- 메인타이틀 영역 -->
	<div class="main-title">
	</div>
	<!-- //메인타이틀 영역 -->

	<!-- 메뉴 설명 -->
	<div class="infoBox menu-desc">
	</div>
	<!-- //메뉴 설명 -->
	<form id="custSecedeForm" name="custSecedeForm" action="#" th:action="@{'/customer/secede/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
				<table class="frmStyle" aria-describedby="검색조건">
					<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">
							<select name="searchGb">
								<option value="">선택</option>
								<option value="custNo">회원번호</option>
								<option value="custNm">회원명 </option>
								<option value="email">이메일</option>
								<option value="custId">아이디</option>
							</select>
							<input type="text" class="w200" name="searchTxt" id="searchTxt"/>
						</td>
						<th class="dashR">사이트</th>
						<td class="dashR">
							<select name="siteCd">
								<option value="">전체</option>
								<option th:if="${siteList}" th:each="oneData, status : ${siteList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="dashR">탈퇴사유</th>
						<td class="dashR">
							<select name="secedeRsn" class="w200">
								<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>
						<th class="dashR">휴대폰번호(숫자만)</th>
						<td class="dashR">
							<input type="text" class="w200" name="cellPhnno" id="cellPhnno" maxlength="13"/>
						</td>
					</tr>
					<tr>
						<th class="dashR">탈퇴일</th>
						<td class="dashR" colspan="3" id="terms">
						</td>
					</tr>
					</tbody>
				</table>

				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearch">조회</button>
						<button type="button" class="btn btn-gray btn-lg" onclick="$('#custSecedeForm')[0].reset();">초기화</button>
					</li>
				</ul>
		</div>
		<!-- //검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<li>
					<button type="button" class="btn btn-danger btn-lg" id="btnDelete">탈퇴이력삭제</button>
				</li>
				<li class="right">
					검색결과 : <strong><span id="gridRowTotalCount">0</span> 건</strong>&nbsp;
					쪽번호 <span id="pgNo">0</span>/ <strong id="endPgNo">0</strong>&nbsp;&nbsp;
					<select id="pageSize" name="pageSize">
						<option value="50" selected="selected">50개씩 보기</option>
						<option value="100">100개씩 보기</option>
						<option value="500">500개씩 보기</option>
						<option value="1000">1000개씩 보기</option>
					</select>
					<input type="hidden" name="pageNo" id="pageNo" value ="1"/>
				</li>
			</ul>
			<div id="gridList" style="width: 100%; height: 570px" class="ag-theme-balham"></div>
			<ul class="panelBar">
				<li class="center">
					<div class="tablePaging" id="custListPagination"></div>
				</li>
			</ul>
		</div>
		<!-- //리스트 영역 -->
	</form>
</div>
<script type="text/javascript" th:src="@{'/ux/plugins/gaga/gaga.paging.js?v=' + ${#calendars.format(#calendars.createNow(), 'yyyyMMddHHmmss')}}" src="/ux/plugins/gaga/gaga.paging.js"></script>
<script th:inline="javascript">
	/*<![CDATA[*/
	// 사이트목록
	const siteList = gagajf.convertToArray([[${siteList}]]);

	// specify the columns
	const columnDefs = [
		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{
			headerName: "사이트", field:'siteCd', width:100, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(siteList, params.data.siteCd); }
		},
		{headerName: "회원ID", field:'maskingCustId', width:120, cellClass: 'text-left'},
		{headerName: "회원NO", field: "custNo", width: 120, cellClass: 'text-center'},
		{headerName: "회원명", field:'maskingCustNm', width:100, cellClass: 'text-left'},
		{headerName: "핸드폰", field:'maskingCellPhnno', width:140, cellClass: 'text-center'},
		{headerName: "이메일", field:'maskingEmail', width:220, cellClass: 'text-left'},
		{
			headerName: "생년월일", field:'birthYmd', width:90, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.toDateFormat(params.data.birthYmd); }
		},
		{
			headerName: "탈퇴일자", field:'secedeDt', width:120, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.toDateFormat(params.data.secedeDt); }
		}
	];

	// Get GridOptions
	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);
		gridOptions.rowSelection = 'multiple';

	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {

	}
	//페이지 사이즈 클릭시 재조회
	$('#pageSize').on('click', function () {
		fnSearch();
	});

	// 조회
	$('#btnSearch').on('click', function() {
		fnSearch();
	});

	//엔터키 조회
	$('#custSecedeForm input[name=cellPhnno], #custSecedeForm input[name=searchNm]').on('keypress', function (event) {
		if (event.which === 13) {
			fnSearch();
		}
	});

	// 휴대폰 자동 하이픈
	$('#custSecedeForm input[name=cellPhnno]').on('input keyup keydown paste change', function () {
		cfnCellPhonnHypen(this);
	});

	// 유효성 확인
	var fnValidationCheck = function () {
		// 입력 값 체크
		const $searchGb = $('#custSecedeForm select[name=searchGb]');	// 검색구분
		const $searchTxt = $('#custSecedeForm input[name=searchTxt]');	// 검색내용
		let isSearchVaild = true;
		let validationMessage;

		// 검색구분: O / 검색내용: X
		if (!gagajf.isNull($searchGb.val())) {
			if (gagajf.isNull($searchTxt.val())) {
				validationMessage = '내용을 입력해주세요';
				isSearchVaild = false;
			}
		}

		// 검색구분: X / 검색내용: O
		if (!gagajf.isNull($searchTxt.val())) {
			if (gagajf.isNull($searchGb.val())) {
				validationMessage = '검색구분을 선택해주세요';
				isSearchVaild = false;
			}

		}
		if (!isSearchVaild) {
			mcxDialog.alertC(validationMessage, {
				sureBtnText: "확인",
				sureBtnClick: function() {
					$searchTxt.focus();
				}
			});
		}

		return isSearchVaild;

	}

	// 탈퇴이력 삭제
	$('#btnDelete').on('click', function() {
		var removedData = gagaAgGrid.removeRowData(gridOptions);

		if (removedData.length == 0) {
			mcxDialog.alert('선택된 행이 없습니다.');
			return;
		}

		mcxDialog.alertC('탈퇴이력 삭제 하시겠습니까?', {
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify(removedData);
				gagajf.ajaxJsonSubmit('/customer/secede/delete', jsonData, function() {
					fnSearch();
				});
			}
		});
	});

	// 검색
	var fnSearch = function() {
		// 유효성 체크
		let validation = fnValidationCheck();
		if (!validation) {
			return;
		}
		//gagaAgGrid.fetch($('#custSecedeForm').prop('action'), gridOptions, '#custSecedeForm');

		gagaPaging.init('custSecedeForm', fnSearchCallBack, 'custListPagination', $('#custSecedeForm select[name=pageSize]').val());
		gagaPaging.load($('#custSecedeForm input[name=pageNo]').val());
	};

	var fnSearchCallBack = function (result) {
		$('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
		$('#custSecedeForm input[name=pageNo]').val(result.pageing.pageable.pageNo.addComma());
		$('#pgNo').html(result.pageing.pageable.pageNo.addComma());
		$('#endPgNo').html(result.pageing.pageable.totalPage.addComma());

		gridOptions.api.setRowData(result.custList);
		gagaPaging.createPagination(result.pageing.pageable);
	};

	$(document).ready(function() {
		// 공통 달력 생성
		cfnCreateCalendar('#terms', 'stDate', 'edDate', true);
		$('.btnToday').trigger('click');

		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});

	/*]]>*/
</script>

</html>
