<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : SupplyVendorForm.html
 * @desc    : 공급벤더관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.01.18   gagamel     최초 작성
 *******************************************************************************
 -->
	<div id="main">
		<!-- 메인타이틀 영역 -->
		<div class="main-title">
		</div>
		<!-- //메인타이틀 영역 -->
		
		<!-- 메뉴 설명 -->
		<div class="infoBox menu-desc">
		</div>
		<!-- //메뉴 설명 -->
		
		<!-- 검색조건 영역 -->
		<div class="panelStyle">
			<form id="searchForm" name="searchForm" action="#" th:action="@{'/business/supply/vendor/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>검색어</th>
						<td>
							<select name="searchGb">
								<option value="NAME">벤더명</option>
								<option value="OWNER">대표자명</option>
							</select>
							<input type="text" name="searchTxt" class="w300" maxlength="20"/>
						</td>
					</tr>
				</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="$('#searchForm')[0].reset();">초기화</button>
					</li>
				</ul>
			</form>
		</div>
		<!-- 검색조건 영역 -->

		<!-- 리스트 영역 -->
		<div class="panelStyle">
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-default btn-lg" id="btnExcel">엑셀다운로드</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<div id="gridList" style="width: 100%; height: 470px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
		
		<!-- 등록/수정 -->
		<div class="panelStyle">
			<form id="detailForm" name="detailForm" action="#" th:action="@{'/business/supply/vendor/save'}">
				<table class="frmStyle" aria-describedby="등록/수정 폼">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
					</colgroup>
					<tr>
						<th>벤더코드</th>
						<td>
							<input type="text" class="w150" name="supplyVendorCd" placeholder="자동생성" maxlength="6" data-valid-name="벤더코드" readonly="readonly"/>
						</td>
						<th>벤더명<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="supplyVendorNm" maxlength="100" required="required" data-valid-name="벤더명"/>
						</td>
						<th>사업자구분<i class="required" title="필수"></i></th>
						<td>
							<label class="rdoBtn"><input type="radio" name="bizGb" value="C" checked="checked"/>법인<span></span></label>
							<label class="rdoBtn"><input type="radio" name="bizGb" value="P"/>개인<span></span></label>
						</td>
						<th>사업자등록번호<i class="required" title="필수"></i></th>
						<td>
							<input type="text" class="w150" name="bizNo" maxlength="20" required="required" data-valid-name="사업자등록번호"/>
							<button type="button" class="btn btn-info btn-sm" onclick="fnCertifyBizNo();">인증</button>
						</td>
					</tr>
					<tr>
						<th>업종<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="bizKind" maxlength="100" required="required" data-valid-name="업종"/>
						</td>
						<th>업태<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="bizType" maxlength="100" required="required" data-valid-name="업태"/>
						</td>
						<th>대표자명<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="ownerNm" maxlength="50" required="required" data-valid-name="대표자명"/>
						</td>
						<th>대표전화<i class="required" title="필수"></i></th>
						<td>
							<input type="text" name="mainTelno" placeholder="02-0000-0000" maxlength="20" required="required" data-valid-name="대표전화"/>
						</td>
					</tr>
					<tr>
						<th>대표팩스번호</th>
						<td>
							<input type="text" name="mainFaxno" placeholder="02-0000-0000" maxlength="20" data-valid-name="대표팩스번호"/>
						</td>
						<th>사업장주소<i class="required" title="필수"></i></th>
						<td colspan="5">
							<input type="text" name="bizZipcode"  class="w100" data-valid-name="우편번호" readonly="readonly"/>
							<button type="button" class="btn btn-info btn-sm" onclick="fnOpenDaumAddr();">우편번호찾기</button>
							<input type="text" name="bizBaseAddr" class="w300" maxlength="200" required="required" data-valid-name="사업장주소" readonly="readonly"/>
							<input type="text" name="bizDtlAddr" class="w300" maxlength="200"/>
						</td>
					</tr>
					<tr>
						<th>홈페이지URL</th>
						<td colspan="5">
							<input type="text" class="w300" name="homepageUrl" data-valid-name="홈페이지URL"/>
						</td>
						<th>사용여부<i class="required" title="필수"></i></th>
						<td>
							<label class="rdoBtn"><input type="radio" name="useYn" value="Y" checked="checked"/>Yes<span></span></label>
							<label class="rdoBtn"><input type="radio" name="useYn" value="N"/>No<span></span></label>
						</td>
					</tr>
				</table>
			</form>
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-info btn-lg" id="btnNew">신규</button>
					<button type="button" class="btn btn-success btn-lg" id="btnSave">저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
		</div>
		<!-- 등록/수정 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let columnDefs = [
		{ headerName: "벤더코드", field: "supplyVendorCd", width: 100, cellClass: 'text-center' },
		{
			headerName: "벤더명", field: "supplyVendorNm", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{
			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' },
		{ headerName: "대표팩스번호", field: "mainFaxno", width: 120, cellClass: 'text-center' },
		{ 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 gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// Cell click
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'supplyVendorNm')
			return;
		
		$('#detailForm input[name=supplyVendorCd]').val(event.data.supplyVendorCd);
		$('#detailForm input[name=supplyVendorNm]').val(event.data.supplyVendorNm);
		
		if (event.data.bizGb == 'C') {
			$('#detailForm input:radio[name=bizGb]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=bizGb]').eq(1).trigger('click');
		}
		
		$('#detailForm input[name=bizNo] ').val(event.data.bizNo);
		$('#detailForm input[name=bizKind]').val(event.data.bizKind);
		$('#detailForm input[name=bizType]').val(event.data.bizType);
		$('#detailForm input[name=ownerNm]').val(event.data.ownerNm);
		$('#detailForm input[name=mainTelno]').val(event.data.mainTelno);
		$('#detailForm input[name=mainFaxno]').val(event.data.mainFaxno);
		$('#detailForm input[name=bizZipcode]').val(event.data.bizZipcode);
		$('#detailForm input[name=bizBaseAddr]').val(event.data.bizBaseAddr);
		$('#detailForm input[name=bizDtlAddr]').val(event.data.bizDtlAddr);
		$('#detailForm input[name=homepageUrl]').val(event.data.homepageUrl);
		
		if (event.data.useYn == 'Y') {
			$('#detailForm input:radio[name=useYn]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=useYn]').eq(1).trigger('click');
		}
	}

	// 검색
	$('#btnSearch').on('click', function() {
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 신규버튼
	$('#btnNew').on('click', function() {
		$("#detailForm")[0].reset();
	});

	// 저장
	$("#btnSave").on("click", function() {
		// 필수값 체크
		if (!gagajf.validation('#detailForm'))
			return false;

		mcxDialog.confirm("저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				gagajf.ajaxFormSubmit($('#detailForm').prop('action'), '#detailForm', function() {
					$('#btnNew').trigger('click');
					$('#btnSearch').trigger('click');
				});
			}
		});
	});
	
	// 엑셀다운로드
	$('#btnExcel').on('click', function() {
		gagaAgGrid.exportToExcel('공급벤더 목록', gridOptions);
	});

	/**
	 * DAUM을 이용한 우편번호 팝업 레이어
	 */
	var fnOpenDaumAddr = function() {
		let daumZip = new daum.Postcode({
			oncomplete: function(data) {
				// 우편번호와 주소 정보를 해당 필드에 넣는다.
				$('#detailForm input[name=bizZipcode]').val(data.zonecode);
				$('#detailForm input[name=bizBaseAddr]').val(cfnGetDaumRoadAddr(data));
				$('#detailForm input[name=bizDtlAddr]').focus();
				
				cfnCloseDaumAddr();
			},
			width: '100%'
		});
		
		cfnOpenDaumAddr(daumZip);
	}
	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
