<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : GiftCardListForm.html
 * @desc    : 상품권 등록 화면 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2021 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.05.13   jsshin     최초 작성
 *******************************************************************************
 -->
<div id="main">
	<!-- 메인타이틀 영역 -->
	<div class="main-title">
	</div>
	<!-- //메인타이틀 영역 -->

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

	<!-- 검색조건 영역 -->
	<div class="panelContent">
		<form id="giftCardForm" name="giftCardForm" action="#" th:action="@{'/marketing/giftcard/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
		<div class="panelStyle">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:40%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tbody>
					<tr>
						<th class="dashR">아이디</th>
						<td class="dashR">
							<input type="text" class="w200" name="custId" id="custId"/>
						</td>
					</tr>
					<tr>
						<th class="dashR">등록일자</th>
						<td class="dashR">
							<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="$('#giftCardForm')[0].reset();">초기화</button>
					</li>
				</ul>
		</div>
		<!-- //검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<ul class="panelBar">
				<li>
					<button type="button" class="btn btn-default btn-lg" onclick="cfnDownloadSampleFile('SF021');">상품권대량업로드 양식 다운로드</button>
					<button type="button" class="btn btn-primary btn-lg" id="btnGiftCardReg">상품권대량업로드</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="giftCardListPagination"></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}]]);				// 사이트목록

	// specify the columns
	const columnDefs = [
		{
			headerName: "회원ID", field:'maskingCustId', width:120, cellClass: 'text-rigth',
			cellRenderer: function (params) {
				return gagajf.isNull(params.data.custNo) ?
					params.data.maskingCustId :'<a href="javascript:void(0);" onclick="cfnOpenCustDetailPopup(\''+params.data.custNo+'\')">' + params.data.maskingCustId + '</a>'
			}
		},
		{headerName: "상품권번호", field:'gfcdNo', width:200, cellClass: 'text-center'},
		{headerName: "결과메시지", field:'resultMsg', width:150, cellClass: 'text-center'},
		{
			headerName: "등록일자", field:'regDt', width:120, cellClass: 'text-center',
			valueGetter: function (params) { return gagaAgGrid.toDateFormat(params.data.regDt); }
		}

	];

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

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

	}

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

	// 검색
	var fnSearch = function() {
		gagaPaging.init('giftCardForm', fnSearchCallBack, 'giftCardListPagination', $('#giftCardForm select[name=pageSize]').val());
		gagaPaging.load($('#giftCardForm input[name=pageNo]').val());
	};

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

	// 상품대량수정 클릭시
	$('#btnGiftCardReg').on('click', function() {
		cfnExcelUploadPopup('giftCardReg', 'fnSaveGiftCardExcel');
	});

	var fnSaveGiftCardExcel = function(result){
		var data = {
			         procJob : result.procJob
					,excelFileNm : result.excelFileNm
					};
		var jsonData = JSON.stringify(data);
		gagajf.ajaxJsonSubmit('/marketing/upload/giftcard/bulk/reg', jsonData, fnGiftCardBulkExcelUpload);
	}

	var fnGiftCardBulkExcelUpload = function(){
		fnSearch();
	}

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

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

	/*]]>*/
</script>

</html>
