<!DOCTYPE html>
<html lang="ko"
	  xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : SupplyCompanySearchForm.html
 * @desc    : 공급업체 목록 페이지
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.12.23   xodud1202   최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="530" id="popupCompanyList">
	<div class="panelStyle"  style="max-height:700px;overflow-y:scroll;">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong>공급업체 목록</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupCompanyList');"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->
		<!-- 검색 조건 -->
		<div class="panelContent">
			<form id="searchCompanyListForm" name="searchCompanyListForm" action="#" th:action="@{'/business/supply/company/list'}" onsubmit="$('#btnSearchCompanyList').trigger('click'); return false;">
				<input type="hidden" name="searchGb" value="NAME" />		<!-- 공급업체 목록 검색 조건은 업체명으로만 -->
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:15%;"/>
						<col style="width:35%;"/>
						<col style="width:15%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<th>자사/입점</th>
							<td colspan="3">
								<select name="selfYn" id="selfYn">
									<option value="">전체</option>
									<option value="Y">자사</option>
									<option value="N">입점</option>
								</select>
							</td>
						</tr>
						<tr>
							<th>업체코드<i class="required" title="필수"></i></th>
							<td>
								<textarea class="textareaR2" name="searchSupplyCompCd" id="searchSupplyCompCd"></textarea>
							</td>
							<th>업체명<i class="required" title="필수"></i></th>
							<td>
								<textarea class="textareaR2" name="searchSupplyCompNm" id="searchSupplyCompNm"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearchCompanyList">조회</button>
					</li>
				</ul>
			</form>
			<!-- 리스트 영역 -->
			<div class="panelContent">
				<div id="gridComapanyPopupList" style="width: 100%; height: 380px" class="ag-theme-balham"></div>
			</div>
			<!-- //리스트 영역 -->
	
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnConfirmCompany">확인</button>
				</li>
			</ul>
		</div>
		<!-- //검색 조건 -->
	</div>
	<script th:inline="javascript">
		/*<![CDATA[*/
		let headerSelection = false;
		if([[${params.multiGb}]] == "M") headerSelection = true;
		let columnCompanyPopupDefList = [
			{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: headerSelection, checkboxSelection: true, filter: false},
			{headerName: "공급업체번호", field: "supplyCompCd", width: 120, cellClass: 'text-center'},
			{headerName: "공급업체국문명", field: "supplyCompNm", width: 150, cellClass: 'text-center'},
			{headerName: "입점상태", field: "supplyStatNm", width: 150, cellClass: 'text-center'}
		];

		let gridOptionsCompanyPopupList = gagaAgGrid.getGridOptions(columnCompanyPopupDefList);
		if(headerSelection) {	gridOptionsCompanyPopupList.rowSelection = "multiple";	}

		// Row double click
		gridOptionsCompanyPopupList.onRowDoubleClicked = function(event) {
			$('#btnConfirmCompany').trigger('click');
		}

		// 조회
		$('#btnSearchCompanyList').on('click', function() {
			
			// if (gagajf.isNull($('#searchCompanyListForm textarea[name=searchSupplyCompCd]').val())  && gagajf.isNull($('#searchCompanyListForm textarea[name=searchSupplyCompNm]').val())){
			// 	mcxDialog.alert('검색조건을 입력하세요.');
			// 	return false;
			// }
			
			// Fetch data
			gagaAgGrid.fetch($('#searchCompanyListForm').prop('action'), gridOptionsCompanyPopupList, '#searchCompanyListForm');
		});

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

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

			var callbackFn = [[${params.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('popupCompanyList');
			}
		});

		$(document).ready(function() {
			// Create a agGrid
			gagaAgGrid.createGrid('gridComapanyPopupList', gridOptionsCompanyPopupList);

			//  조회
			//$('#btnSearchCompanyList').trigger('click');
		});
		/*]]>*/
	</script>

</div>

</html>
