<%@ 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="content-wrapper" data-doctx="${pageName}">
	<div class="container-xxl flex-grow-1 px-0">
		<div class="card wrapper-list">

		    <div class="container-page-btn">
		        <button type="button" name="btnReset" class="btn btn-outline-dark w-px-120" title="초기화">초기화</button>
		        <div class="w-100 d-flex justify-content-center">
			        <div class="btn-group">
				        <button type="button" name="btnPhotoInspection" class="btn btn-blue btn-outline-some" title="단속사진 비교">단속사진 비교</button>
				        <button type="button" name="btnSameVehicleInspection" class="btn btn-blue btn-outline-some" title="동일단속차량 검사">동일단속차량 검사</button>
			        </div>
		        </div>
		        <span class="container-window-btn-right">
		            <button type="button" name="btnSearch"
		            class="btn btn-search w-px-120" title="검색">검색</button>
		            <button type="button" name="btnExcel" class="btn btn-excel w-px-120" title="엑셀 저장">엑셀</button>
		        </span>
		    </div>

		    <form name="frmSearch">
		        <div class="container-search">
                    <div class="row g-1">
                    	<jsp:include page="/WEB-INF/jsp/include/sgg-tasklist.jsp" />
                        <div class="col-6">
							<label class="form-label fw-bold form-search-title w-px-120 text-end">단속일자</label>
                        	<span class="form-search-linebox">
                                <input type="text" name="schCrdnYmdFrom"
                                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="schCrdnYmdTo"
                                class="form-control form-date"
                                	data-fmt-type="day" title="종료 날짜 선택">
                                <button type="button" class="bx bx-lg bx-calendar bg-white"></button>
                            </span>
                        </div>
                        <div class="col-6">
                            <label is="name-label" for="crdnInptSeCd" class="form-label fw-bold form-search-title w-px-120 text-end">단속구분</label>
                            <select is="id-select" name="crdnInptSeCd" class="form-select">
                            	<option value="">전체</option>
                            	<c:forEach items="${FIM003List}" var="item">
                            		<option value="${item.code}">${item.value}</option>
                            	</c:forEach>
                            </select>
                        </div>
                        <div class="col-6">
                        	<label is="name-label" for="vhrno" class="form-label fw-bold form-search-title w-px-120 text-end">차량번호</label>
                            <input type="text" is="id-input" name="vhrno" class="form-control" />
                        </div>
                        <div class="col-6">
                        	<span class="area-samevehicleinspection">
	                        	<span class="form-label fw-bold form-search-title w-px-120 text-end">단속건수</span>
	                        	<input type="text" name="schCrdnCntFrom" class="form-control w-px-50" placeholder="2" />
	                        	~ <input type="text" name="schCrdnCntTo" class="form-control w-px-50"/>
                        	</span>
                        </div>
                        <div class="col-6">
                        	<label>
                        		<input type="checkbox" name="schExclEnd" class="form-check-input" />
                        		서손자료제외
							</label>
                        	<label class="area-samevehicleinspection">
                        		<input type="checkbox" name="schOnlySamePlace" class="form-check-input" />
                        		동일장소만조회
							</label>
							<label class="area-photoinspection">
                        		<input type="checkbox" name="schOnlyUnpay" class="form-check-input" />
                        		미납만조회
							</label>
							<span slot="search">
								<template class="pvs">
									<slot>
										<label class="area-photoinspection">
			                        		<input type="checkbox" name="schExclOvtime" class="form-check-input" />
			                        		2시간초과 처리 자료 제외
										</label>
									</slot>
								</template>
							</span>
                        </div>
						<!-- 동적검색 -->
						<div class="col-6">
                        	<input type="hidden" name="by" />
							<input type="text" class="form-control fw-bold w-px-120 text-end" name="byOutput" value="동적 검색" readonly />
							<input type="hidden" name="mainOption" />
							<input type="hidden" name="subOption" />
							<input type="text" class="form-control w-px-400" name="term" autocomplete="off" />
							<!-- 상세 검색조건 버튼 -->
							<span class="flr">
								<button type="button" class="btn btn-open-detail" data-bs-toggle="collapse"
								data-bs-target="[data-doctx='${pageName}'] [name='searchDetail']">
									<i class="bx bx-chevron-down"></i>
									상세검색
								</button>
							</span>
						</div>
                    </div>
		        </div>
		        <div name="searchDetail" class="container-search container-search-detail collapse">
		            <div class="row">
			            <div class="col-4">
			                <label is="name-label" for="crdnSttsCd" class="form-label fw-bold form-search-title w-px-120 text-end">자료상태</label>
                            <select is="id-select" name="crdnSttsCd" class="form-select">
                            	<option value="">전체</option>
                            	<c:forEach items="${FIM010List}" var="item">
                            		<option value="${item.code}">${item.value}</option>
                            	</c:forEach>
                            </select>
			            </div>
						<!-- 등록일자, 수정일자 -->
						<div class="col-4">
							<select class="form-select w-px-120 text-center" name="schRegDateOpt">
								<option value="regDt">등록일자</option>
								<option value="mdfcnDt">수정일자</option>
							</select>
							<span class="form-search-linebox">
								<input type="text" class="form-control form-date" name="schRegDateFrom"
                                	data-fmt-type="day" title="시작 날짜 선택" />
								<button type="button" class="bx bx-lg bx-calendar bg-white"></button>
                                ~
								<input type="text" class="form-control form-date" name="schRegDateTo"
                                	data-fmt-type="day" title="종료 날짜 선택">
								<button type="button" class="bx bx-lg bx-calendar bg-white"></button>
							</span>
						</div>
						<!-- 등록자명, 수정자명 -->
						<div class="col-4">
							<select class="form-select w-px-120 text-center" name="schRgtrOpt">
								<option value="rgtr">등록자</option>
								<option value="mdfr">수정자</option>
							</select>
							<input type="hidden" name="schRgtrCd" />
							<input type="text" class="form-control w-px-160" name="schRgtrNm" />
							<button type="button" class="btn btn-sm btn-outline-dark"
							name="btnFindUser" title="사용자 검색">검색</button>
						</div>
			        </div>
		        </div>
		    </form>

	        <div name="gridbuttonArea" class="container-page-btn">
	        	<div class="d-flex flex-row justify-content-between area-photoinspection">
					<span is="paging-info" name="photoInspectionPagingInfo" class="dataTables_info"></span>
	                <ul name="photoInspectionPaging" class="pagination pagination-primary"></ul>
				</div>

				<div class="d-flex flex-row justify-content-between area-samevehicleinspection">
					<span is="paging-info" name="sameVehicleInspectionMainPagingInfo" class="dataTables_info"></span>
	                <ul name="sameVehicleInspectionMainPaging" class="pagination pagination-primary"></ul>
				</div>

	            <span class="container-window-btn-right">
					<button type="button" name="btnInstLevyExcl" class="btn btn-primary"
					title="비부과 등록">부과 제외</button>
					<span slot="button">
						<template class="pvs">
							<slot>
								<button name="btnOpenOverTime"
								class="btn btn-primary area-photoinspection"
								title="2시간 초과 처리">2시간 초과 처리</button>
							</slot>
						</template>
					</span>
	            </span>
	        </div>

			<div class="card-datatable text-nowrap area-photoinspection">
		        <div class="dataTables_wrapper dt-bootstrap5 no-footer">
					<div name="photoInspection-responsive" class="table-responsive ox-scroll oy-scroll h-px-200">
						<table name="photoInspectionTable"
							class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
							<thead class="sticky-thead">
								<tr data-search-target="[data-doctx='${pageName}']">
									<th style="width: 80px;">No.</th>
									<th onclick="FimsSupport.searchFromGridTitle('CRDN_YMD','단속일자','ymd','');"
									style="width: 180px;">단속일시</th>
									<th onclick="FimsSupport.searchFromGridTitle('VHRNO',this.innerText,'match','part');"
									style="width: 120px;">차량번호</th>
									<th style="width: 100px;" class="text-orange">면제차량</th>
									<th style="width: 100px;" class="text-orange">위반건수</th>
									<th style="width: 100px;" class="text-orange">검사결과</th>
									<th style="width: 250px;" class="text-orange">처리방법</th>
									<th onclick="FimsSupport.searchFromGridTitle('CRDN_STDG_NM',this.innerText,'match','perfect');"
									style="width: 100px;">위반동</th>
									<th onclick="FimsSupport.searchFromGridTitle('CRDN_PLC',this.innerText,'match','part');"
									style="width: 300px;">단속장소</th>
									<th onclick="FimsSupport.searchFromGridTitle('ATCH_FILE_CNT',this.innerText,'match','perfect');"
									style="width: 100px;">사진매수</th>
									<th onclick="FimsSupport.searchFromGridTitle('CRDN_STTS_CD',this.innerText,'codeValue','FIM010');"
									style="width: 120px;">처리상태</th>
									<th onclick="FimsSupport.searchFromGridTitle('FFNLG_CRDN_AMT',this.innerText,'match','perfect');"
									style="width: 100px;">원금액</th>
									<th onclick="FimsSupport.searchFromGridTitle('ADVNTCE_AMT',this.innerText,'match','perfect');"
									style="width: 100px;">감경금액</th>
									<th onclick="FimsSupport.searchFromGridTitle('CRDN_INPT_SE_CD',this.innerText,'codeValue','FIM003');"
									style="width: 120px;">자료출처</th>
									<th class="dummy-th"></th>
								</tr>
		                    </thead>
		                    <tbody name="photoInspectionTbody"></tbody>
							<template is="curly-brackets" name="photoInspectionRow">
								<tr data-index="DATA-INDEX">
									<td onclick ondblclick class="text-center">ROW_NUM</td>
									<td onclick ondblclick class="text-center">CRDN_YMD_TM</td>
									<td onclick ondblclick class="text-center">VHRNO</td>
									<td onclick ondblclick class="text-center">EXMPTN</td>
									<td onclick ondblclick class="text-center">CRDN_CNT</td>
									<td onclick ondblclick class="text-center">INSP_RSLT</td>
									<td onclick ondblclick class="text-center">PRCS_MTHD</td>
									<td onclick ondblclick class="text-center">CRDN_STDG_NM</td>
									<td onclick ondblclick class="text-start text-truncate"
										style="max-width:500px;">CRDN_PLC</td>
									<td onclick ondblclick class="text-center">ATCH_FILE_CNT</td>
									<td onclick ondblclick class="text-center">CRDN_STTS_NM</td>
									<td onclick ondblclick class="text-end">FFNLG_CRDN_AMT</td>
									<td onclick ondblclick class="text-end">ADVNTCE_AMT</td>
									<td onclick ondblclick class="text-center">CRDN_INPT_SE_NM</td>
									<td class="dummy-td"></td>
								</tr>
							</template>
							<template name="photoInspectionNotFound">
								<tr class="odd"><td valign="top" colspan="14" class="dataTables_empty text-center">단속 정보를 찾지 못했습니다.</td></tr>
							</template>
						</table>
					</div>
				</div>
		    </div>

			<div class="area-photoinspection h-px-200">
				선택자료
				<strong name="curDataVhrno"></strong>
				<div name="curDataFiles" class="ox-scroll d-flex w-100 h-px-175 bg-bordergray">

				</div>
			</div>
			<div class="area-photoinspection h-px-200">
				비교자료(선택자료의 다음 자료가 보여집니다.)
				<strong name="nextDataVhrno"></strong>
				<div name="nextDataFiles" class="ox-scroll d-flex w-100 h-px-175 bg-bordergray">

				</div>
			</div>
			<span class="area-samevehicleinspection">
				<div class="d-flex justify-content-evenly min-w-px-1400">
					<div class="card-datatable text-nowrap d-inline-flex">
				        <div class="dataTables_wrapper dt-bootstrap5 no-footer">
							<div name="sameVehicleInspectionMain-responsive"
								class="table-responsive ox-scroll oy-scroll h-px-400 w-px-350">
								<table name="sameVehicleInspectionMainTable"
									class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
									<thead class="sticky-thead">
										<tr data-search-target="[data-doctx='${pageName}']">
											<th onclick="FimsSupport.searchFromGridTitle('VHRNO',this.innerText,'match','part');"
											style="width:120px">차량번호</th>
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_STDG_NM',this.innerText,'match','perfect');"
											style="width:100px">단속동</th>
											<th class="text-orange"
											style="width:100px">단속건수</th>
											<th class="dummy-th"></th>
										</tr>
				                    </thead>
				                    <tbody name="sameVehicleInspectionMainTbody"></tbody>
									<template is="curly-brackets" name="sameVehicleInspectionMainRow">
				                    	<tr data-index="DATA-INDEX">
											<td onclick class="text-center">VHRNO</td>
					                    	<td onclick class="text-center">CRDN_STDG_NM</td>
					                    	<td onclick class="text-center">CRDN_CNT</td>
					                    	<td class="dummy-td"></td>
					                    </tr>
									</template>
									<template name="sameVehicleInspectionMainNotFound">
										<tr class="odd">
											<td valign="top" colspan="4" class="dataTables_empty text-center">
											단속 정보를 찾지 못했습니다.
											</td>
										</tr>
									</template>
								</table>
							</div>
						</div>
				    </div>

				    <div class="card-datatable text-nowrap d-inline-flex ms-3">
				        <div class="dataTables_wrapper dt-bootstrap5 no-footer">
							<div name="sameVehicleInspectionSub-responsive"
								class="table-responsive ox-scroll oy-scroll h-px-400 w-px-1000">
								<table name="sameVehicleInspectionSubTable"
									class="table-layout-fixed datatables-ajax table table-bordered dataTable no-footer">
									<thead class="sticky-thead">
										<tr data-search-target="[data-doctx='${pageName}']">
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_YMD','단속일자','ymd','');"
											style="width:180px">단속일시</th>
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_INPT_SE_CD',this.innerText,'codeValue','FIM003');"
											style="width:120px">자료출처</th>
											<th onclick="FimsSupport.searchFromGridTitle('TEAM_NM',this.innerText,'match','perfect');"
											style="width:120px">단속조</th>
											<th onclick="FimsSupport.searchFromGridTitle('VHRNO',this.innerText,'match','part');"
											style="width:120px">차량번호</th>
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_STDG_NM',this.innerText,'match','perfect');"
											style="width:120px">단속동</th>
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_PLC',this.innerText,'match','part');"
											style="width:120px">단속장소</th>
											<th onclick="FimsSupport.searchFromGridTitle('CRDN_STTS_CD',this.innerText,'codeValue','FIM010');"
											style="width:120px">처리상태</th>
											<th onclick="FimsSupport.searchFromGridTitle('FFNLG_CRDN_AMT',this.innerText,'match','perfect');"
											style="width:120px">금액</th>
											<th onclick="FimsSupport.searchFromGridTitle('RTPYR_NM',this.innerText,'match','part');"
											style="width:120px">성명</th>
											<th style="width:160px">주민번호</th>
											<th class="dummy-th"></th>
										</tr>
				                    </thead>
				                    <tbody name="sameVehicleInspectionSubTbody">
				                    </tbody>
									<template is="curly-brackets" name="sameVehicleInspectionSubRow">
										<tr data-index="DATA-INDEX">
											<td onclick ondblclick class="text-center">CRDN_YMD_TM</td>
											<td onclick ondblclick class="text-center">CRDN_INPT_SE_NM</td>
											<td onclick ondblclick class="text-center">TEAM_NM</td>
											<td onclick ondblclick class="text-center">VHRNO</td>
											<td onclick ondblclick class="text-center">CRDN_STDG_NM</td>
											<td onclick ondblclick class="text-start text-truncate"
												style="max-width:500px;min-width: 300px;">CRDN_PLC</td>
											<td onclick ondblclick class="text-center">CRDN_STTS_NM</td>
											<td onclick ondblclick class="text-end">FFNLG_CRDN_AMT</td>
											<td onclick ondblclick class="text-start">RTPYR_NM</td>
											<td onclick ondblclick class="text-center privacy-cell">
												<span>{RTPYR_NO}</span>
												<span>************</span>
											</td>
											<td class="dummy-td"></td>
										</tr>
									</template>
									<template name="sameVehicleInspectionSubNotFound">
										<tr class="odd">
											<td valign="top" colspan="10" class="dataTables_empty text-center">단속 정보를 찾지 못했습니다.</td>
										</tr>
									</template>
								</table>
							</div>
						</div>
				    </div>
				</div>
			</span>
		</div>
	</div>

  	<div class="content-backdrop fade"></div>
