<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<c:set var="pageKorName" scope="request">면제차량 상세 조회</c:set>

<div class="card" data-doctx="${pageName}" style="padding: .25rem;">
	<form name="frmEdit">
		<input type="hidden" name="exmptnVhclId" data-map="EXMPTN_VHCL_ID" />
		<input type="hidden" name="sggCd" data-map="SGG_CD" />

		<div class="row g-1">

			<div class="col-md-12">
				<label is="name-label" for="vhrno" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
					차량번호
				</label>
				<input type="text" is="id-input" name="vhrno" data-map="VHRNO" class="form-control"
					data-maxlengthb="30" required />
			</div>
			<div class="col-md-12">
				<label class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					면제기간
				</label>
				<input type="text" name="exmptnBgngYmd" data-map="EXMPTN_BGNG_YMD"
				class="form-control form-date" data-fmt-type="day"   title="시작 날짜 선택" />
                <button type="button" class="bx bx-lg bx-calendar bg-white"></button>
                ~
                <input type="text" name="exmptnEndYmd" data-map="EXMPTN_END_YMD"
                class="form-control form-date" data-fmt-type="day" title="종료 날짜 선택">
                <button type="button" class="bx bx-lg bx-calendar bg-white"></button>
			</div>
			<div class="col-md-12">
				<label is="name-label" for="exmptnRsn" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					면제 사유
				</label>
				<input type="text" is="id-input" name="exmptnRsn" data-map="EXMPTN_RSN"
					class="form-control w-px-300" data-maxlengthb="1000" />
			</div>
			<div class="col-md-12">
				<label is="name-label" for="docNo" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					공문번호
				</label>
				<input type="text" is="id-input" name="docNo" data-map="DOC_NO"
					class="form-control w-px-300" data-maxlengthb="100" />
			</div>
			<div class="col-md-12">
				<label is="name-label" for="ownrNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					소유주명
				</label>
				<input type="text" is="id-input" name="ownrNm" data-map="OWNR_NM"
					class="form-control w-px-300" data-maxlengthb="200" />
			</div>
		</div>
		<div class="row mt-4 justify-content-end mb-3">
			<div class="col-md-6">
				<div class="row justify-content-end">
					<div class="col-sm-3">
						<button type="button" name="btnSave" class="btn btn-primary">저장</button>
					</div>
				</div>
			</div>
		</div>

	</form>
</div>

<script>
LoadScript("crdn08020Script",wctx.url("/resources/js/fims/crdn/crdn08020.js?ver=${ver}"));

/**************************************************************************
* Global Variable
**************************************************************************/

pageObject["${pageName}"] = newDoctxFinder("${pageName}");
pageObject["${pageName}"].provided = {};

pageObject.childReq = [];
pageObject.childReq.push({
	refreshList : function(){}
});

$(document).ready(function(){

	var $P = pageObject["${pageName}"];

	if(pageObject.parentRes.length > 0){
		$P.provided = pageObject.parentRes.pop();
	} else {
		$P.provided = pageObject.childReq.pop();
	}

	/**************************************************************************
	* DatasetControl, DatasetSupport, FormFields
	**************************************************************************/
	$P.formFields = new FimsFormFields($P.selectorn("frmEdit"));

	var ctrl = newCrdn08020Control($P);

	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.setInfo = (item) => {
		$P.formFields.set(ctrl, item);

		var create = isEmpty(item.EXMPTN_VHCL_ID);
		$P.$findn("vhrno").prop("readonly", !create);
	}

	$P.fnSave = async() => {

		if(!AppSupport.customValidate($P.$findn("frmEdit").find("input"))) return;

		if(await confirm2("면제 차량 정보를 저장하시겠습니까?")){
			var info = $P.formFields.get();

			if (!info) {
				return;
			}

			var create = isEmpty(info.exmptnVhclId);

			ajax.post({
				url : !create ? ctrl.urls.update : ctrl.urls.create,
				data : info,
				success : (resp) => {
					$P.saveCallback(resp);
				}
			});
		}

	};

	$P.saveCallback = (resp) => {
		if (resp.saved) {
			dialog.alert({
				content : "저장됐습니다.",
				init : function() {
					AppSupport.setDialogZindex();
					AppSupport.focusClose();
				}
			});
			dialog.close($P.selfDlgId());
			$P.provided.refreshList();
		}
	};

	/**************************************************************************
	* element.on
	**************************************************************************/
	 $P.$findn("btnSave").on('click', () => $P.fnSave());

	/**************************************************************************
	* 초기화
	**************************************************************************/
	AppSupport.initDatepicker($P.findn("frmEdit")); //달력 초기화

	$P.$findn("frmEdit").find(".form-date").each(function(){
		$(this).on("input",function(){
			var 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);
			}

		});
	});

	//보안모드
    fn_securityModeToggle($("#securityMode--top").is(":checked"));

    var exmptnVhclInfo = ${exmptnVhclInfo};
	$P.setInfo(exmptnVhclInfo);

});
</script>