<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *******************************************************************************
 * @source  : SupplyCompanyForm.html
 * @desc    : 공급업체관리 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.10.14   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/company/list'}" onsubmit="$('#btnSearch').trigger('click'); return false;">
				<table class="frmStyle" aria-describedby="검색조건">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
						<col style="width:30%;"/>
						<col style="width:10%;"/>
						<col/>
					</colgroup>
					<tr>
						<th>공급업체</th>
						<td>
							<select name="supplyCompCd" disabled="disabled">
								<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>대표자명</th>
						<td>
							<input type="text" name="ownerNm" class="w300" maxlength="20"/>
						</td>
						<th>입점상태</th>
						<td>
							<select name="supplyStat">
								<option value="">[전체]</option>
								<option th:if="${supplyStatList}" th:each="oneData, status : ${supplyStatList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</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: 270px" class="ag-theme-balham"></div>
		</div>
		<!-- //리스트 영역 -->
		
		<!-- 등록/수정 -->
		<div class="panelStyle">
			<form id="detailForm" name="detailForm" action="#" th:action="@{'/business/supply/company/save'}">
				<h4>기본정보</h4>
				<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="supplyCompCd" placeholder="자동생성" maxlength="5" data-valid-name="업체코드" readonly="readonly"/>
						</td>
						<th>업체명</th>
						<td>
							<input type="text" name="supplyCompNm" maxlength="100" readonly="readonly"/>
						</td>
						<th>공급벤더</th>
						<td colspan="3">
							<input type="text" class="w200" name="supplyVendorNm" readonly="readonly"/>
							<input name="supplyVendorCd" type="text" class="w100" maxlength="20" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<th>사업자구분</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="bizGb" value="C" checked="checked" readonly="readonly"/>법인<span></span></label>
							<label class="rdoBtn"><input type="radio" name="bizGb" value="P" readonly="readonly"/>개인<span></span></label>
						</td>
						<th>사업자등록번호</th>
						<td>
							<input type="text" name="bizNo" maxlength="20" readonly="readonly"/>
						</td>
						<th>업종</th>
						<td colspan="3">
							<input type="text" name="bizKind" maxlength="100" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<th>업태</th>
						<td colspan="3">
							<input type="text" name="bizType" maxlength="100" readonly="readonly"/>
						</td>
						<th>대표자명</th>
						<td>
							<input type="text" name="ownerNm" maxlength="50" readonly="readonly"/>
						</td>
						<th>대표전화</th>
						<td>
							<input type="text" name="mainTelno" maxlength="20" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<th>대표팩스번호</th>
						<td>
							<input type="text" class="w200" name="mainFaxno" maxlength="20" readonly="readonly"/>
						</td>
						<th>사업장주소</th>
						<td colspan="5">
							<input type="text" name="bizZipcode"  class="w100" data-valid-name="우편번호" readonly="readonly"/>
							<input type="text" name="bizBaseAddr" class="w300" maxlength="200" readonly="readonly"/>
							<input type="text" name="bizDtlAddr" class="w300" maxlength="200" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<th>홈페이지URL</th>
						<td colspan="3">
							<input type="text" name="homepageUrl" maxlength="100"/>
						</td>
						<th>입점상태</th>
						<td>
							<select name="supplyStat" id="supplyStat" disabled="disabled">
								<option th:if="${supplyStatList}" th:each="oneData, status : ${supplyStatList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
						<th>판매수수료율</th>
						<td>
							<input type="text" name="sellFeeRate" class="w100 aR" placeholder="0.0" maxlength="5" data-valid-type="real" data-valid-name="판매수수료율" readonly="readonly"/>%
						</td>
					</tr>
					<tr>
						<th>CS담당자</th>
						<td>
							<input type="text" name="csChargeNm" class="w100" maxlength="50"/>
						</td>
						<th>CS담당자 연락처</th>
						<td>
							<input type="text" name="csChargeTelno" placeholder="02-0000-0000" maxlength="13"/>
						</td>
						<th>정산담당자</th>
						<td>
							<input type="text" name="settleChargeNm" class="w100" maxlength="50"/>
						</td>
						<th>정산담당자 연락처</th>
						<td>
							<input type="text" name="settleChargeTelno" placeholder="02-0000-0000" maxlength="13"/>
						</td>
					</tr>
					<tr>
						<th>정산담당자 이메일</th>
						<td>
							<input type="text" name="settleChargeEmail" maxlength="100" data-valid-type="email"/>
						</td>
						<th>계산서 이메일</th>
						<td>
							<input type="text" name="billEmail" maxlength="100" data-valid-type="email"/>
						</td>
						<th>전자계약여부</th>
						<td>
							<label class="rdoBtn"><input type="radio" name="econtractYn" value="Y" checked="checked" readonly="readonly"/>Yes<span></span></label>
							<label class="rdoBtn"><input type="radio" name="econtractYn" value="N" readonly="readonly"/>No<span></span></label>
						</td>
						<th>정산주기</th>
						<td>
							<select name="settleDay" disabled="disabled">
								<option value="">[선택]</option>
								<option th:if="${settleDayList}" th:each="oneData, status : ${settleDayList}" th:value="${oneData.cd}" th:text="${'[' + oneData.cd + '] ' + oneData.cdNm}"></option>
							</select>
						</td>
					</tr>
					<tr>
						<th>거래은행</th>
						<td>
							<select name="bankCd" disabled="disabled">
								<option value="">[선택]</option>
								<option th:if="${bankList}" th:each="oneData, status : ${bankList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
							</select>
						</td>
						<th>계좌번호</th>
						<td>
							<input type="text" name="accountNo" maxlength="20" readonly="readonly"/>
						</td>
						<th>예금주명</th>
						<td colspan="3">
							<input type="text" class="w100" name="depositorNm" maxlength="50" readonly="readonly"/>
						</td>
					</tr>
					<tr>
						<th>배송안내</th>
						<td colspan="7">
							<textarea class="textareaR3" name="note" id="note"  data-valid-name="배송안내"></textarea>
						</td>
					</tr>
				</table>
			</form>
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar">
				<li class="right">
					<button type="button" class="btn btn-success btn-lg" id="btnSave">기본정보 저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
			
			<form id="delvFeePolicyForm" name="delvFeePolicyForm" action="#" th:action="@{'/business/delivery/fee/policy/list/save'}">
				<input type="hidden" name="delvFeeCd"/>
				<input type="hidden" name="supplyCompCd"/>
				<input type="hidden" name="delvFeeCrite"/>
				<input type="hidden" name="minOrdAmt"/>
				<input type="hidden" name="delvFee"/>
				<input type="hidden" name="rtnDelvFee"/>
				<input type="hidden" name="useYn"/>
				
				<h4 class="delvFeePolicy" style="display: none;">배송비 정책<button type="button" class="btn btn-info btn-ssm marL10" id="btnAddDelvFeePolicy"><i class="fa fa-plus" aria-hidden="true"></i></button></h4>
				<table class="frmStyle delvFeePolicy" style="display: none;" aria-describedby="배송비 정책 등록/수정 폼">
					<colgroup>
						<col style="width:10%;"/>
						<col style="width:25%;"/>
						<col style="width:25%;"/>
						<col style="width:15%;"/>
						<col style="width:15%;"/>
						<col style="width:10%;"/>
					</colgroup>
					<thead>
						<tr>
							<th>정책코드</th>
							<th>배송비부과기준</th>
							<th>무료배송비기준금액</th>
							<th>배송비</th>
							<th>반품배송비</th>
							<th>사용여부</th>
						</tr>
					</thead>
					<tbody id="tbodyDelvFeePolicy">
					</tbody>
				</table>
			</form>
			
			<!-- 버튼 배치 영역 -->
			<ul class="panelBar delvFeePolicy" style="display: none;">
				<li class="right">
					<button type="button" class="btn btn-success btn-lg" id="btnSaveDelvFeePolicy">배송비 정책 저장</button>
				</li>
			</ul>
			<!-- //버튼 배치 영역 -->
		</div>
		<!-- 등록/수정 -->
	</div>

