<%@ 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="rductId--${pageName}" name="rductId" data-map="RDUCT_ID" />

		<div class="row g-1">
			<!-- 납부자 명 -->
			<div class="col-md-6">
				<label for="rtpyrNm--${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="rtpyrNm--${pageName}" name="rtpyrNm" data-map="RTPYR_NM" readonly />
			</div>
			<!-- 납부자 번호 -->
			<div class="col-md-6">
				<label for="rtpyrNo--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">납부자번호</label>
				<input type="text" class="form-control w-50" id="rtpyrNo--${pageName}" name="rtpyrNo" data-map="RTPYR_NO" readonly />
			</div>
			<!-- 과태료 단속 금액 -->
			<div class="col-md-6">
				<label for="ffnlgCrdnAmt--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">단속금액</label>
				<input type="text" class="form-control w-30 text-end" id="ffnlgCrdnAmt--${pageName}" name="ffnlgCrdnAmt" data-map="FFNLG_CRDN_AMT" readonly /> *
				<input type="text" class="form-control w-15 text-end" id="wksnRductRt--${pageName}" name="wksnRductRt" data-map="WKSN_RDUCT_RT" readonly /> %
			</div>
			<!-- 감경 금액 -->
			<div class="col-md-6">
				<label for="rductAmt--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">감경금액</label>
				<input type="text" class="form-control w-30 text-end" id="rductAmt--${pageName}" name="rductAmt" data-map="RDUCT_AMT" readonly />
			</div>
			<!-- 감경 일자 -->
			<div class="col-md-6">
				<label for="rductYmd--${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="rductYmd--${pageName}" name="rductYmd" data-map="RDUCT_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-6">
				<label for="rductRsnCd--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end required">감경사유</label>
				<select class="form-select" id="rductRsnCd--${pageName}" name="rductRsnCd" data-map="RDUCT_RSN_CD" required>
					<c:forEach items="${FIM019List}" 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 = "/levy/levy02";
	// FormFields
 	var ${pageName}Fields = new FormFields("#frmEdit--${pageName}");

	/**************************************************************************
	 * DatasetControl
	 **************************************************************************/
	var ${pageName}Control = new DatasetControl({
		  prefix : "rduct"
		, prefixName : "감경"
		, keymapper : info => info ? info.RDUCT_ID : ""
		, dataGetter : obj => obj.rductInfo
		, urls : {
			  create : wctx.url(${pageName}PrefixUrl + "/020/create.do")		// 등록
			, update : wctx.url(${pageName}PrefixUrl + "/020/update.do")		// 수정
		}
		, formats : {
			  RDUCT_YMD : dateFormat											// 감경 일자
			, FFNLG_CRDN_AMT : numberFormat										// 과태료 단속 금액
			, WKSN_RDUCT_RT : numberFormat										// 감경 율
			, RDUCT_AMT : numberFormat											// 감경 금액
		}
	});

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

	/**************************************************************************
	 * 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");
		}
	}

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

  		let create = isEmpty(info.rductId);

		ajax.post({
  			  url : !create ? ${pageName}Control.urls.update : ${pageName}Control.urls.create
  			, data : info
  			, success : resp => ${pageName}Control.onSave(resp)
  		});
	}

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

	// 이벤트 설정
	function 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
	 **************************************************************************/
	// 저장
	function fnSave${pageName}() {
		// validate 확인
		if (!customValidate($("#frmEdit--${pageName}").find("input, select, textarea"))) return;

		// 감경 사유 확인
		let rductRsn = $("#rductRsnCd--${pageName}").val();

		if (rductRsn == "00") {
			dialog.alert("감경 사유를 다시 선택하여 주시기 바랍니다.");

			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([${rductInfo}]);
	});

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