<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org">
<!--
 *****************************************************************************
 * @source  : HilandDeliveryFeeDetailForm.html
 * @desc    : 도서산간배송비 상세
 *============================================================================
 * WIVIS
 * Copyright(C) 2019 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2020.03.16   Daehyoung   최초 작성
 *****************************************************************************
 -->
	<ul class="popup modal" id="hilandDeliveryFeeDetail" data-width="600" >
		<li class="mdPopTitle">
			<strong>도서산간 배송비 설정</strong>
			<button type="button" id="closeBtn" class="close" onclick="uifnPopClose('hilandDeliveryFeeDetail')"><i class="fa fa-times" aria-hidden="true"></i></button>
		</li>
		<li class="mdPopContent">
			<form name="hilandDeliveryFeeDetailForm" id="hilandDeliveryFeeDetailForm" action="#">
				<input type="hidden" id="originPostFno" name="originPostFno"/>
				<input type="hidden" id="originPostTno" name="originPostTno"/>
				
				<table class="frmStyle" aria-describedby="상세">
					<colgroup>
						<col style="width:20%;"/>
					</colgroup>
					<tbody>
						<tr>
							<th class="dashR">공급업체</th>
							<td class="dashR">
								<select id="supplyCompCd" name="supplyCompCd" required="required" data-valid-name="공급업체">
									<option value="">[선택]</option>
									<option th:if="${supplyCompList}" th:each="oneData, status : ${supplyCompList}" th:value="${oneData.cd}" th:text="${oneData.cdNm}"></option>
								</select>
							</td>
						</tr>
						<tr>
							<th class="dashR">지역명(도서, 산간 등)</th>
							<td class="dashR">
								<input type="text" class="w300" id="hilandNm" name="hilandNm" required="required" data-valid-name="지역명"/>
							</td>
						</tr>
						<tr>
							<th class="dashR">우편번호 범위</th>
							<td class="dashR">
								<input type="text" id="postFno" name="postFno"  class="w50"  required="required" data-valid-name="우편번호" readonly="readonly">
								<button type="button" class="btn btn-info btn-sm" onclick="cfnOpenPostFindPopup('postFno');">우편번호찾기</button>부터 
								<input type="text" id="postTno" name="postTno"  class="w50"  required="required" data-valid-name="우편번호" readonly="readonly"/>
								<button type="button" class="btn btn-info btn-sm" onclick="cfnOpenPostFindPopup('postTno');">우편번호찾기</button>까지
							</td>
						</tr>
						<tr>
							<th class="dashR">추가배송비</th>
							<td class="dashR">
								<input type="text" id="addDelvFee" name="addDelvFee" class="w70 text-right" data-valid-type="integer" data-valid-name="추가배송비" required="required"/>원
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</li>
		<li class="boxContentBtnB">
			<button type="button" class="btn btn-success btn-lg " id="btnSave">저장</button>
		</li>
	</ul>
<script th:inline="javascript">
/*<![CDATA[*/
	
	var mode = [[${mode}]];	
	var admHilandDeliveryFee;
	
	$('#btnSave').on('click', function() {
		var formId = '#hilandDeliveryFeeDetailForm';
		if (!gagajf.validation(formId))
			return false;
		
		// 우편번호 범위 유효성
		if ($('#postTno').val() < $('#postFno').val()) {
			mcxDialog.alert("우편번호 뒷범위가 앞범위보다 크거나 같게 해주세요.");
			return;
		}
		
		gagajf.removeCommaAtNumberFormattedInput('#hilandDeliveryFeeDetailForm');
		if(mode == "N"){
			fnRegist();
		} else {
			fnUpdate();
		}
	});
	
	// 도서산간배송비 등록
	var fnRegist = function() {
		mcxDialog.confirm("등록하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify($('#hilandDeliveryFeeDetailForm').serializeObject());
				gagajf.ajaxJsonSubmit('/system/hiland/deliveryfee/detail/create', jsonData, saveCallback);
			}
		});
	}
	
	// 도서산간배송비 수정
	var fnUpdate = function() {
		mcxDialog.confirm("수정하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				var jsonData = JSON.stringify($('#hilandDeliveryFeeDetailForm').serializeObject());
				gagajf.ajaxJsonSubmit('/system/hiland/deliveryfee/detail/update', jsonData, saveCallback);
			}
		});
	}
	
	// 저장 콜백
	var saveCallback = function() {
		$('#closeBtn').trigger('click');
		fnSearch();
	}
	
	// 초기세팅
	var fnInit = function(mode){
		
		if(mode == "N"){
			// 등록
			
		} else {
			// 수정
			admHilandDeliveryFee = [[${admHilandDeliveryFee}]];
			
			$('#originPostFno').val(admHilandDeliveryFee.postFno);
			$('#originPostTno').val(admHilandDeliveryFee.postTno);
			
			$('#supplyCompCd').val(admHilandDeliveryFee.supplyCompCd);
			$('#hilandNm').val(admHilandDeliveryFee.hilandNm);
			$('#addDelvFee').val(admHilandDeliveryFee.addDelvFee);
			
			$('input[name=postFno]').val(admHilandDeliveryFee.postFno);
			$('input[name=postTno]').val(admHilandDeliveryFee.postTno);
		}
		gagajf.addCommaAtNumberFormattedInput('#hilandDeliveryFeeDetailForm');
	}
	
	// 우편번호 콜백 함수
	var fnSetPostValue = function(zipNo, baseRoadAddr1, baseRoadAddr2, etcAddr, id) {
		if(id == 'postFno') {
			$('input[name=postFno]').val(zipNo);
		}
		if(id == 'postTno') {
			$('input[name=postTno]').val(zipNo);
		}
	}
	
	$(document).ready(function() {
		fnInit(mode);
	});

/*]]>*/
</script>
</html>