<script th:inline="javascript">
/*<![CDATA[*/
	let supplyStatList = gagajf.convertToArray([[${supplyStatList}]]);
	let bankList = gagajf.convertToArray([[${bankList}]]);

	let columnDefs = [
		{ headerName: "업체코드", field: "supplyCompCd", width: 100, cellClass: 'text-center' },
		{
			headerName: "업체명", field: "supplyCompNm", width: 150, cellClass: 'text-center',
			cellRenderer: function(params) {
				return '<a href="javascript:void(0);">' + params.value + '</a>';
			}
		},
		{ headerName: "공급벤더코드", field: "supplyVendorCd", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "공급벤더명", field: "supplyVendorNm", width: 150, cellClass: 'text-center', hide: true },
		{
			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: "econtractYn", width: 100, cellClass: 'text-center',
			valueGetter: function (params) { return params.data.econtractYn == 'Y' ? 'Yes' : 'No'; }
		},
		{ headerName: "업종", field: "bizKind", width: 150, cellClass: 'text-center' },
		{ headerName: "업태", field: "bizType", width: 150, cellClass: 'text-center' },
		{
			headerName: "입점상태", field: "supplyStat", width: 100, cellClass: 'text-center',
			valueGetter: function (params) {
				return gagaAgGrid.lookupValue(supplyStatList, params.data.supplyStat);
			}
		},
		{ headerName: "대표자명", field: "ownerNm", width: 100, cellClass: 'text-center' },
		{ headerName: "우편번호", field: "bizZipcode", width: 80, cellClass: 'text-center' },
		{ headerName: "기본주소", field: "bizBaseAddr", width: 250 },
		{ headerName: "상세주소", field: "bizDtlAddr", width: 150 },
		{ headerName: "대표전화번호", field: "mainTelno", width: 120, cellClass: 'text-center' },
		{ headerName: "대표팩스번호", field: "mainFaxno", width: 120, cellClass: 'text-center' },
		{ headerName: "홈페이지URL", field: "homepageUrl", width: 200 },
		{
			headerName: "판매수수료율", field: "sellFeeRate", width: 120, cellClass: 'text-center',
			valueGetter: function(params) {
				return params.data.sellFeeRate + '%';
			}
		},
		{ headerName: "CS담당자", field: "csChargeNm", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "CS담당자연락처", field: "csChargeTelno", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "정산담당자", field: "settleChargeNm", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "정산담당자연락처", field: "settleChargeTelno", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "정산담당자이메일", field: "settleChargeEmail", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "계산서이메일", field: "billEmail", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "정산주기", field: "settleDay", width: 100, cellClass: 'text-center', hide: true },
		{
			headerName: "은행명", field: "bankCd", width: 150, cellClass: 'text-center', hide: true,
			valueGetter: function (params) {
				return gagaAgGrid.lookupValue(bankList, params.data.bankCd);
			}
		},
		{ headerName: "계좌번호", field: "accountNo", width: 150, cellClass: 'text-center', hide: true },
		{ headerName: "예금주명", field: "depositorNm", width: 100, cellClass: 'text-center', hide: true },
		{ headerName: "배송안내", field: "note", width: 150, hide: true }
	];

	let gridOptions = gagaAgGrid.getGridOptions(columnDefs);

	// Cell click
	gridOptions.onCellClicked = function(event) {
		if (event.colDef.field != 'supplyCompNm')
			return;
		
		$('#detailForm input[name=supplyCompCd]').val(event.data.supplyCompCd);
		$('#detailForm input[name=supplyCompNm]').val(event.data.supplyCompNm);
		$('#detailForm input[name=supplyVendorCd]').val(event.data.supplyVendorCd);
		$('#detailForm input[name=supplyVendorNm]').val(event.data.supplyVendorNm);
		$('#detailForm select[name=supplyStat]').val(event.data.supplyStat);
		$('#detailForm input[name=ownerNm]').val(event.data.ownerNm);
		
		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=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);
		
		$('#detailForm input[name=mainTelno]').val(event.data.mainTelno);
		$('#detailForm input[name=mainFaxno]').val(event.data.mainFaxno);
		$('#detailForm input[name=sellFeeRate]').val(event.data.sellFeeRate);
		$('#detailForm input[name=csChargeNm]').val(event.data.csChargeNm);
		$('#detailForm input[name=csChargeTelno]').val(event.data.csChargeTelno);
		$('#detailForm input[name=settleChargeNm]').val(event.data.settleChargeNm);
		$('#detailForm input[name=settleChargeTelno]').val(event.data.settleChargeTelno);
		$('#detailForm input[name=settleChargeEmail]').val(event.data.settleChargeEmail);
		$('#detailForm input[name=billEmail]').val(event.data.billEmail);
		
		if (event.data.econtractYn == 'Y') {
			$('#detailForm input:radio[name=econtractYn]').eq(0).trigger('click');
		} else {
			$('#detailForm input:radio[name=econtractYn]').eq(1).trigger('click');
		}
		
		$('#detailForm select[name=settleDay]').val(event.data.settleDay);
		$('#detailForm select[name=bankCd]').val(event.data.bankCd);
		$('#detailForm input[name=accountNo]').val(event.data.accountNo);
		$('#detailForm input[name=depositorNm]').val(event.data.depositorNm);
		$('#detailForm textarea[name=remarks]').val(event.data.remarks);
		$('#detailForm textarea[name=note]').val(event.data.note);
		
		// 배송비 정책 조회
		fnGetDeliveryFeePolicy(event.data.supplyCompCd);
	}

	// 검색
	$('#btnSearch').on('click', function() {
		gagaAgGrid.fetch($('#searchForm').prop('action'), gridOptions, '#searchForm');
	});
	
	// 기본정보 저장
	$("#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);
	});

	// 배송비 정책 추가
	$('#btnAddDelvFeePolicy').on('click', function() {
		let idx = $('#delvFeePolicyForm input[name=delvFeeCd]').length;
		
		let tag = '<tr>\n';
		tag += '	<td align="center">\n';
		tag += '		<input type="text" name="delvFeeCd" class="w100 aC" placeholder="자동생성" maxlength="20" readonly="readonly"/>\n';
		tag += '		<input type="hidden" name="supplyCompCd" value="' + $('#detailForm input[name=supplyCompCd]').val() + '"/>\n';
		tag += '	</td>\n';
		tag += '	<td align="center">\n';
		tag += '		<select name="delvFeeCrite" onclick="fnChangeDeliveryFeeCriterion(' + idx + ', this);">\n';
		tag += '			<option value="G078_10">[G078_10] 조건부 무료</option>\n';
		tag += '			<option value="G078_20">[G078_20] 무료</option>\n';
		tag += '			<option value="G078_30">[G078_30] 유료</option>\n';
		tag += '		</select>\n';
		tag += '	</td>\n';
		tag += '	<td align="center">\n';
		tag += '		<input type="text" name="minOrdAmt" class="w100 aR" placeholder="" maxlength="7" required="required" data-valid-type="integer" data-valid-name="무료배송비기준금액"/>원 <span id="txtCriterion' + idx + '">이상</span>\n';
		tag += '	</td>\n';
		tag += '	<td align="center">\n';
		tag += '		<input type="text" name="delvFee" class="w100 aR" placeholder="" maxlength="7" required="required" data-valid-type="integer" data-valid-name="배송비"/>원\n';
		tag += '	</td>\n';
		tag += '	<td align="center">\n';
		tag += '		<input type="text" name="rtnDelvFee" class="w100 aR" placeholder="" maxlength="7" required="required" data-valid-type="integer" data-valid-name="반품배송비"/>원\n';
		tag += '	</td>\n';
		tag += '	<td align="center">\n';
		tag += '		<select name="useYn">\n';
		tag += '			<option value="Y">Yes</option>\n';
		tag += '			<option value="N">No</option>\n';
		tag += '		</select>\n';
		tag += '	</td>\n';
		tag += '</tr>\n';
		
		$('#tbodyDelvFeePolicy').append(tag);
	});
	
	// 배송비 정책 조회
	let fnGetDeliveryFeePolicy = function(supplyCompCd) {
		$('#tbodyDelvFeePolicy').html('');
		
		$.getJSON('/business/delivery/fee/policy/list/' + supplyCompCd
			, function(result, status) {
				if (result == null || result.length == 0) {
					$('.delvFeePolicy').show();
					return;
				}
				
				$.each(result, function(idx, item) {
					let tag = '<tr>\n';
					tag += '	<td align="center">\n';
					tag += '		<input type="text" name="delvFeeCd" class="w100 aC" placeholder="자동생성" value="' + item.delvFeeCd + '" maxlength="20" readonly="readonly"/>\n';
					tag += '		<input type="hidden" name="supplyCompCd" value="' + item.supplyCompCd + '"/>\n';
					tag += '	</td>\n';
					tag += '	<td align="center">\n';
					tag += '		<select name="delvFeeCrite" onclick="fnChangeDeliveryFeeCriterion(' + (idx + 1) + ', this);">\n';
					tag += '			<option value="G078_10"' + (item.delvFeeCrite == "G078_10" ? " selected" : "") + '>[G078_10] 조건부 무료</option>\n';
					tag += '			<option value="G078_20"' + (item.delvFeeCrite == "G078_20" ? " selected" : "") + '>[G078_20] 무료</option>\n';
					tag += '			<option value="G078_30"' + (item.delvFeeCrite == "G078_30" ? " selected" : "") + '>[G078_30] 유료</option>\n';
					tag += '		</select>\n';
					tag += '	</td>\n';
					tag += '	<td align="center">\n';
					tag += '		<input type="text" name="minOrdAmt" class="w100 aR" placeholder="" value="' + item.minOrdAmt.addComma() + '" maxlength="7" required="required" data-valid-type="integer" data-valid-name="무료배송비기준금액"/>원 <span id="txtCriterion' + (idx + 1) + '">이상</span>\n';
					tag += '	</td>\n';
					tag += '	<td align="center">\n';
					tag += '		<input type="text" name="delvFee" class="w100 aR" placeholder="" value="' + item.delvFee.addComma() + '" maxlength="7" required="required" data-valid-type="integer" data-valid-name="배송비"/>원\n';
					tag += '	</td>\n';
					tag += '	<td align="center">\n';
					tag += '		<input type="text" name="rtnDelvFee" class="w100 aR" placeholder="" value="' + item.rtnDelvFee.addComma() + '" maxlength="7" required="required" data-valid-type="integer" data-valid-name="반품배송비"/>원\n';
					tag += '	</td>\n';
					tag += '	<td align="center">\n';
					tag += '		<select name="useYn">\n';
					tag += '			<option value="Y" ' + (item.useYn == "Y" ? "selected" : "") + '>Yes</option>\n';
					tag += '			<option value="N" ' + (item.useYn == "N" ? "selected" : "") + '>No</option>\n';
					tag += '		</select>\n';
					tag += '	</td>\n';
					tag += '</tr>\n';
					
					$('#tbodyDelvFeePolicy').append(tag);
				});
				
				$('.delvFeePolicy').show();
			});
	}

	// 배송비부과기준
	var fnChangeDeliveryFeeCriterion = function(idx, obj) {
		if ($(obj).val() == 'G078_10') {
			$('#delvFeePolicyForm input[name=minOrdAmt]').eq(idx).attr('readonly', false);
			$('#txtCriterion' + idx).html('이상');
		} else if ($(obj).val() == 'G078_20') {
			$('#delvFeePolicyForm input[name=minOrdAmt]').eq(idx).val(0);
			$('#delvFeePolicyForm input[name=minOrdAmt]').eq(idx).attr('readonly', true);
			$('#txtCriterion' + idx).html('이상');
		} else if ($(obj).val() == 'G078_30') {
			$('#delvFeePolicyForm input[name=minOrdAmt]').eq(idx).val(0);
			$('#delvFeePolicyForm input[name=minOrdAmt]').eq(idx).attr('readonly', true);
			$('#txtCriterion' + idx).html('금액에 상관 없음');
		}
	}
	
	// 배송비정책 저장
	$("#btnSaveDelvFeePolicy").on("click", function() {
		// 필수값 체크
		if (!gagajf.validation('#delvFeePolicyForm'))
			return false;

		mcxDialog.confirm("배송비정책을 저장하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				// comma(,) 제거
				gagajf.removeCommaAtNumberFormattedInput('#delvFeePolicyForm');
				
				var arrData = [];
				
				$('#tbodyDelvFeePolicy tr').each(function(idx) {
					var params = new Object();
					params.delvFeeCd 			= $(this).find('input[name=delvFeeCd]').val();
					params.supplyCompCd 		= $(this).find('input[name=supplyCompCd]').val();
					params.delvFeeCrite 		= $(this).find('select[name=delvFeeCrite]').val();
					params.minOrdAmt 			= $(this).find('input[name=minOrdAmt]').val();
					params.delvFee 				= $(this).find('input[name=delvFee]').val();
					params.rtnDelvFee 			= $(this).find('input[name=rtnDelvFee]').val();
					params.useYn 				= $(this).find('select[name=useYn]').val();
					
					// 2021.009.14 SCM 배송비정책 등록 오류 수정 
					//params.distributionGb 		= $('#detailForm select[name=distributionGb]').val();
					params.distributionGb 		= "G065_20";
					
					arrData.push(params);
				});
				
				let jsonData = JSON.stringify(arrData);
				gagajf.ajaxJsonSubmit($('#delvFeePolicyForm').prop('action'), jsonData, function() {
					// 배송비정책 조회
					fnGetDeliveryFeePolicy($('#detailForm input[name=supplyCompCd]').val());
				});
			}
		});
	});
	
	$(document).ready(function() {
		// Create a agGrid
		gagaAgGrid.createGrid('gridList', gridOptions);
	});
/*]]>*/
</script>

</html>
