<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : SupplyVendorPopupForm.html
 * @desc    : 공급벤더 팝업 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.18   gagamel     최초 작성
 *******************************************************************************
 -->
<div class="modalPopup" data-width="1200" id="popupSupplyVendor">
	<div class="panelStyle" style="max-height:700px;overflow-y:scroll;">
		<!-- TITLE -->
		<div class="panelTitle">
			<strong>벤더 조회</strong>
			<button type="button" class="close" onclick="uifnPopupClose('popupSupplyVendor');"><em class="fa fa-times"></em></button>
		</div>
		<!-- //TITLE -->
		
		<!-- CONTENT -->
		<div class="panelContent">
			<form id="searchSupplyVendorForm" name="searchSupplyVendorForm" action="#" th:action="@{'/business/supply/vendor/list'}" th:method="post">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tbody>
						<tr>
							<th>벤더명</th>
							<td>
								<input type="text" name="supplyVendorNm" class="w300" maxlength="50" th:value="${supplyVendorNm}"/>
							</td>
						</tr>
					</tbody>
				</table>
				
				<ul class="panelBar">
					<li class="center">
						<button type="button" class="btn btn-base btn-lg" id="btnSearchSupplyVendor">조회</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- //CONTENT -->

		<!-- 리스트 영역 -->
		<div class="panelContent">
			<div id="gridSupplyVendorList" 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="btnConfirmSupplyVendor">확인</button>
			</li>
		</ul>
		<!-- //버튼 배치 영역 -->
	</div>
</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let returnCode = [[${returnCode}]];
	let returnName = [[${returnName}]];

	let columnDefsSupplyVendorList = [
// 		{width: 40, minWidth: 40, cellClass: 'text-center', headerCheckboxSelection: true, checkboxSelection: true, filter: false},
		{ headerName: "벤더코드", field: "supplyVendorCd", width: 100, cellClass: 'text-center' },
		{ headerName: "벤더명", field: "supplyVendorNm", width: 150, cellClass: 'text-center'},
		{
			headerName: "사업자구분", field: "bizGb", width: 100, cellClass: 'text-center',
			valueGetter: function (params) { return params.data.bizGb == 'C' ? '법인' : '개인'; }
		},
		{ headerName: "사업자등록번호", field: "bizNo", width: 120, cellClass: 'text-center' },
		{ headerName: "업종", field: "bizKind", width: 150, cellClass: 'text-center' },
		{ headerName: "업태", field: "bizType", width: 150, cellClass: 'text-center' },
		{ headerName: "대표자명", field: "ownerNm", width: 100, cellClass: 'text-center' },
		{ headerName: "대표전화번호", field: "mainTelno", width: 120, cellClass: 'text-center', hide: true },
		{ headerName: "대표팩스번호", field: "mainFaxno", width: 120, cellClass: 'text-center', hide: true },
		{ headerName: "우편번호", field: "bizZipcode", width: 80, cellClass: 'text-center' },
		{ headerName: "기본주소", field: "bizBaseAddr", width: 250 },
		{ headerName: "상세주소", field: "bizDtlAddr", width: 150 },
		{ headerName: "홈페이지URL", field: "homepageUrl", width: 200 }
	];

	let gridOptionsSupplyVendorList = gagaAgGrid.getGridOptions(columnDefsSupplyVendorList);
	
	gridOptionsSupplyVendorList.rowSelection = 'single';
	gridOptionsSupplyVendorList.rowMultiSelectWithClick = true; // 클릭으로 선택 가능
	
// 	// Row double click
// 	gridOptionsSupplyVendorList.onRowDoubleClicked = function(event) {
// 		$('#btnConfirmSupplyVendor').trigger('click');
// 	}

	// 조회
	$('#btnSearchSupplyVendor').on('click', function() {
		// Fetch data
		gagaAgGrid.fetch($('#searchSupplyVendorForm').prop('action'), gridOptionsSupplyVendorList, '#searchSupplyVendorForm', function(result) {
			if (result.length == 1) {
				// TODO: row를 클릭한 것처럼 활성화 하고, $('#btnConfirmSupplyVendor').trigger('click');
			}
		});
	});
	
	// 부모창에 값을 설정
	let fnSetSupplyVendorValueToOpener = function(rowData) {
		$(returnCode).val(rowData.supplyVendorCd);
		$(returnName).val(rowData.supplyVendorNm);

		uifnPopupClose('popupSupplyVendor');
	}
	
	// 확인
	$('#btnConfirmSupplyVendor').on('click', function() {
		var selectedData = gagaAgGrid.selectedRowData(gridOptionsSupplyVendorList);
		if (selectedData.length == 0) {
			mcxDialog.alert('선택된 항목이 없습니다.');
			return false;
		}
		
		fnSetSupplyVendorValueToOpener(selectedData[0]);
	});
	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridSupplyVendorList', gridOptionsSupplyVendorList);
		
		$('#btnSearchSupplyVendor').trigger('click');
	});
/*]]>*/
</script>

</html>
