<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : FreeGoodsSearchForm.html
 * @desc    : 사은품 조회 페이지
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.12   xodud1202   최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="850" id="popupFreeGoodsList">
	<div class="panelStyle">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong>사은품 목록</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupFreeGoodsList');"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->

		<!-- 검색 조건 -->
		<div class="panelContent">
			<form id="searchCompanyListForm" name="searchCompanyListForm" action="#" th:action="@{'/goods/freeGoods/list'}" onsubmit="$('#btnSearchFreeGoodsList').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:15%;"/>
						<col/>
					</colgroup>
					<tbody>
					<tr>
						<th>검색어 지정</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="search" value="searchProductNo" checked/>사은품코드</label>
							<label class="rdoBtn"><input type="radio" name="search" value="searchGoodsNm"/>품번</label>
							<textarea name="condition" style="height:75px;"></textarea>
						</td>
					</tr>
					</tbody>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearchFreeGoodsList">조회</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- //검색 조건 -->

		<!-- 리스트 영역 -->
		<div class="panelContent">
			<div id="freeGoodsSearchList" style="width: 100%; height: 470px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->

		<!-- 버튼 배치 영역 -->
		<ul class="panelBar">
			<li class="right">
				<button type="button" class="btn btn-info btn-lg" id="btnConfirmFreeGoods">확인</button>
			</li>
		</ul>
	</div>

	<script th:inline="javascript">
		/*<![CDATA[*/
		let columnFreeGoodsPopupDefList = [
			  {width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false}
			, {headerName: "사은품코드", field: "productNo", width: 120, cellClass: 'text-center'}
			, {headerName: "품번코드", field: "goodsNum", width: 150, cellClass: 'text-center'}
			, {headerName: "사은품명", field: "goodsNm", width: 300, cellClass: 'text-center'}
			, {headerName: "상태", field: "useYn", width: 50, cellClass: 'text-center'}
		];

		let gridOptionsFreeGoodsPopupList = gagaAgGrid.getGridOptions(columnFreeGoodsPopupDefList);
		gridOptionsFreeGoodsPopupList.rowSelection = "multiple";

		// Row double click
		gridOptionsFreeGoodsPopupList.onRowDoubleClicked = function(event) {
			$('#popupFreeGoodsList #btnConfirmFreeGoods').trigger('click');
		}

		// 조회
		$('#popupFreeGoodsList #btnSearchFreeGoodsList').on('click', function() {
			// Fetch data
			gagaAgGrid.fetch($('#popupFreeGoodsList #searchCompanyListForm').prop('action'), gridOptionsFreeGoodsPopupList, '#searchCompanyListForm');
		});

		// 확인
		$('#popupFreeGoodsList #btnConfirmFreeGoods').on('click', function() {
			var selectedData = gagaAgGrid.selectedRowData(gridOptionsFreeGoodsPopupList);

			if (selectedData.length == 0) {
				mcxDialog.alert('선택된 공급업체가 없습니다.');
				return false;
			}

			var callbackFn = [[${param.callbackFn}]];

			var jsonData = JSON.stringify(selectedData);

			if (typeof callbackFn != 'undefined' && callbackFn) {
				if (typeof callbackFn == 'function') {
					callbackFn(jsonData);
				} else {
					if (callbackFn) {
						if (callbackFn.indexOf("(") == -1) {
							(new Function(callbackFn + "(" + jsonData + ");"))();
						} else {
							(new Function(callbackFn(jsonData)))();
						}
					}
				}
				uifnPopupClose('popupFreeGoodsList');
			}
		});

		$(document).ready(function() {
			// Create a agGrid
			gagaAgGrid.createGrid('freeGoodsSearchList', gridOptionsFreeGoodsPopupList);
		});
		/*]]>*/
	</script>

</div>

</html>
