<%@ 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="d-flex flex-row justify-content-evenly" data-doctx="${pageName}">
	<div class="card mw-px-1000">
		<form name="frmEdit">
			<input type="text" name="crdnId" data-map="CRDN_ID" hidden />
			<input type="text" name="rtpyrId" data-map="RTPYR_ID" hidden />
			<input type="text" name="addrSn" data-map="ADDR_SN" hidden />
			<input type="text" name="sggCd" data-map="SGG_CD" hidden />
			<input type="text" name="taskSeCd" data-map="TASK_SE_CD" hidden />

			<div class="row mt-4 justify-content-end mb-3">
				<div class="col-md-12 ps-4 pe-4">
					<button type="button" name="btnReset" class="btn btn-outline-dark w-px-120">
					초기화
					</button>
					<span class="float-end">
						<input type="text" name="countStauts"
						class="form-control w-px-150 text-center fw-bold" readonly />
						<button type="button" name="btnPrev" class="w-px-50 btn-PageUp">◀</button>
						<button type="button" name="btnNext" class="w-px-50 btn-PageDown">▶</button>
					</span>
				</div>
			</div>

			<div class="row g-1">
				<div class="col-md-12" slot="edit">
					<template class="pvs bpv">
						<slot>
							<label is="name-label" for="crdnSeCd"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							단속구분
							</label>
							<select is="id-select" name="crdnSeCd"
							data-map="CRDN_SE_CD" class="form-select">
								<c:forEach items="${FIM002List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
				<div class="col-md-4">
					<label is="name-label" for="crdnYmd"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
						위반일자
					</label>
					<input type="text" is="id-input" name="crdnYmd" data-map="CRDN_YMD"
						class="form-control form-date" data-fmt-type="day" maxlength="10" required />
		            <button type="button" class="bx bx-lg bx-calendar bg-white"></button>
				</div>
				<div class="col-md-4">
					<label is="name-label" for="crdnTm"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end required">
						위반시간
					</label>
		            <input type="text" is="id-input" name="crdnTm" data-map="CRDN_TM"
		            	class="form-control form-time" data-fmt-type="time" maxlength="8" required
		            	placeholder="시:분:초" />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="vhrno" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
						차량번호
					</label>
					<input type="text" is="id-input" name="vhrno" data-map="VHRNO" class="form-control"
						data-maxlengthb="30" />
				</div>
				<div class="col-md-12">
					<span class="float-end">
						<button type="button" name="btnViewCrdnList" class="btn btn-outline-dark mx-2">
						동일번호&nbsp;<span name="outputCrdnCount"></span>건
						</button>
						<button type="button" name="btnViewCvlcptDscsnList" class="btn btn-outline-dark mx-2">
						차량민원&nbsp;<span name="outputCvlcptDscsnCount"></span>건
						</button>
					</span>
				</div>
				<div class="col-md-6">
					<label is="name-label" for="vltnCd" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
						위반내용
					</label>
					<select is="id-select" name="vltnCd" class="form-select" data-map="VLTN_CD">
						<c:forEach items="${VLTNList}" var="item">
							<option value="${item.code}">${item.value}</option>
		                </c:forEach>
					</select>
					<label is="name-label" for="dstrbncYn">
						<input type="checkbox" is="id-input" name="dstrbncYn"
						data-map="DSTRBNC_YN" value="Y" />
						1면 방해
					</label>
				</div>
				<div class="col-md-6 select2-primary">
					<label is="name-label" for="crdnStdgNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					법정동
					</label>
					<input type="text" is="id-input" name="crdnStdgNm" data-map="CRDN_STDG_NM"
					class="form-control" list="stdgNmList" />
					<datalist is="id-datalist" name="stdgNmList">
						<c:forEach items="${stdgNmList}" var="item">
							<option value="${item}"></option>
						</c:forEach>
					</datalist>
				</div>
				<div class="col-md-6">
					<label is="name-label" for="crdnPlc" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					단속장소
					</label>
					<input type="text" is="id-input" name="crdnPlc" data-map="CRDN_PLC"
						class="form-control w-px-300" data-maxlengthb="200" />
				</div>
				<div class="col-md-6" slot="edit">
					<template class="bpv">
						<slot>
							<label is="name-label" for="dtlCrdnPlc"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							상세단속장소
							</label>
							<input type="text" is="id-input" name="dtlCrdnPlc"
							data-map="DTL_CRDN_PLC" class="form-control"
								data-maxlenghb="200" />
						</slot>
					</template>
					<template class="pvs">
						<slot>
							<label is="name-label" for="crdnSpareaCd"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							특별구역
							</label>
							<select is="id-select" name="crdnSpareaCd"
							data-map="CRDN_SPAREA_CD" class="form-select">
								<c:forEach items="${FIM007List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
				<div class="col-md-6">
					<label is="name-label" for="cvlcptAplcntNm"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					신고자
					</label>
					<input type="text" is="id-input" name="cvlcptAplcntNm"
					data-map="CVLCPT_APLCNT_NM" class="form-control" readonly />
				</div>
				<div class="col-md-6">
					<label is="name-label" for="cvlcptPrcsPicNm"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					담당자
					</label>
					<input type="text" is="id-input" name="cvlcptPrcsPicNm"
					data-map="CVLCPT_PRCS_PIC_NM" class="form-control" readonly />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="cvlcptAplyCn"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end align-top"
					>신고내용</label>
					<textarea is="id-textarea" name="cvlcptAplyCn"
					data-map="CVLCPT_APLY_CN" class="form-control"
					cols="100%" rows="4" readonly
					></textarea>
				</div>
				<div class="col-md-6">
					<label is="name-label" for="cvlcptRcptYmd"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					접수일
					</label>
					<input type="text" is="id-input" name="cvlcptRcptYmd"
					data-map="CVLCPT_RCPT_YMD" class="form-control form-date"
					data-fmt-type="day" maxlength="10" disabled />
				</div>
				<div class="col-md-6">
					<label is="name-label" for="cvldptPrcsPrnmntDt"
						class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">답변기한</label>
					<input type="text" is="id-input" name="cvldptPrcsPrnmntDt"
					data-map="CVLCPT_PRCS_PRNMNT_DT" class="form-control form-date"
					data-fmt-type="day" maxlength="10" disabled />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="etcCn"
					class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					특기사항
					</label>
					<input type="text" is="id-input" name="etcCn" data-map="ETC_CN"
						class="form-control w-px-500" data-maxlengthb="1000" />
				</div>
			</div>
			<div class="row my-1 mx-4 g-1 border-card rounded-3">
				<div class="col-md-12">
					<div class="float-end">
						<button type="button" class="btn btn-primary" name="btnDeletePayer">
							납부자 초기화
						</button>
						<button type="button" class="btn btn-primary" name="btnPopPayer">
							납부자 수정
						</button>
					</div>
				</div>
				<div class="col-md-4">
					<label is="name-label" for="rtpyrNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					납부자명
					</label>
					<input type="text" is="id-input" name="rtpyrNm" data-map="RTPYR_NM"
						class="form-control w-px-140" readonly />
				</div>
				<div class="col-md-3">
					<label is="name-label" for="rtpyrSeCd" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					납부자구분
					</label>
					<select is="id-select" name="rtpyrSeCd"
					data-map="RTPYR_SE_CD" class="form-select" disabled>
						<c:forEach items="${FIM011List}" var="item">
							<option value="${item.code}">${item.value}</option>
		                </c:forEach>
					</select>
				</div>
				<div class="col-md-5">
					<label is="name-label" for="rtpyrNo" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					납부자번호
					</label>
					<input type="text" is="id-input" name="rtpyrNo" data-map="RTPYR_NO"
						class="form-control privacy" readonly />
					<input type="text" is="id-input" name="mask-rtpyrNo" class="form-control privacy-mask"
					disabled value="******"/>
				</div>
				<div class="col-md-12">
					<label is="name-label" for="zip" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					우편번호
					</label>
					<input type="text" is="id-input" name="zip" data-map="ZIP" class="form-control w-px-100"
						readonly maxlength="7" pattern="(\d{3}-\d{3}|\d{6}|\d{5})" />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="addr" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					주소
					</label>
					<input type="text" is="id-input" name="addr" data-map="ADDR"
						class="form-control w-px-700" readonly data-maxlengthb="320" />
				</div>
				<div class="col-md-12">
					<label is="name-label" for="dtlAddr" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					상세주소
					</label>
					<input type="text" is="id-input" name="dtlAddr" data-map="DTL_ADDR"
						class="form-control w-px-700" readonly data-maxlengthb="200" />
				</div>
			</div>
			<div class="row g-1">
				<div class="col-md-4">
					<label is="name-label" for="vin" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					차대번호
					</label>
					<input type="text" is="id-input" name="vin" data-map="VIN" class="form-control" readonly
						placeholder="입력항목이 아닙니다." />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="vhclNm" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					차량명칭
					</label>
					<input type="text" is="id-input" name="vhclNm"
					data-map="VHCL_NM" class="form-control" readonly
						placeholder="입력항목이 아닙니다." />
				</div>
				<div class="col-md-4">
					<label is="name-label" for="vhclColr" class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
					차량색상
					</label>
					<input type="text" is="id-input" name="vhclColr"
					data-map="VHCL_COLR" class="form-control" readonly
						placeholder="입력항목이 아닙니다." />
				</div>
				<div class="col-md-12" slot="edit">
					<template class="pvs bpv">
						<slot>
							<label is="name-label" for="ffnlgCarmdlCd"
							class="w-px-150 bg-lighter pe-2 col-form-label text-sm-end">차종</label>
							<select is="id-select" name ="ffnlgCarmdlCd"
							data-map="FFNLG_CARMDL_CD" class="form-select">
								<option value=""></option>
								<c:forEach items="${FIM009List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
				<div class="col-md-12" slot="edit">
					<template class="eca">
						<slot>
							<label is="name-label" for="useFuelCd"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							연료구분
							</label>
							<select is="id-select" name="useFuelCd"
							data-map="USE_FUEL_CD" class="form-select" disabled>
								<option value=""></option>
								<c:forEach items="${LVS005List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
				<div class="col-md-4" slot="edit">
					<template class="dpv eca pvs">
						<slot>
							<label is="name-label" for="towngYn"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							견인지시
							</label>
							<select is="id-select" name="towngYn" class="form-select" data-map="TOWNG_YN">
								<c:forEach items="${FIM053List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
				<div class="col-md-4" slot="edit">
					<template class="dpv eca pvs">
						<slot>
							<label is="name-label" for="crdnSn"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							스티커번호
							</label>
							<input type="text" is="id-input" name="crdnSn"
							data-map="CRDN_SN" class="form-control"
								maxlength="20" data-maxlengthb="20" />
						</slot>
					</template>
				</div>
				<div class="col-md-4" slot="edit">
					<template class="dpv">
						<slot>
							<label is="name-label" for="prkPsbltyRsltCd"
							class="w-px-130 bg-lighter pe-2 col-form-label text-sm-end">
							장애차량확인
							</label>
							<select is="id-select" name="prkPsbltyRsltCd"
							data-map="PRK_PSBLTY_RSLT_CD" class="form-select">
								<c:forEach items="${FIM034List}" var="item">
									<option value="${item.code}">${item.value}</option>
				                </c:forEach>
							</select>
						</slot>
					</template>
				</div>
			</div>

			<div class="row mt-4 justify-content-end mb-3">
				<div class="col-md-12">
					<div class="float-end pe-4">
						<button type="button" name="btnInstLevyExcl1" class="btn btn-primary">
						저장(서손처리)
						</button>
						<button type="button" name="btnInstLevyExcl2" class="btn btn-primary">
						저장(계도처리)
						</button>
						<button type="button" name="btnAccept" class="btn btn-primary">
						저장(수용)
						</button>
						<button type="button" name="btnSendBack" class="btn btn-primary">
						반송
						</button>
						<button type="button" name="btnDataCopy" class="btn btn-primary">
						자료복사
						</button>
						<button type="button" name="btnHold" class="btn btn-primary">
						처리보류
						</button>
						<button type="button" name="btnOpenCvlcptOrgnl" class="btn btn-primary">
						원본보기
						</button>
					</div>
				</div>
			</div>

		</form>
	</div>

	<jsp:include page="/WEB-INF/jsp/fims/photo-main.jsp" />
	<div name="refreshEnd" class="parentGrid" hidden></div>
