<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>

<!-- Page Body -->
<div class="card">
	<!-- 입력 영역 -->
	<form id="frmEdit--${pageName}" name="frmEdit">
		<!-- hidden -->
		<input type="hidden" id="crdnId--${pageName}" name="crdnId" data-map="CRDN_ID" />
		<input type="hidden" id="sggCd--${pageName}" name="sggCd" data-map="SGG_CD" />
		<input type="hidden" id="taskSeCd--${pageName}" name="taskSeCd" data-map="TASK_SE_CD" />
		<input type="hidden" id="levyExclId--${pageName}" name="levyExclId" data-map="LEVY_EXCL_ID" />

		<div class="row g-1">
			<!-- 차량번호 -->
			<div class="col-md-12">
				<label for="vhrno--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">차량번호</label>
				<input type="text" class="form-control w-px-120" id="vhrno--${pageName}" name="vhrno" data-map="VHRNO" readonly />
			</div>
			<!-- 부과 제외 구분 -->
			<div class="col-md-12">
				<label for="levyExclSeNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">부과제외구분</label>
				<input type="text" class="form-control w-px-120" id="levyExclSeNm--${pageName}" readonly />
				<input type="hidden" id="levyExclSeCd--${pageName}" name="levyExclSeCd" data-map="LEVY_EXCL_SE_CD" />
			</div>
			<!-- 부과 제외 일자 -->
			<div class="col-md-12">
				<label for="levyExclYmd--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">부과제외일자</label>
				<input type="text" class="form-control form-date" id="levyExclYmd--${pageName}" name="levyExclYmd" data-map="LEVY_EXCL_YMD"
					data-fmt-type="day" title="날짜 선택" maxlength="10" required />
				<button type="button" class="bx bx-sm bx-calendar bg-white"></button>
			</div>
			<!-- 부과 제외 사유 -->
			<div class="col-md-12">
				<label for="levyExclRsnCd--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">부과제외사유</label>
				<select class="form-select" id="levyExclRsnCd--${pageName}" name="levyExclRsnCd" data-map="LEVY_EXCL_RSN_CD" required>
					<option value="">선택하세요</option>
					<c:forEach items="${FIM022List}" var="item">
						<option value="${item.code}">${item.value}</option>
					</c:forEach>
				</select>
			</div>
			<!-- 기타 내용 -->
			<div class="col-md-12">
				<label for="etcCn--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">기타 내용</label>
				<textarea type="text" class="form-control w-80" id="etcCn--${pageName}" name="etcCn" data-map="ETC_CN" rows="3" data-maxlengthb="1000">
				</textarea>
			</div>
		</div>
	</form>
	<!-- /입력 영역 -->
</div>
<!-- <div class="card"> -->

<!-- 업무 버튼 표시 -->
<div>
	<span class="container-page-btn">
		<span class="container-window-btn-right">
			<!-- 업무 버튼 -->
			<button type="button" class="btn btn-primary" id="btnSave--${pageName}" title="저장" onclick="fnSave${pageName}()">저장</button>
		</span>
	</span>
</div>
<!-- / 업무 버튼 표시 -->

