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

	<!-- 메뉴 설명 -->
	<div class="infoBox menu-desc">
	</div>
	<!-- //메뉴 설명 -->

	<!-- 검색조건 영역 -->
	<div class="panelContent">
		<form id="custActiveForm" name="custActiveForm" action="#" th:action="@{'/customer/active/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>
						<th class="dashR">수신여부</th>
						<td class="dashR">
							<label class="chkBox">
								<input type="checkbox" name='emailAgreeYn' value='Y'/> 메일 수신여부
							</label>
							<label class="chkBox">
								<input type="checkbox" name='smsAgreeYn' value='Y'/> SMS 수신여부
							</label>
						</td>
					</tr>
					<tr>
						<th class="dashR">회원구분</th>
						<td class="dashR">
							<select name="custGb">
								<option value="">전체</option>
								<option th:if="${custGbList}" th:each="oneData, status : ${custGbList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>

						<th class="dashR">회원등급</th>
						<td class="dashR">
							<select name="custGrade">
								<option value="">전체</option>
								<option th:if="${custGradeList}" th:each="oneData, status : ${custGradeList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>

						<th class="dashR">관리대상</th>
						<td class="dashR">
							<select name="managedRsn">
								<option value="">전체</option>
								<option th:if="${managedRsnList}" th:each="oneData, status : ${managedRsnList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="dashR">휴대폰번호</th>
						<td class="dashR">
							<input type="text" class="w200" name="cellPhnno" id="cellPhnno"/>
						</td>

						<th class="dashR">간편가입유형</th>
						<td class="dashR">
							<select name="snsType">
								<option value="">전체</option>
								<option th:if="${snsTypeList}" th:each="oneData, status : ${snsTypeList}" th:value="${oneData.cd}" th:text="|[${oneData.cd}] ${oneData.cdNm}|"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th class="dashR">조회일자</th>
						<td class="dashR" colspan="5" >
							<select name="searchDateGb">
								<option value="joinDt">가입일자</option>
								<option value="loginLdt">로그인일자</option>
							</select>
							<span id="terms"></span>
						</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="$('#custActiveForm')[0].reset();">초기화</button>
					</li>
				</ul>
		</div>
		<!-- //검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<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>
</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}]]);				// 사이트목록
	const custGbList = gagajf.convertToArray([[${custGbList}]]);			// 회원구분
	const custGradeList = gagajf.convertToArray([[${custGradeList}]]);		// 회원등급
	const managedRsnList = gagajf.convertToArray([[${managedRsnList}]]);	// 관리대상
	const genderGbList = gagajf.convertToArray([[${genderGbList}]]);		// 성별

	// specify the columns
	const columnDefs = [
		{
			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',
			valueGetter: function (params) { return params.data.maskingCustId; }
		},
		{headerName: "회원NO", field: "custNo", width: 120, cellClass: 'text-center'},
		{
			headerName: "회원명", field:'maskingCustNm', width:100, cellClass: 'text-center',
			cellRenderer: function(params) { return '<a href="javascript:void(0);">' + params.data.maskingCustNm + '</a>'; }
		},
		{
			headerName: "회원구분", field:'custGb', width:100, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(custGbList, params.data.custGb); }
		},
		{
			headerName: "등급", field:'custGrade', width:100, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(custGradeList, params.data.custGrade); }
		},
		{
			headerName: "관리대상", field:'managedRsn', width:230, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(managedRsnList, params.data.managedRsn); }
		},
		{
			headerName: "가입일자", field:'joinDt', width:120, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.toDateFormat(params.data.joinDt); }
		},
		{
			headerName: "로그인일자", field:'loginLdt', width:120, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.toDateFormat(params.data.loginLdt); }
		},
		{
			headerName: "핸드폰", field:'maskingCellPhnno', width:140, cellClass: 'text-center',
			valueGetter: function (params) { return params.data.maskingCellPhnno; }
		},
		{
			headerName: "이메일", field:'maskingEmail', width:220, cellClass: 'text-left',
			valueGetter: function (params) { return params.data.maskingEmail; }
		},
		{
			headerName: "성별", field:'sexGb', width:50, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.lookupValue(genderGbList, params.data.sexGb); }
		},
		{headerName: "수신동의(SMS)", field:'smsAgreeYn', width:110, cellClass: 'text-center'},
		{headerName: "수신동의(Email)", field:'emailAgreeYn', width:110, cellClass: 'text-center'},
		{headerName: "수신동의(APP)", field:'appAgreeYn', width:110, cellClass: 'text-center', hide: true},
	];

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

	// 셀 클릭 이벤트
	gridOptions.onCellClicked = function(event) {
		 if (event.colDef.field === 'maskingCustNm') {
			// 고객 상세
			cfnOpenCustDetailPopup(event.data.custNo);
		}
	}

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

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

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

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

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

		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 (gagajf.isNull($stDate.val()) && gagajf.isNull($edDate.val())) {
			if (gagajf.isNull($searchTxt.val()) && gagajf.isNull($searchGb.val())) {
				validationMessage = '일자 없이 조회시 <br> 검색구분 선택 및 내용을 입력해주세요';
				isSearchVaild = false;
			}
		}

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


	// 검색
	var fnSearch = function() {
		// 유효성 체크
		let validation = fnValidationCheck();
		if (!validation) {
			return;
		}
		//gagaAgGrid.fetch($('#custActiveForm').prop('action'), gridOptions, '#custActiveForm');
		gagaPaging.init('custActiveForm', fnSearchCallBack, 'custListPagination', $('#custActiveForm select[name=pageSize]').val());
		gagaPaging.load($('#custActiveForm input[name=pageNo]').val());
	};

	var fnSearchCallBack = function (result) {
		$('#gridRowTotalCount').html(result.pageing.pageable.totalCount.addComma());
		$('#custActiveForm 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>