</div>

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

/**************************************************************************
 * Global Variable
 **************************************************************************/
var FIM002 = new CommonCodes(${FIM002});
var FIM003 = new CommonCodes(${FIM003});
var FIM010 = new CommonCodes(${FIM010});
var FIM026 = new CommonCodes(${FIM026});
pageObject["${pageName}"] = newDoctxFinder("${pageName}");

$(document).ready(function(){

	let $P = pageObject["${pageName}"];
	let enableExclBtn = (dataItem) => $P.$findn("btnInstLevyExcl").prop("disabled", !dataItem || "21" != dataItem.data["CRDN_STTS_CD"]);

	/**************************************************************************
	* DatasetControl, DatasetSupport, FormFields
	**************************************************************************/
	//단속사진검사 datasetControl 인스턴스
	var ctrl = newCrdn02010Control($P);
	ctrl.defaultFetchSize = FETCH_XS;
	ctrl.query = { pageNum : 1, fetchSize : ctrl.defaultFetchSize };
	ctrl.beforeCurrent = null;
	ctrl.getNext = (dataIndex) => {
		var crdnId = ctrl.dataset.getData(dataIndex).CRDN_ID;
		var dsArray = ctrl.dataset.getDataset();

		var index = dsArray.findIndex(item => item.CRDN_ID == crdnId);
		if(dsArray.length > index+1){
			return dsArray[index+1];
		} else {
			return null;
		}
	}
	ctrl.dataset.onDatasetChange = (obj, option) => {

		var t = $P.getGridTemplate("photoInspection");
		var trs = Apply.fromDataset.getTbody(ctrl.dataset, t.found, t.notFound, t.replacer);
		$P.renderInspectionDataList(obj?.Paging?.totalSize, ctrl.dataset.length, trs, "photoInspection", option);

		$P.pagingSupport0.setPagingInfo(obj);
	};

	ctrl.dataset.onCurrentChange = (dataItem) => {
		Apply.fromDataset.currentRow(ctrl.dataset, dataItem, $P.findn("photoInspectionTbody"));

		var dataIndex = "";
		var curCrdnId = "";
		var curDataVhrno = "";
		var nextCrdnId = "";
		var nextDataVhrno = "";
		if(!ctrl.dataset.empty){
			dataIndex = ctrl.dataset.getKey(dataItem);
			curCrdnId = ctrl.dataset.getData(dataIndex).CRDN_ID;
			curDataVhrno = ctrl.dataset.getData(dataIndex).VHRNO;
			var nextData = ctrl.getNext(dataIndex);
			nextCrdnId = nextData != null ? nextData.CRDN_ID : "";
			nextDataVhrno = nextData != null  ? nextData.VHRNO : "";
		}

		$P.showPhoto(curCrdnId,nextCrdnId,curDataVhrno,nextDataVhrno);
		enableExclBtn(dataItem);
	}

	$P.pagingSupport0 = new FimsPagingSupport({
		doq: $P,
        linkContainer: "[name='photoInspectionPaging']"
	});

	//동일차량검사 datasetControl 인스턴스
	var alt = newCrdn02010Alt($P);
	alt.defaultFetchSize = FETCH_XS;
	alt.query = { pageNum : 1, fetchSize : alt.defaultFetchSize };
	alt.beforeCurrent = null;

	alt.dataset.onDatasetChange = (obj, option) => {

		var t = $P.getGridTemplate("sameVehicleInspectionMain");
		var trs = Apply.fromDataset.getTbody(alt.dataset, t.found, t.notFound, t.replacer);
		$P.renderInspectionDataList(obj?.Paging?.totalSize, alt.dataset.length, trs, "sameVehicleInspectionMain", option);

		$P.pagingSupport1.setPagingInfo(obj);
	};

	alt.dataset.onCurrentChange = (dataItem) => {
		Apply.fromDataset.currentRow(alt.dataset, dataItem, $P.findn("sameVehicleInspectionMainTbody"));
		if(dataItem){
			$P.searchDetailInspectionDataList(dataItem.data["CRDN_ID_LIST"]);
		} else {
			$P.$findn("sameVehicleInspectionSubTbody").html("");
		}
	}

	$P.pagingSupport1 = new FimsPagingSupport({
		doq: $P,
        linkContainer: "[name='sameVehicleInspectionMainPaging']"
	});

	var shift = newCrdn02010Shift($P);

	shift.dataset.onDatasetChange = (obj, option) => {
		var t = $P.getGridTemplate("sameVehicleInspectionSub");
		var trs = Apply.fromDataset.getTbody(shift.dataset, t.found, t.notFound, t.replacer);
		$P.renderInspectionDataList(obj["Total"], shift.dataset.length, trs, "sameVehicleInspectionSub", option);
	};

	shift.dataset.onCurrentChange = (dataItem) => {
		Apply.fromDataset.currentRow(shift.dataset, dataItem, $P.findn("sameVehicleInspectionSubTbody"));
		enableExclBtn(dataItem);
	};


	/**************************************************************************
	* pageObject.function
	**************************************************************************/
	$P.fnReset = () => {
		var searchForm = $P.$findn("frmSearch");
		searchForm.find("input[type='radio']").not("[name='taskSeCd']").prop("checked", false);
		searchForm.find("input[type='checkbox']").prop("checked", false);
		searchForm.find("input[type='text']").val("");
		searchForm.find("input[type='hidden']").val("");
		searchForm.find("select").each(function(){ $(this).find("option:eq(0)").prop("selected", true); });

		$P.$findn("byOutput").val("동적 검색");
		$P.$findn("schRgtrNm").prop("readonly", true);				// 사용자 이름
		$P.$findn("schCrdnYmdFrom").datepicker('setDate', DateSupport.getAddDay(-7));
		$P.$findn("schCrdnYmdTo").datepicker('setDate', TODAY());
		ctrl.dataset.setData([]);
		alt.dataset.setData([]);
	};

	$P.fnResetAndChangeBiz = (taskSeCd) => {
		$P.fnReset();
		ctrl.urls.load = wctx.url("/crdn/crdn02/020/list.do");
		alt.urls.load = wctx.url("/crdn/crdn02/020/list.do");
		shift.urls.load = wctx.url("/crdn/crdn02/020/list.do");

		var clsForTask = taskSeCd.toLowerCase();
		//업무별 조회조건
		FimsSupport.renderForTask($P.findn("frmSearch"), clsForTask);
		//업무별 버튼
		FimsSupport.renderForTask($P.findn("gridbuttonArea"), clsForTask);
		//버튼 이벤트 재매핑
		$P.$findn("btnOpenOverTime").off("click");
		$P.$findn("btnOpenOverTime").on("click", () => $P.openOverTimePop());

		$P.$findn('btnPhotoInspection').trigger("click");
	}

	$P.getParams = () => {
		var formFields = new FimsFormFields($P.selectorn("frmSearch"));
		var data = formFields.get();

		if($P.currentDisplay == "photoInspection"){
			data.fetchSize = ctrl.defaultFetchSize;
		} else if($P.currentDisplay == "sameVehicleInspection"){
			data.fetchSize = alt.defaultFetchSize;
		}

		return data;
	}

	$P.searchInspectionList = () => {
		switch ($P.currentDisplay) {
			case "photoInspection":
				ctrl.query = $P.getParams();
				ctrl.query.inspectionDataType = "photo";
			    ctrl.load(1);
				break;
			case "sameVehicleInspection":
				alt.query = $P.getParams();
				alt.query.inspectionDataType = "sameVehicleMain";
			    alt.load(1);
				break;
			default: break;
		}
	}

	$P.searchDetailInspectionDataList = (dataKey) => {
		shift.query = {};
		shift.query.inspectionDataType = "sameVehicleSub";
		shift.query.crdnIds = dataKey;
		shift.query.taskSeCd = alt.query.taskSeCd;
	    shift.load(0);
	}

	$P.scrollInspectionDataList = () => {
		switch ($P.currentDisplay) {
			case "photoInspection":
				ctrl.load(ctrl.query.pageNum + 1);
				break;
			case "sameVehicleInspection":
				alt.load(alt.query.pageNum + 1);
				break;
			default: break;
		}
	}

	$P.refreshInspectionList = () => {
		switch ($P.currentDisplay) {
			case "photoInspection":
				ctrl.beforeCurrent = {
	                primaryKey : ctrl.dataset.getCurrent()["CRDN_ID"],
	                arrayIndex : ctrl.dataset.getCurrent()["ROW_NUM"] - 1
	            };

		        Apply.fromDatasetControl.reload(ctrl).then((resp)=>{
					Apply.toDataset.set(ctrl.dataset, resp);
					ctrl.dataset.onDatasetChange(resp, {reloaded : true});

					let todoCurrent = Apply.fromDataset.getTodoCurrent(ctrl.dataset, ctrl.beforeCurrent, "CRDN_ID");
					ctrl.beforeCurrent = null;
					if(todoCurrent != null){
						ctrl.dataset.setCurrent(todoCurrent.index, true);
					}
				});
				break;
			case "sameVehicleInspection":
				alt.beforeCurrent = {
					primaryKey : alt.dataset.getCurrent()["CRDN_ID_LIST"],
					arrayIndex : alt.dataset.getCurrent()["ROW_NUM"] - 1
	            };

				Apply.fromDatasetControl.reload(alt).then((resp)=>{
					Apply.toDataset.set(alt.dataset, resp);
					alt.dataset.onDatasetChange(resp, {reloaded : true});

					let todoCurrent = Apply.fromDataset.getTodoCurrent(alt.dataset, alt.beforeCurrent, "CRDN_ID_LIST");
					alt.beforeCurrent = null;
					if(todoCurrent != null){
						alt.dataset.setCurrent(todoCurrent.index, true);
					}
				});

			    break;
			default: break;
		}
	}

	$P.fnExcelDown = async() => {
		if($P.currentDisplay == "photoInspection"){
			if(ctrl.dataset.empty){
	    		alert("조회된 자료가 없습니다.");
	    		return;
	    	}

			var cellDefs = AppSupport.getCellDefs(
				$P.$findn("photoInspectionTable").find("thead th").not(".dummy-th").not(":eq(0)"),
    			$($P.findn("photoInspectionRow").content).find("td").not(".dummy-td").not(":eq(0)")
			);
			ctrl.query.cellDefs = cellDefs;

	    	ctrl.download();

		} else {

			if(alt.dataset.empty){
	    		alert("조회된 자료가 없습니다.");
	    		return;
	    	}

			var excelTarget = await dialog2("저장할 자료를 선택하세요.","",
					[{key:"main",value:"단속건수 엑셀저장"},{key:"sub",value:"상세내역 엑셀저장"},{key:"cancel",value:"취소"}]);

	    	if(excelTarget == "main"){

				var cellDefs = AppSupport.getCellDefs(
					$P.$findn("sameVehicleInspectionMainTable").find("thead th").not(".dummy-th"),
		    		$($P.findn("sameVehicleInspectionMainRow").content).find("td").not(".dummy-td")
		    	);
				alt.query.cellDefs = cellDefs;

		    	alt.download();
			} else if(excelTarget == "sub"){

				var cellDefs = AppSupport.getCellDefs(
					$P.$findn("sameVehicleInspectionSubTable").find("thead th").not(".dummy-th"),
	    			$($P.findn("sameVehicleInspectionSubRow").content).find("td").not(".dummy-td"),
	    			FimsSupport.getCellDefsForPrivacyCell
		    	);
				shift.query.cellDefs = cellDefs;

				shift.download();
			}

		}
	}

	$P.getGridTemplate = (gridType) => {
		var notFound;
		var found;
		var replacer;

		switch (gridType) {
			case "photoInspection":
				notFound = [$P.findn("photoInspectionNotFound").innerHTML]
				found = $P.findn("photoInspectionRow").innerHTML;
				replacer = (str, dataItem) => str
				    .replace(/{onclick}/gi, "pageObject['${pageName}'].clickInspectionDataList('{DATA-INDEX}','photoInspection');")
		            .replace(/{ondblclick}/gi, "pageObject['${pageName}'].dblclickInspectionDataList('{CRDN_ID}','photoInspection');");

				break;
			case "sameVehicleInspectionMain":
				notFound = [$P.findn("sameVehicleInspectionMainNotFound").innerHTML];
				found = $P.findn("sameVehicleInspectionMainRow").innerHTML;
				replacer = (str, dataItem) => str
					.replace(/{onclick}/gi, "pageObject['${pageName}'].clickInspectionDataList('{DATA-INDEX}','sameVehicleInspectionMain');");

				break;
			case "sameVehicleInspectionSub":
				notFound = [$P.findn("sameVehicleInspectionSubNotFound").innerHTML]
				found = $P.findn("sameVehicleInspectionSubRow").innerHTML;
				replacer = (str, dataItem) => str
					.replace(/{onclick}/gi, "pageObject['${pageName}'].clickInspectionDataList('{DATA-INDEX}','sameVehicleInspectionSub');")
		        	.replace(/{ondblclick}/gi, "pageObject['${pageName}'].dblclickInspectionDataList('{CRDN_ID}','sameVehicleInspectionSub');");

				break;
		}

		return {
			found : found,
			notFound : notFound,
			replacer : replacer
		};
	}

	$P.renderInspectionDataList = (total, listLength, trs, renderDataType, option) => {

		let noMore = (listLength >= total);

	    switch (renderDataType) {
			case "photoInspection":
				var initScroll = (ctrl.query.pageNum < 2);
				if(option != null && option.reloaded){
					initScroll = false;
				}

				$P.findn("photoInspection-responsive").changeContent(trs, initScroll, noMore);

				break;
			case "sameVehicleInspectionMain":
				var initScroll = (alt.query.pageNum < 2);
				if(option != null && option.reloaded){
					initScroll = false;
				}

				$P.findn("sameVehicleInspectionMain-responsive").changeContent(trs, initScroll, noMore);

				break;
			case "sameVehicleInspectionSub":

				$P.$findn("sameVehicleInspectionSubTbody").html(trs);
				break;
			default: break;
		}

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

	$P.clickInspectionDataList = (dataIndex, gridType) => {

		switch (gridType) {
			case "photoInspection":

				if(dataIndex != ""){
					$P.$findn("photoInspectionTbody").setCurrentRow(dataIndex);
					Apply.toDataset.current(ctrl.dataset, dataIndex);
				}
				var curData = ctrl.dataset.getData(dataIndex);
				var curCrdnId = curData.CRDN_ID;
				var curDataVhrno = curData.VHRNO;
				var nextData = ctrl.getNext(dataIndex);
				var nextCrdnId = nextData != null ? nextData.CRDN_ID : "";
				var nextDataVhrno = nextData != null  ? nextData.VHRNO : "";
				$P.showPhoto(curCrdnId,nextCrdnId,curDataVhrno,nextDataVhrno);
				break;
			case "sameVehicleInspectionMain":
				if(dataIndex == ""){
					return;
				}
				$P.$findn("sameVehicleInspectionMainTbody").setCurrentRow(dataIndex);

				Apply.toDataset.current(alt.dataset, dataIndex);

				var crdnIdList = alt.dataset.getData(dataIndex).CRDN_ID_LIST;
				$P.searchDetailInspectionDataList(crdnIdList);

				break;
			case "sameVehicleInspectionSub":
				if(dataIndex == ""){
					return;
				}
				$P.$findn("sameVehicleInspectionSubTbody").setCurrentRow(dataIndex);

				Apply.toDataset.current(shift.dataset, dataIndex);
				break;
		}
	}

	$P.dblclickInspectionDataList = (dataKey) => crdnTotalInfo(
		{
			callPageName : "${pageName}",
			crdnId : dataKey
		},
		() => $P.refreshInspectionList()
	);

	$P.showPhoto = (crdnId, nextCrndId, curDataVhrno, nextDataVhrno) => {

		if(crdnId == ""){
			$P.$findn("curDataVhrno").html("");
			$P.$findn("nextDataVhrno").html("");
			$P.$findn("curDataFiles").html("");
			$P.$findn("nextDataFiles").html("");
			return;
		}

		$P.$findn("curDataVhrno").html(curDataVhrno);
		$P.$findn("nextDataVhrno").html(nextDataVhrno);

		ajax.get({
			url:"crdn/crdn06/fileList.do",
			data: {
				infoType : "100",
				infoKeys : [crdnId, nextCrndId],
				fetchSize : 0
			},
			success : (resp) => {

				var fileList = resp.fileList;

				var currentDataFileList = fileList.filter(x => x.INF_KEY == crdnId);
				var nextDataFileList = fileList.filter(x => x.INF_KEY == nextCrndId);

				$P.$findn("curDataFiles").html("");
				$P.$findn("nextDataFiles").html("");

				currentDataFileList.forEach(function(item, index, array){
					var output = fnMakeImgTagForInspection(item.URL, item.FILE_NM,"cur"+item.FILE_ID+'${pageName}',item.MOSAIC);
					$P.$findn("curDataFiles").append(output);
				});
				nextDataFileList.forEach(function(item, index, array){
					var output = fnMakeImgTagForInspection(item.URL, item.FILE_NM,"next"+item.FILE_ID+'${pageName}',item.MOSAIC);
					$P.$findn("nextDataFiles").append(output);
				});

			}
		});
	}

	$P.openLevyExclPop = (levyExclSeCd) => {
		var dataItem = "";

		if ($P.currentDisplay == "photoInspection") {
			dataItem = ctrl.dataset.getCurrent("item");
		} else if ($P.currentDisplay == "sameVehicleInspection") {
			dataItem = shift.dataset.getCurrent("item");
		} else {
			return;
		}

		if (dataItem == undefined || dataItem == "") {
			return;
		}

		var params = {
			"crdnId" : dataItem.data.CRDN_ID,
			"levyExclSeCd" : levyExclSeCd,
			"savedCallbackFuncName" : "pageObject['${pageName}']['popupSavedCallback']",
			"callPurpose" : "create"
		};

		var taskSeCd = $P.$findn("frmSearch").find("[name='taskSeCd']:checked").val();

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

				if((typeof resp) != "string"){
					dialog.alert({
						content : resp.message,
						init : function(){
							AppSupport.focusClose();
						}
					});
					return;
				}

				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}");
					},
					onClose : () => {}
				});

			}
		});
	};

	$P.openOverTimePop = () => {

		if ($P.currentDisplay != "photoInspection") {
			return;
		}

		var dataItem = ctrl.dataset.getCurrent("item");

		if (dataItem == undefined || dataItem == "") {
			return;
		}

		var params = {
			"crdnId" : dataItem.data.CRDN_ID,
			"savedCallbackFuncName" : "pageObject['${pageName}']['popupSavedCallback']"
		};

		ajax.get({
			url : wctx.url("/crdn/crdn02/050/info.do"),
			data : params,
			success : (resp) => {

				if((typeof resp) != "string"){
					dialog.alert({
						content : resp.message,
						init : function(){
							AppSupport.focusClose();
						}
					});
					return;
				}

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

				dialog.open({
					id : dialogId,
					title : "2시간 초과 처리",
					content : resp,
					size : "lg",
					init : () => {
						$("#"+dialogId).attr("name", dialogName);
						$("#"+dialogId).attr("data-ref-doctx","${pageName}");
					},
					onClose : () => {}
				});
			}
		});
	}

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

		if(saved){
			$P.refreshInspectionList();
		}
	}

	// 사용자검색 callback
	$P.callbackFindUser = (userId, userNm) => {
		$P.$findn("schRgtrCd").val(userId);							// 사용자 ID
		$P.$findn("schRgtrNm").val(userNm);							// 사용자 명
	}

	// 사용자검색 버튼 클릭 이벤트
	$P.fnGetFindUser = () => {
		let params = {
			callbackFuncName: "pageObject['${pageName}']['callbackFindUser']"
		};

		ajax.get({
			  url: wctx.url("/user/user02/010/main.do")
			, data: params || {}
			, success: resp => {

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

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

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

	/**************************************************************************
	* element.on
	**************************************************************************/
    $P.$findn("btnReset").on('click', () => $P.fnReset()); //초기화버튼
    $P.$findn("btnPhotoInspection").on('click', () => {

    	$(".area-photoinspection").removeAttr("hidden");
    	$(".area-samevehicleinspection").attr("hidden","hidden");

		$P.$findn('btnPhotoInspection').addClass("active");
		$P.$findn('btnSameVehicleInspection').removeClass("active");
    	$P.currentDisplay = "photoInspection";
    	
		enableExclBtn(ctrl.getCurrent("item"));
    });
    $P.$findn("btnSameVehicleInspection").on('click', () => {

    	$(".area-samevehicleinspection").removeAttr("hidden");
    	$(".area-photoinspection").attr("hidden","hidden");

    	$P.$findn("btnSameVehicleInspection").addClass("active");
		$P.$findn("btnPhotoInspection").removeClass("active");
    	$P.currentDisplay = "sameVehicleInspection";
    	
    	enableExclBtn(shift.getCurrent("item"));
    });

    $P.$findn('btnSearch').on('click', () => $P.searchInspectionList()); //검색버튼
	// 동적검색에서 엔터(Enter) 키를 누르면 검색한다.
	$P.$findn("term").onEnterPress($P.searchInspectionList);

	$P.$findn("btnExcel").on('click', () => $P.fnExcelDown());
	$P.$findn("btnFindUser").on("click", () => $P.fnGetFindUser());		// 사용자 검색
	$P.$findn("btnInstLevyExcl").on("click", () => $P.openLevyExclPop("1"));

	Componentization.fnMakeResizableTable($P.findn("photoInspection-responsive"));
	Componentization.fnMakeResizableTable($P.findn("sameVehicleInspectionMain-responsive"));
	Componentization.fnMakeResizableTable($P.findn("sameVehicleInspectionSub-responsive"));
	//스크롤 테이블
	Componentization.fnMakeScrollableTable($P.findn("photoInspection-responsive"), $P.scrollInspectionDataList);
	Componentization.fnMakeScrollableTable($P.findn("sameVehicleInspectionMain-responsive"), $P.scrollInspectionDataList);

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

    var defaultBizValue = $("#layout-navbar input[name='taskSeCd']:checked").val();
    $P.$findn("frmSearch").find("input[name='taskSeCd'][value='" + defaultBizValue + "']").prop("checked",true);
	$P.fnResetAndChangeBiz(defaultBizValue);

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

    $P.$findn("frmSearch").find("input[name='taskSeCd']").each(function(i) {
		$(this).prop("disabled", "true");
	});
});
//# sourceURL=crdn02010-main.jsp
</script>