<script>
	/**************************************************************************
	 * Global Variable
	 **************************************************************************/
	// URL
	var ${pageName}PrefixUrl = "/excl/excl01";
	// FormFields
 	var ${pageName}Fields = new FormFields("#frmEdit--${pageName}");
 	// 공통 코드
	var FIM021 = new CommonCodes(${FIM021}, true);
	var FIM022 = new CommonCodes(${FIM022}, true);
	// 호출한 Page Name
	var openerPageName = "${openerPageName}";

	/**************************************************************************
	 * DatasetControl
	 **************************************************************************/
	var ${pageName}Control = new DatasetControl({
		  prefix : "levyExcl"
		, prefixName : "부과제외"
		, keymapper : info => info ? info.LEVY_EXCL_ID : ""
		, dataGetter : obj => obj.levyExclInfo
		, urls : {
			  create : wctx.url(${pageName}PrefixUrl + "/020/create.do")		// 등록
			, update : wctx.url(${pageName}PrefixUrl + "/020/update.do")		// 수정
		}
		, formats : {
	    	LEVY_EXCL_YMD : dateFormat
		}
	});

	${pageName}Control.onCurrentChange = item => {
		${pageName}Fields.set(item);

		setFim021(item.data.LEVY_EXCL_SE_CD, item.data.LEVY_EXCL_RSN_CD);
	}

	/**************************************************************************
	 * DatasetControl 이벤트
	 **************************************************************************/
	// 저장 callback
	${pageName}Control.onSave = (resp) => {
  		let dialogTitle = $("#" + ${pageName}Control.prefix + "Dialog").find("h5.modal-title").html();
  		let showMessage = resp.retMessage.replace(/[S]|[F]/g, dialogTitle);

		dialog.alert(showMessage);

		if (resp.saved) {
			dialog.close(${pageName}Control.prefix + "Dialog");

			if ("${savedCallbackFuncName}" != "") {
				${savedCallbackFuncName}(resp.saved);
			}
		}
	}

	// 저장
	${pageName}Control.save = (info) => {
		if (!info) return;

  		let create = isEmpty(info.levyExclId);

  		// 민원 접수 관리에서 호출했다면..
  		if (create && "${saveCallbackFuncName}" != "") {
  			${saveCallbackFuncName}(info);
  		} else {
  			ajax.post({
	  			  url : !create ? ${pageName}Control.urls.update : ${pageName}Control.urls.create
	  			, data : info
	  			, success : resp => ${pageName}Control.onSave(resp)
	  		});
  		}
	}

	/**************************************************************************
	 *
	 **************************************************************************/
	// 부과제외 구분에 따른 부과제외 사유 코드 설정
	setFim021 = (seCode, rsnCode) => {
		let cmnCode = FIM021[seCode];

		$("#levyExclSeCd--${pageName}").val(cmnCode.code);
		$("#levyExclSeNm--${pageName}").val(cmnCode.value);

		let reasons = FIM022.list().filter(reason => "1" == seCode ? reason.code < "200" : reason.code > "200");
		$("#levyExclRsnCd--${pageName}").html(reasons.map(reason => "<option value='" + reason.code + "'>" + reason.value + "</option>").join());

		if (rsnCode != undefined && rsnCode != "") {
			$("#levyExclRsnCd--${pageName}").val(rsnCode);
		}
	}

	/**************************************************************************
	 * 초기 셋팅
	 **************************************************************************/
	// 검색조건 초기값 셋팅
	initForm${pageName} = () => {
		// 달력 초기화
	    initDatepicker("frmEdit--${pageName}");
	    $("#levyExclYmd--${pageName}").datepicker("setDate", new Date());
	}

	// 이벤트 설정
	setEvent${pageName} = () => {
		// form-date 항목에서 키보드로 입력시 날짜 포맷팅 적용
		$("#frmEdit--${pageName}").find(".form-date").each(function() {
			$(this).on("input",function() {
				let value = this.value.replaceAll("-", "");

				if (value.length > 7) {
					this.value = value.substring(0, 4) + "-" + value.substring(4, 6) + "-" + value.substring(6);
				} else if(value.length > 5) {
					this.value = value.substring(0, 4) + "-" + value.substring(4);
				}
			});
		});
	}

	/**************************************************************************
	 * function
	 **************************************************************************/
	// 저장
	fnSave${pageName} = () => {
		// validate 확인
		if (!customValidate($("#frmEdit--${pageName}").find("input, select, textarea"))) return;

		dialog.alert({
			  content : "현재 " + ${pageName}Control.prefixName + " 정보를 저장하시겠습니까?"
			, onOK : () => {
				${pageName}Control.save(${pageName}Fields.get());
			}
		});
	}

	/**************************************************************************
	 * script 진입
	 **************************************************************************/
	$(document).ready(function() {
		// 이벤트 설정
		setEvent${pageName}();

		// 화면 초기 설정
		initForm${pageName}();

		// Dataset 셋팅 - 단건일 경우 setData
		${pageName}Control.setData([${levyExclInfo}]);
	});

// #sourceURL=excl01020-info.jsp
</script>