</div>


<script>
LoadScript("cvlc01020Script",wctx.url("/resources/js/fims/cvlc/cvlc01020.js?ver=${ver}"));

/**************************************************************************
* Global Variable
**************************************************************************/
pageObject["${pageName}"] = newDoctxFinder("${pageName}");
pageObject["${pageName}"].provided = {};

pageObject.childReq = [];
pageObject.childReq.push({
	getCountStatus : function(){ return ""; },
	getNextKey : function(){ return ""; },
	getPrevKey : function(){ return ""; },
	selectRow : function(){},
	holdRow : function(){},
	refreshList : function(){},
	hasData : function(){ return true; }
});

$(document).ready(function(){

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

	$P.$findn("photoMainWrapper").addClass("w-px-550 min-w-px-550");

	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 = newCvlc01020Control($P, { taskSeCd : "${taskSeCd}" });

	ctrl.dataset.onCurrentChange = (dataItem) => {
		$P.formFields.set(ctrl,dataItem);
	}


	/**************************************************************************
	* pageObject.function
	**************************************************************************/

	$P.openLevyExclPop = (levyExclSeCd) => {

		if(levyExclSeCd == "2"){
			var rtpyrNm = $P.findn("rtpyrNm");

			if(rtpyrNm.value == ""){
				dialog.alert({
					content:"계도 처리를 하기 위해선 소유주정보가 입력되어야 합니다.",
					init : function() {
						AppSupport.setDialogZindex();
						AppSupport.focusClose();
					},
					onClose:function(){rtpyrNm.focus();}
				});
				return;
			}
		}

		var crdnId = $P.$findn("crdnId").val();
		var sggCd = $P.$findn("sggCd").val();
		var taskSeCd = $P.$findn("taskSeCd").val();

		var params = {
			"saveCallbackFuncName" : "pageObject['${pageName}']['exclSaveCallback']",
			"callPurpose" : "create",
			"crdnId" : crdnId,
			"sggCd" : sggCd,
			"taskSeCd" : taskSeCd,
			"levyExclSeCd" : levyExclSeCd
		};

		ajax.get({
			url : wctx.url("/excl/excl01/020/info.do"),
			data : params,
			success : (resp) => {

				let dialogName = "levyExclDialog";
				let dialogId = dialogName+"-"+uuid();

				dialog.open({
					id : dialogId,
					title : "부과제외 정보",
					content : resp,
					size : "md",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

						AppSupport.setDialogZindex();
					},
					onClose : () => {}
				});
			}
		});
	};

	$P.save = (info, accept) => {
		if (!info) return;

		if(accept){
			info.acceptYn = "Y";
		} else {
			info.acceptYn = "N";
		}

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

	$P.exclSaveCallback = function(exclInfo){

		var mergeInfo = $P.formFields.get();

		mergeInfo.etcCn = exclInfo.etcCn;
		mergeInfo.levyExclId = exclInfo.levyExclId;
		mergeInfo.levyExclYmd = exclInfo.levyExclYmd;
		mergeInfo.levyExclRsnCd = exclInfo.levyExclRsnCd;
		mergeInfo.levyExclSeCd = exclInfo.levyExclSeCd;

		$P.save(mergeInfo, false);
	}

	$P.saveCallback = (resp) => {
		if (resp.saved) {

			dialog.alert({
				content : "저장됐습니다.",
				init : function() {
					AppSupport.setDialogZindex();
					AppSupport.focusClose();
				}
			});

			if($P.refDlgId("levyExclDialog") != ""){
				dialog.close($P.refDlgId("levyExclDialog"));
			}

			var crdnId = $P.$findn("crdnId").val();

			var cursorKey = "";

			var nextKey = $P.provided.getNextKey(crdnId);
	    	if(nextKey != ""){
	    		cursorKey = nextKey;
	    	} else {
	    		var prevKey = $P.provided.getPrevKey(crdnId);
				if(prevKey != ""){
					cursorKey = prevKey;
				}
	    	}

	    	$P.$findn("refreshEnd").attr("data-cursor-key", cursorKey);
			$P.provided.refreshList();
		}
	};

	$P.fnPrev = () => {
		var prevKey = $P.provided.getPrevKey($P.$findn("crdnId").val());
		if(prevKey != ""){
			$P.fnGo(prevKey);
		}
	}

	$P.fnNext = () => {
		var nextKey = $P.provided.getNextKey($P.$findn("crdnId").val());
		if(nextKey != ""){
			$P.fnGo(nextKey);
		}
	}

	$P.fnGo = (crdnId) => {
		ajax.get({
			url: ctrl.urls.getInfo,
			data: { "crdnId" : crdnId },
			headers: {
			    Accept: "application/json; charset=utf-8"
			},
			success : (resp) => {
				var crdnInfo = resp.crdnInfo;
				crdnInfo.CVLCPT_APLY_CN = StringSupport.escapeHTMLEntity(crdnInfo.CVLCPT_APLY_CN);
				ctrl.dataset.setData([crdnInfo]);

				$P.$findn("btnViewCrdnList").attr("hidden","hidden");
				$P.$findn("btnViewCvlcptDscsnList").attr("hidden","hidden");

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

				var cs = $P.provided.getCountStatus($P.$findn("crdnId").val());
				$P.$findn("countStauts").val(cs);
				$P.provided.selectRow(crdnId);


				var existVideo = false;
				if(crdnInfo.VIDEO_EXIST_YN == "Y"){
					existVideo = true;
				}
				initPhotoMain("${pageName}", crdnInfo.fileList, existVideo);

			}
		});
	}

	$P.fnCopy = async() => {
		var crdnId = $P.$findn("crdnId").val();

		if(await confirm2("현 자료의 복사본을 생성하시겠습니까?")){

			ajax.get({
				url : ctrl.urls.create,
				data : { crdnId : crdnId },
				success : (resp) => {
					if (resp.saved) {
						dialog.alert({
							content : "복사 자료가 생성되었습니다.",
							init : function() {
								AppSupport.setDialogZindex();
								AppSupport.focusClose();
							}
						});

						$P.$findn("refreshEnd").attr("data-cursor-key", crdnId);
						$P.provided.refreshList();
					}
				}
			});
		}

	}

	$P.fnOpenCvlcptOrgnl = () => {
		var crdnId = $P.$findn("crdnId").val();

		ajax.get({
			url : wctx.url("/cvlc/cvlc01/050/info.do"),
			data : { crdnId : crdnId },
			success : (resp) => {

				let dialogName = "cvlcptOrgnlDialog";
				let dialogId = dialogName+"-"+uuid();

				dialog.open({
					id : dialogId,
					title : "민원내역 원본",
					content : resp,
					size : "xl",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

						AppSupport.setDialogZindex();
					}
				});
			}
		});
	}

	$P.fnHold = () => {
		var crdnId = $P.$findn("crdnId").val();

		$P.provided.holdRow(crdnId);

		var nextKey = $P.provided.getNextKey(crdnId);
    	if(nextKey != ""){
    		$P.fnGo(nextKey);
    		return;
    	}
    	var prevKey = $P.provided.getPrevKey(crdnId);
		if(prevKey != ""){
			$P.fnGo(prevKey);
			return;
		}

		dialog.close($P.selfDlgId());
	}

	//납부자 삭제
	$P.fnDeletePayer = () => {
		//
	}

	//납부자 등록,수정
	$P.fnPopPayer = () => {
		var callPurpose = "";
		var dialogTitle = "";
		if($P.$findn("rtpyrId").val() == null || $P.$findn("rtpyrId").val() == ""){
			callPurpose = "create";
			dialogTitle = "납부자 등록";
		} else {
			callPurpose = "update";
			dialogTitle = "납부자 수정";
		}

		var params = {
			callPurpose		: callPurpose,
			crdnId			: $P.$findn("crdnId").val(),			// 단속 ID
			sggCd			: $P.$findn("sggCd").val(),			// 시군구 코드
			taskSeCd		: $P.$findn("taskSeCd").val(),		// 업무 구분 코드
			rtpyrId			: $P.$findn("rtpyrId").val(),			// 납부자 ID
			addrSn			: $P.$findn("addrSn").val(),			// 주소 일련번호
			vhrno			: $P.$findn("vhrno").val(),			// 차량번호
			rtpyrInptSeCd	: "01",										// 납부자 입력 구분 코드
			delYn			: "N"
		};

		ajax.get({
			url : wctx.url("/payer/info.do"),
			data : params || {},
			success : (resp) => {

				let dialogName = "payerDialog";
				let dialogId = dialogName+"-"+uuid();

				dialog.open({
					id : dialogId,
					title : dialogTitle,
					content : resp,
					size : "lg",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

					},
					onClose : () => { $P.refreshPayer(); }	// callback
				});
			}
		});

	}

	$P.refreshPayer = () => {

		var params = {
			callPurpose	: "refresh",
			crdnId		: $P.$findn("crdnId").val(),
			sggCd		: $P.$findn("sggCd").val(),
			taskSeCd	: $P.$findn("taskSeCd").val(),
			delYn		: "N"
		};

		ajax.get({
			url : wctx.url("/sprt/sprt02/020/info.do"),
			headers: { Accept: "application/json; charset=utf-8" },
			data : params || {},
			success : (resp) => {

				if (resp.crdnPayer) {
					var payer = resp.crdnPayer;
					$P.$findn("rtpyrId").val(payer.RTPYR_ID).change();
					$P.$findn("addrSn").val(payer.ADDR_SN).change();
					$P.$findn("rtpyrNm").val(payer.RTPYR_NM).change();
					$P.$findn("rtpyrSeCd").val(payer.RTPYR_SE_CD).change();
					$P.$findn("rtpyrNo").val(payer.RTPYR_NO).change();
					$P.$findn("zip").val(payer.ZIP).change();
					$P.$findn("addr").val(payer.ADDR).change();
					$P.$findn("dtlAddr").val(payer.DTL_ADDR).change();
				} else {
					$P.$findn("rtpyrId").val("").change();
					$P.$findn("addrSn").val("").change();
					$P.$findn("rtpyrNm").val("").change();
					$P.$findn("rtpyrSeCd").val("").change();
					$P.$findn("rtpyrNo").val("").change();
					$P.$findn("zip").val("").change();
					$P.$findn("addr").val("").change();
					$P.$findn("dtlAddr").val("").change();
				}
			}
		});

	}

	$P.fnReset = () => {
		var crdnId = $P.$findn("crdnId").val();

		$P.fnGo(crdnId);
	}

	$P.fnAccept = async() => {

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

		var vhrno = $P.findn("vhrno");
		var rtpyrNm = $P.findn("rtpyrNm");

		if(vhrno.value == ""){
			dialog.alert({
				content:"수용 처리를 하기 위해선 차량번호가 입력되어야 합니다.",
				init : function() {
					AppSupport.setDialogZindex();
					AppSupport.focusClose();
				},
				onClose:function(){vhrno.focus();}
			});
			return;
		}

		if(rtpyrNm.value == ""){
			dialog.alert({
				content:"수용 처리를 하기 위해선 소유주정보가 입력되어야 합니다.",
				init : function() {
					AppSupport.setDialogZindex();
					AppSupport.focusClose();
				},
				onClose:function(){rtpyrNm.focus();}
			});
			return;
		}

		if(await confirm2("현재 단속 정보를 저장하시겠습니까?")){
			$P.save($P.formFields.get(), true);
		}

	};


	$P.fnSendBack = async() => {
		if(!await confirm2("반송 처리 하시겠습니까?")){
			return;
		}

		var crdnId = $P.$findn("crdnId").val();

		ajax.post({
			url : ctrl.urls.remove,
			data : { crdnId : crdnId },
			success : (resp) => {
				if(resp.saved){
					var message = "민원회수 요청이 등록되었습니다.\n"
						+"30~60분 사이에 서버에서 민원시스템으로 전송이 진행되니 이후에 민원시스템에서 확인하시기 바랍니다.";

					dialog.alert({
						content : message,
						init : function() {
							AppSupport.setDialogZindex();
							AppSupport.focusClose();
						}
					});


					var crdnId = $P.$findn("crdnId").val();

					var cursorKey = "";

					var nextKey = $P.provided.getNextKey(crdnId);
			    	if(nextKey != ""){
			    		cursorKey = nextKey;
			    	} else {
			    		var prevKey = $P.provided.getPrevKey(crdnId);
						if(prevKey != ""){
							cursorKey = prevKey;
						}
			    	}

			    	$P.$findn("refreshEnd").attr("data-cursor-key", cursorKey);
					$P.provided.refreshList();
				}
			}
		});
	}


	/**************************************************************************
	 * 초기화(업무별 입력항목)
	 **************************************************************************/
	var clsForTask = "${taskSeCd}".toLowerCase();

	//업무별 입력 항목
	FimsSupport.renderForTask($P.findn("frmEdit"), clsForTask);

	/**************************************************************************
	 * element.on
	 **************************************************************************/
	$P.$findn("btnReset").on("click", () => $P.fnReset() );
	$P.$findn("btnPrev").on("click", () => $P.fnPrev() );
	$P.$findn("btnNext").on("click", () => $P.fnNext() );

	//업무처리 버튼
	$P.$findn("btnSendBack").on('click', () => { $P.fnSendBack(); });
	$P.$findn("btnInstLevyExcl1").on("click", () => $P.openLevyExclPop("1"));
	$P.$findn("btnInstLevyExcl2").on("click", () => $P.openLevyExclPop("2"));
	$P.$findn("btnDataCopy").on("click", () => $P.fnCopy());
	$P.$findn("btnAccept").on('click', () => $P.fnAccept());
	$P.$findn("btnHold").on("click", () => $P.fnHold());
	$P.$findn("btnOpenCvlcptOrgnl").on("click", () => $P.fnOpenCvlcptOrgnl());

	//납부자 삭제
	$P.$findn("btnDeletePayer").on("click", () => $P.fnDeletePayer());
	//납부자 등록, 수정
	$P.$findn("btnPopPayer").on("click", () => $P.fnPopPayer());

	$P.$findn("vhrno").onEnterPress(function(){
		$P.getVehicleTotalInfo(event.target);
	});

	//차적조회(단속내역,민원상담내역,차적기본조회,장애인표지조회)
	$P.getVehicleTotalInfo = async function(vhrnoEl){
		var otherWindow = false;
		if($(vhrnoEl).parents("[data-doctx='${pageName}']").length < 1){
			otherWindow = true;
		}

		var taskSeCd = "${taskSeCd}";
		var crdnYmd = $P.$findn("crdnYmd").val().replaceAll("-", "");
		var vhrno = vhrnoEl.value;

		if(crdnYmd == ""){
			if(!otherWindow){
				dialog.alert({
					content:"단속일자를 입력하세요.",
					init : function() {
						AppSupport.setDialogZindex();
						AppSupport.focusClose();
					},
					onClose:function(){ $P.$findn("crdnYmd").focus(); }
				});
				return;
			} else {
				return {
					msg : "단속일자를 입력하세요."
				};
			}
		}

		if(vhrno == ""){
			if(!otherWindow){
				dialog.alert({
					content:"차량번호를 입력하세요.",
					init : function() {
						AppSupport.setDialogZindex();
						AppSupport.focusClose();
					},
					onClose:function(){ $(vhrnoEl).focus(); }
				});
				return;
			} else {
				return {
					msg : "차량번호를 입력하세요."
				};
			}
		}

		var sggCd = $P.$findn("sggCd").val();
		var resp = null;

		//
		resp = await FimsSupport.countCrdnByVhrno(vhrno, taskSeCd, sggCd);
		if(resp.crdnCount > 0){
			$P.$findn("outputCrdnCount").html(resp.crdnCount);
			$P.$findn("btnViewCrdnList").removeAttr("hidden");
		} else {
			$P.$findn("btnViewCrdnList").attr("hidden","hidden");
		}

		//
		resp = await FimsSupport.countCvlcptDscsnByVhrno(vhrno, taskSeCd, sggCd);
		if(resp.cvlcptDscsnNocs.NOCS > 0){
			$P.$findn("outputCvlcptDscsnCount").html(resp.cvlcptDscsnNocs.NOCS);
			$P.$findn("btnViewCvlcptDscsnList").removeAttr("hidden");
		} else {
			$P.$findn("btnViewCvlcptDscsnList").attr("hidden","hidden");
		}

		//
		resp = await FimsSupport.getVhclInfo(sggCd, vhrno, crdnYmd);

		if(otherWindow){
			$P.$findn("vhrno").val(vhrno);
		}

		if(!resp.found){

			$P.$findn("rtpyrId").val("");
			$P.$findn("addrSn").val("");
			$P.$findn("rtpyrNm").val("");
			$P.$findn("rtpyrSeCd").val("");
			$P.$findn("rtpyrNo").val("");
			$P.$findn("vin").val("");
			$P.$findn("vhclNm").val("");
			$P.$findn("vhclColr").val("");
			$P.$findn("useFuelCd").val("");
			$P.$findn("ffnlgCarmdlCd").val("");
			$P.$findn("zip").val("");
			$P.$findn("addr").val("");
			$P.$findn("dtlAddr").val("");

			if(!otherWindow){
				dialog.alert({
					content : "차량 정보가 없습니다.",
					init : function() {
						AppSupport.setDialogZindex();
						AppSupport.focusClose();
					}
				});
				return;
			} else {
				return {
					vhrno : "",
					vhclNm : "",
					vhclColr : ""
				};
			}
		}

		$P.$findn("rtpyrId").val(resp.rtpyrId);
		$P.$findn("addrSn").val(resp.addrSn);

		var vehicle = resp.vehicle;

		$P.$findn("rtpyrNm").val(vehicle.mber_nm);

		var pyrSeCd = "";
		switch(vehicle.mber_se_code){
			case "11" : pyrSeCd = "01"; break;
			case "12" : pyrSeCd = "02"; break;
			case "13" : pyrSeCd = "03"; break;
			case "14" : pyrSeCd = "04"; break;
			case "15" : pyrSeCd = "05"; break;
		}
		$P.$findn("rtpyrSeCd").val(pyrSeCd);

		$P.$findn("rtpyrNo").val(vehicle.mber_se_no);

		$P.$findn("vin").val(vehicle.vin);
		$P.$findn("vhclNm").val(vehicle.cnm);
		$P.$findn("vhclColr").val(vehicle.color_nm);
		$P.$findn("useFuelCd").val(vehicle.use_fuel_code);

		if(vehicle.vhcty_asort_code == "1"){ //승용
			$P.$findn("ffnlgCarmdlCd").val("11");
		} else if(vehicle.vhcty_asort_code == "2"){ //승합
			$P.$findn("ffnlgCarmdlCd").val("12");
		} else if(vehicle.vhcty_asort_code == "3"){ //화물
			if(vehicle.mxmm_ldg <= 4000){
				$P.$findn("ffnlgCarmdlCd").val("13");
			} else {
				$P.$findn("ffnlgCarmdlCd").val("14");
			}
		} else if(vehicle.vhcty_asort_code == "4"){ //특수
			$P.$findn("ffnlgCarmdlCd").val("15");
		} else {
			$P.$findn("ffnlgCarmdlCd").val("");
		}

		$P.$findn("zip").val(vehicle.zip_code); //우편번호
		$P.$findn("addr").val(vehicle.road_nm_adres); //주소
		$P.$findn("dtlAddr").val(vehicle.use_strnghld_adres_nm); //상세주소

		if(taskSeCd == "DPV"){
			resp = await FimsSupport.getVhclDisabledParkingInfo(vhrno);

			if(resp.parkingInfo.BOHUN_PARKING_PSBL_YN == "Y" || resp.parkingInfo.PARKING_PSBL_YN == "Y") {
				$P.$findn("prkPsbltyRsltCd").val("2");
			} else {
				$P.$findn("prkPsbltyRsltCd").val("1");
			}

		}

		if(otherWindow){
			return {
				vhrno : $P.$findn("vhrno").val(),
				vhclNm : $P.$findn("vhclNm").val(),
				vhclColr : $P.$findn("vhclColr").val()
			};
		} else {
			return;
		}
	};

	//단속내역 보기
	$P.$findn("btnViewCrdnList").on("click", function(){
		ajax.get({
            url: wctx.url("/crdn/crdn06/010/main.do"),
            data: {
				openType : "D",
				taskSeCd : "${taskSeCd}",
				vhrno : $P.$findn("vhrno").val()
            },
            success: function(resp) {

            	let dialogName = "crdnListDialog";
				let dialogId = dialogName+"-"+uuid();

            	dialog.open({
					id : dialogId,
					title : "동일차량 단속 내역",
					content : resp,
					size : "xxl",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

						AppSupport.setDialogZindex();

						$(document).find("div.modal").last().on('shown.bs.modal', function () {
							let refDlgId = $P.refDlgId("crdnListDialog");
							$("#"+refDlgId).find("[name='schCrdnYmdFrom']").set("");
							$("#"+refDlgId).find("[name='schCrdnYmdTo']").set("");
							$("#"+refDlgId).find("[name='vhrno']").set($P.$findn("vhrno").val());
							$("#"+refDlgId).find(".btn-search").eq(0).click();
						});
					},
					onClose : () => {}
				});
            }
        });
	});

	//민원내역 보기
	$P.$findn("btnViewCvlcptDscsnList").on("click", function(){
		ajax.get({
            url: wctx.url("/sprt/sprt04/010/main.do"),
            data: {
				openType : "D",
				taskSeCd : "${taskSeCd}",
				vhrno : $P.$findn("vhrno").val()
            },
            success: function(resp) {

            	let dialogName = "cvlcptDscsnListDialog";
				let dialogId = dialogName+"-"+uuid();

            	dialog.open({
					id : dialogId,
					title : "민원상담 내역",
					content : resp,
					size : "xxl",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");

						AppSupport.setDialogZindex();

						$(document).find("div.modal").last().on('shown.bs.modal', function () {
							let refDlgId = $P.refDlgId("crdnListDialog");
							$("#"+refDlgId).find("[name='schDscsnYmdFrom']").set("");
							$("#"+refDlgId).find("[name='schDscsnYmdTo']").set("");
							$("#"+refDlgId).find("[name='schVhrno']").set($P.$findn("vhrno").val());
							$("#"+refDlgId).find(".btn-search").eq(0).click();
						});
					},
					onClose : () => {}
				});
            }
        });
	});


	if("${taskSeCd}" == "DPV"){
		$P.$findn("vltnCd").on("change", function(){
			if(this.value == "01"){
				$P.$findn("dstrbncYn").show();
			} else {
				$P.$findn("dstrbncYn").hide();
				$P.$findn("dstrbncYn").prop("checked", false);
			}
		});
	}

	$P.$findn("refreshEnd").on("refreshEnd", function(){

		if(this.dataset.cursorKey == null || this.dataset.cursorKey == ""){
			dialog.close($P.selfDlgId());
			return;
		}

		if(!$P.provided.hasData(this.dataset.cursorKey)){
			dialog.close($P.selfDlgId());
			return;
		}

		$P.fnGo(this.dataset.cursorKey);
	});

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

	$P.$findn("frmEdit").find(".form-time").each(function(){
		$(this).on("input",function(){
			var value = this.value.replaceAll(":","");

			if(value.length > 5){
				this.value = value.substring(0,2)+":"+value.substring(2,4)+":"+value.substring(4);
			} else if(value.length > 3){
				this.value = value.substring(0,2)+":"+value.substring(2);
			}

		});
	});

	$P.$findn("btnViewCrdnList").attr("hidden","hidden");
	$P.$findn("btnViewCvlcptDscsnList").attr("hidden","hidden");

	var crdnInfo = ${crdnInfo};
	crdnInfo.CVLCPT_APLY_CN = StringSupport.escapeHTMLEntity(crdnInfo.CVLCPT_APLY_CN);
	ctrl.dataset.setData([crdnInfo]);

	if($P.$findn("taskSeCd").val() == "DPV" && $P.$findn("vltnCd").val() == "01"){
		$P.$findn("dstrbncYn").show();
	} else {
		$P.$findn("dstrbncYn").hide();
	}

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

	var cs = $P.provided.getCountStatus($P.$findn("crdnId").val());
	$P.$findn("countStauts").val(cs);


	//사진영역 설정
	settingPhotoMain("${pageName}", $P.findn("crdnId"),
		function(){
			return {
				vhrno : $P.$findn("vhrno").val(),
				vhclNm : $P.$findn("vhclNm").val(),
				vhclColr : $P.$findn("vhclColr").val()
			};
		},
		async function(vhrnoEl){
			return await $P.getVehicleTotalInfo(vhrnoEl);
		}
	);



	//사진영역 초기화
	var existVideo = false;
	if(crdnInfo.VIDEO_EXIST_YN == "Y"){
		existVideo = true;
	}
	initPhotoMain("${pageName}", crdnInfo.fileList, existVideo);

});

</script>