<%@ 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="prefixName" scope="request">통합 반송 등록</c:set>

<!-- inner page html -->
<div class="content-wrapper">
	<!-- Content -->
	<div class="container flex-grow-1 px-0">

		<!-- Page Body -->
		<div class="card">
			<div class="wrapper-list">
				<!-- 상단 버튼 -->
				<div class="container-page-btn">
					<button type="button" class="btn btn-outline-dark w-px-120" id="btnReset--${pageName}" title="초기화">
						초기화
					</button>
					<span class="container-window-btn-right">
						<button type="button" class="btn btn-search w-px-120" id="btnSearch--${pageName}" title="검색">
							검색
						</button>
						<button type="button" class="btn btn-excel w-px-120" id="btnExcel--${pageName}" title="엑셀">
							엑셀
						</button>
					</span>
				</div> <!-- 상단 버튼 -->

				<!-- 검색 조건 영역 -->
				<form id="frmSearch--${pageName}" name="frmSearch">
					<!-- hidden -->
					<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" />

					<!-- 메인 조건 -->
					<div class="container-search">
						<div class="row g-1">
							<!-- 발송 구분 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schSndngSeCd--${pageName}">발송구분</label>
	                            <select class="form-select w-px-160" id="schSndngSeCd--${pageName}" name="schSndngSeCd">
	                            	<option value="">전체</option>
	                            	<c:forEach items="${FIM047List}" var="item">
	                            		<option value="${item.code}">${item.value}</option>
	                            	</c:forEach>
	                            </select>
							</div>
							<!-- 발송 일자 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schSndngYmd--${pageName}">발송일자</label>
								<span class="form-search-linebox">
									<input type="text" class="form-control form-date" id="schSndngYmd--${pageName}" name="schSndngYmd"
										data-fmt-type="day" title="시작 날짜 선택" />
									<button type="button" class="bx bx-lg bx-calendar bg-white"></button>
								</span>
							</div>
							<!-- 발송 상세 ID -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="sndngDtlId--${pageName}">발송번호</label>
								<input type="text" class="form-control w-px-200" id="sndngDtlId--${pageName}" name="sndngDtlId" autocomplete="off" />
							</div>
							<!-- 회계연도 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schFyr--${pageName}">회계연도</label>
								<input type="text" class="form-control w-px-60" id="schFyr--${pageName}" name="schFyr" maxlength="4" autocomplete="off" />
							</div>
							<!-- 고지 번호 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schLevyNoFrom--${pageName}">고지번호</label>
								<input type="text" class="form-control w-px-80" id="schLevyNoFrom--${pageName}" name="schLevyNoFrom" maxlength="6" autocomplete="off" />
								~
								<input type="text" class="form-control w-px-80" id="schLevyNoTo--${pageName}" name="schLevyNoTo" maxlength="6" autocomplete="off" />
							</div>
							<!-- 수령인 명 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schRcpnNm--${pageName}">수령인명</label>
								<input type="text" class="form-control w-px-200" id="schRcpnNm--${pageName}" name="schRcpnNm" autocomplete="off" />
							</div>
							<!-- 차량번호 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schVhrno--${pageName}">차량번호</label>
								<input type="text" class="form-control w-px-160" id="schVhrno--${pageName}" name="schVhrno" autocomplete="off" />
							</div>
							<!-- 등기 번호 -->
							<div class="col-4">
								<label class="form-label fw-bold form-search-title w-px-120 text-end" for="schRgNo--${pageName}">등기번호</label>
								<input type="text" class="form-control w-px-160" id="schRgNo--${pageName}" name="schRgNo" autocomplete="off" />
							</div>
						</div> <!-- <div class="row g-1"> -->
					</div> <!-- <div class="container-search"> -->
			    </form>
			    <!-- 검색 조건 영역 -->

				<!-- 업무 버튼 및 건수 표시 -->
				<div>
					<span class="container-page-btn">
		            	<!-- 건수, 페이지 표시 -->
						<div class="d-flex flex-row justify-content-between">
							<span class="dataTables_info" id="paging--${pageName}PagingInfo" role="status" aria-live="polite"></span>
							<ul class="pagination pagination-primary" id="paging--${pageName}">
							</ul>
						</div>
					</span>
				</div> <!-- 업무 버튼 및 건수 표시 -->

				<!-- DataTables(그리드) -->
				<div class="card-datatable text-nowrap">
					<div class="dataTables_wrapper dt-bootstrap5 no-footer" id="DataTables_Table_0_wrapper--${pageName}">
						<div class="table-responsive ox-scroll oy-scroll h-px-400" id="table-responsive--${pageName}">
							<table class="table-layout-fixed dataTable datatables-ajax table table-bordered no-footer" id="DataTables_Table_0--${pageName}" aria-describedby="DataTables_Table_0_info">
								<thead class="sticky-thead">
									<tr id="theadTr--${pageName}">
										<th class="cmn" style="width: 72px;">No.</th>
										<th class="cmn" style="width: 56px;"><input type="checkbox" class="form-check-input" id="gridAllCheckbox--${pageName}" onchange="pageObject['${pageName}'].control.select(this.checked);" /></th>
										<th class="cmn" style="width: 200px;">발송번호</th>
										<th class="cmn" style="width: 200px;">발송구분</th>
										<th class="cmn" style="width: 120px;">발송일자</th>
										<th class="cmn" style="width: 120px;">발송종료일자</th>
										<th class="cmn" style="width: 160px;">등기번호</th>
										<th class="cmn" style="width: 120px;">수납</th>
										<th class="cmn" style="width: 160px;">발송상세상태</th>
										<th class="cmn" style="width: 200px;">수령인</th>
										<th class="cmn" style="width: 120px;">수령인생일</th>
										<th class="cmn" style="width: 100px;">우편번호</th>
										<th class="cmn" style="width: 280px;">주소</th>
										<th class="cmn" style="width: 320px;">상세주소</th>
										<th class="cmn" style="width: 180px;">단속일시</th>
										<th class="cmn" style="width: 140px;">차량번호</th>
										<th class="cmn" style="width: 160px;">법정동</th>
										<th class="cmn" style="width: 280px;">단속장소</th>
										<th class="cmn" style="width: 100px;">회계연도</th>
										<th class="cmn" style="width: 100px;">부과번호</th>
										<th class="cmn" style="width: 120px;">부과일자</th>
										<th class="cmn" style="width: 120px;">납기일자</th>
										<th class="cmn" style="width: 120px;">과태료금액</th>
										<th class="cmn" style="width: 120px;">본세</th>
										<th class="cmn" style="width: 120px;">가산금</th>
										<th class="cmn" style="width: 200px;">전자납부번호</th>
										<th class="cmn" style="width: 180px;">등록일시</th>
										<th class="cmn" style="width: 140px;">등록사용자</th>
										<th class="cmn" style="width: 180px;">수정일시</th>
										<th class="cmn" style="width: 140px;">수정사용자</th>
										<th class="cmn dummy-th"></th>
									</tr>
								</thead>
								<tbody id="tbody--${pageName}">
								</tbody>
								<template id="${infoPrefix}Row--${pageName}">
									<tr data-key="{SNDNG_DTL_ID}">
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{ROW_NUM}</td>
										<td class="cmn text-center"><input type="checkbox" class="form-check-input" name="gridCheckbox" value="{SNDNG_DTL_ID}" onchange="pageObject['${pageName}'].control.select('{SNDNG_DTL_ID}', this.checked);" /></td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_DTL_ID}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_SE_NM}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_YMD}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_END_YMD}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{RG_NO}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_RCVMT_NM}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{SNDNG_DTL_STTS_NM}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{RCPN_NM}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{RCPN_BRDT}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{RCPN_ZIP}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{RCPN_ADDR}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{RCPN_DTL_ADDR}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{CRDN_DT}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{VHRNO}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{CRDN_STDG_NM}</td>
										<td class="cmn text-start"  onclick="{onclick}" ondblclick="{ondblclick}">{CRDN_PLC}</td>
										<td class="cmn text-center"  onclick="{onclick}" ondblclick="{ondblclick}">{FYR}</td>
										<td class="cmn text-center"  onclick="{onclick}" ondblclick="{ondblclick}">{LEVY_NO}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{LEVY_YMD}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{DUDT_YMD}</td>
										<td class="cmn text-end"	onclick="{onclick}" ondblclick="{ondblclick}">{FFNLG_AMT}</td>
										<td class="cmn text-end"	onclick="{onclick}" ondblclick="{ondblclick}">{PCPTAX}</td>
										<td class="cmn text-end"	onclick="{onclick}" ondblclick="{ondblclick}">{ADAMT}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{EPAYNO}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{REG_DT}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{RGTR_NM}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{MDFCN_DT}</td>
										<td class="cmn text-center" onclick="{onclick}" ondblclick="{ondblclick}">{MDFR_NM}</td>
										<td class="cmn dummy-td"></td>
									</tr>
								</template>
								<template id="${infoPrefix}NotFound--${pageName}">
									<tr class="odd">
										<td valign="top" colspan="31" class="dataTables_empty text-center">${prefixName} 정보를 찾지 못했습니다.</td>
									</tr>
								</template>
							</table>
						</div>
					</div>
				</div> <!-- DataTables(그리드) -->

				<p></p>

				<!-- 입력 영역 -->
				<form id="frmEdit--${pageName}" name="frmEdit">
					<div class="container-search-detail">
						<!-- 업무 버튼 및 건수 표시 -->
						<div>
							<span class="container-page-btn">
				            	<!-- 건수, 페이지 표시 -->
								<div class="d-flex flex-row justify-content-between">
									<!-- 배달 일자 -->
									<label class="form-label fw-bold form-search-title w-px-120 text-end required" for="dlvrYmd--${pageName}">배달일자</label>
									<span class="form-search-linebox">
										<input type="text" class="form-control form-date" id="dlvrYmd--${pageName}" name="dlvrYmd"
											data-fmt-type="day" title="날짜 선택" required />
										<button type="button" class="bx bx-lg bx-calendar bg-white"></button>
									</span>
									<!-- 미배달 사유 코드 -->
									<label class="form-label fw-bold form-search-title w-px-120 text-end required" for="undlvrRsnCd--${pageName}">미배달사유</label>
		                            <select class="form-select w-px-160" id="undlvrRsnCd--${pageName}" name="undlvrRsnCd" required>
		                            	<option value="">선택하세요</option>
		                            	<c:forEach items="${FIM081List}" var="item">
		                            		<option value="${item.code}">${item.value}</option>
		                            	</c:forEach>
		                            </select>
								</div>
								<!-- 업무 버튼 -->
					            <span class="container-window-btn-right">
									<button type="button" class="btn btn-primary w-px-120" id="btnSave--${pageName}" title="반송 등록">
										반송 등록
									</button>
					            </span>
							</span>
						</div> <!-- 업무 버튼 및 건수 표시 -->
					</div>
			    </form>
				<!-- 입력 영역 -->
			</div> <!-- <div class="wrapper-list"> -->
		</div> <!-- <div class="card"> -->
		<!-- Page Body -->

	</div> <!-- <div class="container-xxl flex-grow-1 px-0"> -->
	<!-- Content -->

  	<div class="content-backdrop fade"></div>
</div>
<!-- / inner page html <div class="content-wrapper"> -->

<script>
	/**************************************************************************
	 * Global Variable
	 **************************************************************************/
	pageObject["${pageName}"] = {};

	/**************************************************************************
	 * script 진입
	 **************************************************************************/
	$(document).ready(function() {
		// pageObject
		let $P = pageObject["${pageName}"];

	 	// infoDialog 호출 용도(view 조회(편집불가), create 등록, update 수정)
		$P.callPurpose = "${callPurpose}";
		// FormFields
		$P.formFields = new FimsFormFields("#frmSearch--${pageName}");
		$P.formEditFields = new FimsFormFields("#frmEdit--${pageName}");

		/**************************************************************************
		 * DatasetControl
		 **************************************************************************/
		$P.control = new DatasetControl({
			  prefix: "sndbkTrgt"
			, prefixName: "반송 대상"
			, keymapper: info => info ? info.SNDNG_DTL_ID : ""
			, dataGetter: obj => obj.${infoPrefix}List
			, appendData: true
			, formats: {
		    	  SNDNG_YMD: dateFormat
		    	, SNDNG_END_YMD: dateFormat
		    	, LEVY_YMD: dateFormat
		    	, DUDT_YMD: dateFormat
		    	, FFNLG_AMT: numberFormat
		    	, PCPTAX: numberFormat
		    	, ADAMT: numberFormat
		    	, REG_DT: datetimeFormat
		    	, MDFCN_DT: datetimeFormat
			}
		});
		// $P.control 설정
		$P.control.defaultFetchSize = FETCH_XS;									// 1 페이지당 조회되는 자료 건수 index.jsp에서 확인 FETCH_XS = 30
		$P.control.query = { pageNum : 1, fetchSize : $P.control.defaultFetchSize };
		$P.control.beforeCurrent = null;


		/**************************************************************************
		 * DatasetControl 이벤트
		 **************************************************************************/
		// Dataset 변경
		$P.control.onDatasetChange = (obj, option) => {
			$P.renderList(obj.${infoPrefix}Total, option);

			$("#paging--${pageName}").setPagingInfo({
				  list: $P.control.dataset
				, prefix: "paging--${pageName}"
				, start: obj.${infoPrefix}Start
				, totalSize: obj.${infoPrefix}Total
				, fetchSize: obj.${infoPrefix}Fetch
				, func: "pageObject['${pageName}'].control.load({index})"
			});


		};

		// 현재 선택 자료 변경 이벤트
		$P.control.onCurrentChange = (item) => {
			if (!item) return;

			let key = item.data.SNDNG_DTL_ID;

			$("#tbody--${pageName}").setCurrentRow(key);
		};

		// 선택(체크) 변경 이벤트
		$P.control.onSelectionChange = (selected) => {
			let ${infoPrefix}List = $P.control.dataset;
			let keys = selected.map(e => ${infoPrefix}List.getKey(e));

			$("#tbody--${pageName} input[type='checkbox']").each(function() {
				let checkbox = $(this);
				checkbox.prop("checked", keys.includes(checkbox.val()));
			});

			// DataTables(그리드) 전체 선택(checkbox)
			if (keys.length < 1) {
				$("#DataTables_Table_0--${pageName} th input[type='checkbox']").prop("checked", false);		// 체크 해제
			} else if (keys.length == ${infoPrefix}List.length) {
				$("#DataTables_Table_0--${pageName} th input[type='checkbox']").prop("checked", true);		// 체크 설정
			} else {
				$("#DataTables_Table_0--${pageName} th input[type='checkbox']").prop("checked", false);		// 체크 해제
			}
		};

		// 저장 callback
		$P.control.onSave = (resp) => {
			let dialogTitle = $("#" + $P.control.prefix + "Dialog--${openerPageName}").find("h5.modal-title").html();
			let showMessage = resp.rtnMsg.replace(/[S]|[F]/g, dialogTitle);

			// 메시지 출력
			dialog.alert({
				  content: showMessage
				, init: () => { AppSupport.setDialogZindex(); }
				, onOK: () => { }
			});

			if (resp.saved) {
				dialog.close($P.control.prefix + "Dialog--${openerPageName}");
			}
		}

		// 저장
		$P.control.save = (info) => {
			if (!info) return;

	  		let create = ($P.callPurpose == "create");

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

		/**************************************************************************
		 * DataTables 이벤트
		 **************************************************************************/
		// DataTables에 click, dbclick 이벤트
		$P.renderList = (totalSize, option) => {
			let ${infoPrefix}List = $P.control.dataset;
			let empty = ${infoPrefix}List.empty;

			let trs = empty ?
				[document.getElementById("${infoPrefix}NotFound--${pageName}").innerHTML] : <%-- from template#${infoPrefix}NotFound --%>
				${infoPrefix}List.inStrings(
					document.getElementById("${infoPrefix}Row--${pageName}").innerHTML, <%-- from template#${infoPrefix}Row --%>
					(str, dataItem) => str
						.replace(/{onclick}/gi, "pageObject['${pageName}'].control.setCurrent('" + dataItem.getValue("SNDNG_DTL_ID") + "');")
						.replace(/{ondblclick}/gi, "pageObject['${pageName}'].getTotalInfo('" + dataItem.getValue("CRDN_ID") + "');")
				);

			let noMore = (${infoPrefix}List.length >= totalSize);
			let initScroll = ($P.control.query.pageNum < 2);
			if(option != null && option.reloaded){
				initScroll = false;
			}
			$("#table-responsive--${pageName}")[0].changeContent(trs.join(), initScroll, noMore);


		    // checkbox 체크 해제
		    $("#DataTables_Table_0--${pageName} th input[type='checkbox']").prop("checked", false);

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

		// DataTables에 스크롤이 맨 밑으로 이동했을 때 이벤트
		$P.scrollDataList = () => {


			$P.control.load($P.control.query.pageNum + 1);
		}

		// DataTables에 더블 클릭시 개별총정보 dialog
		$P.getTotalInfo = (crdnId) => {
			crdnTotalInfo({
				  callControlName: "pageObject['${pageName}'].control"
				, sggCd: $P.control.dataset.getValue("SGG_CD")
				, taskSeCd: $P.control.dataset.getValue("TASK_SE_CD")
				, crdnId: crdnId
			});
		}

		/**************************************************************************
		 * 사용자 함수(function)
		 **************************************************************************/
		// 검색 자료 재조회
		$P.fnRefreshList = () => {

			$P.control.reload({all : true});
		}

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

		/**************************************************************************
		 * 버튼 clickEvent
		 **************************************************************************/
		// 업무 구분 변경 이벤트
		$P.fnResetAndChangeBiz = (taskSeCd) => {
			// 업무 구분 코드
			if (!taskSeCd) {
				taskSeCd = $("#layout-navbar input[name='taskSeCd']:checked").val();
			}

			// 초기 기본 설정
			$P.initForm(taskSeCd);
			// 업무 구분별 설정
			$P.setTask(taskSeCd);

			// dataset 초기화
	 		$P.control.dataset.clear();
		}

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

			ajax.get({
				  url: wctx.url("/user/user02/010/main.do") + "?openerPageName=${pageName}"
				, data: params || {}
				, success: resp => {
					dialog.open({
						  id: "userDialog--${pageName}"
						, title: "사용자 검색"
						, content: resp
						, size: "lg"
						, init: () => { AppSupport.setDialogZindex(); }
					});
				}
			});
		}

		// 검색 버튼 이벤트
		$P.fnSearchList = () => {
			// 검색조건
			$P.control.query = $P.formFields.get();								// 검색 조건
			$P.control.query.fetchSize = $P.control.defaultFetchSize;			// 한번에 조회되는 자료 건수
			$P.control.query.delYn = "N";										// 삭제 여부

			$P.control.load(1);
		}

		// 엑셀 버튼 이벤트
		$P.fnExcel = () => {
			if ($P.control.dataset.empty) {
				dialog.alert({
					  content: "검색된 자료가 없습니다."
					, onOK: () => { }
				});
				return;
			}

			// DataTables(그리드)
			let cellDefs = AppSupport.getCellDefs($("#theadTr--${pageName} th").not(".dummy-th").not(":eq(0)")
					, $($("#${infoPrefix}Row--${pageName}")[0].content).find("td").not(".dummy-td").not(":eq(0)")
					, FimsSupport.getCellDefsForPrivacyCell);

			$P.control.query.cellDefs = cellDefs;

			$P.control.download();
		}

		// 반송 등록 버튼 이벤트
		$P.fnSave = () => {
			// 선택 자료
			let selected = $P.control.dataset.getKeys("selected");

			if (selected.length < 1) {
				dialog.alert({
					  content: "선택하신 " + $P.control.prefixName + " 정보가 없습니다."
					, init: () => { AppSupport.setDialogZindex(); }
					, onOK: () => { }
				});
				return;
			}

			// validate 확인
			if (!AppSupport.customValidate($("#frmEdit--${pageName}").find("input, select, textarea"))) return;

			let params = $P.formEditFields.get();										// formFields
			params.sggCd = $("#sggCd--${pageName}").val()								// 시군구 코드
			params.taskSeCd = $("#taskSeCd--${pageName}").val()							// 업무 구분 코드
 			params.sndngDtlIds = selected.join(",");									// 발송 상세 Ids
 			params.undlvrRsnNm = $("#undlvrRsnCd--${pageName} option:selected").text();	// 미배달 사유 명
 			params.sndngDtlSttsCd = "05";												// 발송 상세 상태 코드(FIM050) - 05: 반송

			dialog.alert({
				  content: "선택하신 " + selected.length + "건의 " + $P.control.prefixName + " 정보를 등록하시겠습니까?"
				, onOK: () => {
					$P.control.save(params);
				}
			});
		}

		/**************************************************************************
		 * 초기 설정
		 **************************************************************************/
		// 이벤트 설정
		$P.setEvent = () => {
			// 기본 버튼 이벤트
			$("#btnReset--${pageName}").on("click", () => $P.fnResetAndChangeBiz());	// 초기화
			$("#btnSearch--${pageName}").on("click", () => $P.fnSearchList());			// 검색
			$("#btnExcel--${pageName}").on("click", () => $P.fnExcel());				// 엑셀
			$("#btnFindUser--${pageName}").on("click", () => $P.fnGetFindUser());		// 사용자 검색

	 		// 동적검색에서 엔터(Enter) 키를 누르면 검색한다.
			$("#term--${pageName}").onEnterPress(function() {
				$P.fnSearchList();
			});

			// form-date 항목에서 키보드로 입력시 날짜 포맷팅 적용
			$("#frmSearch--${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);
					}
				});
			});

			// 버튼 이벤트
			$("#btnSave--${pageName}").on("click", () => $P.fnSave());			// 저장

			// DataTables width 변경 조정	업무별 그리드가 존재 한다면.. crdn06010-main.jsp 참고
			Componentization.fnMakeResizableTable($("#table-responsive--${pageName}")[0]);

			// DataTables 스크롤 이벤트 생성
			Componentization.fnMakeScrollableTable($("#table-responsive--${pageName}")[0], $P.scrollDataList);
		}

		// 초기 화면 설정
		$P.initForm = (taskSeCd) => {
			// 화면 초기화
	 		$("#frmSearch--${pageName}")[0].reset();

			// input, select 초기화
			let searchForm = $("#frmSearch--${pageName}");
			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); });

			// 최고 관리자 경우 업무구분을 선택할 수 있도록 하자.
	 		$("#frmSearch--${pageName} input[name='taskSeCd']").each(function(i) {
	 			$(this).prop("disabled", "true");
	 		});

			// 기본 데이터 설정
			$("#sggCd--${pageName}").val("${sggCd}");							// 시군구 코드
			$("#taskSeCd--${pageName}").val("${taskSeCd}");						// 업무 구분 코드
			AppSupport.initDatepicker("frmSearch--${pageName}");							// 달력 초기화
			$("#schSndngYmd--${pageName}").datepicker("setDate", new Date());	// 발송 일자
			$("#dlvrYmd--${pageName}").datepicker("setDate", new Date());		// 배달 일자
		}

		// 업무 구분별 설정
		$P.setTask = (taskSeCd) => {
			// 업무구분에 따른 URL 설정
			$P.control.urls.load = wctx.url("${infoPrefixUrl}" + "/210/list.do");		// 검색
			$P.control.urls.create = wctx.url("${infoPrefixUrl}" + "/230/create.do");	// 반송 등록
		}

		/**************************************************************************
		 * 최초 실행 함수
		 **************************************************************************/
		// 1. 이벤트 설정
		$P.setEvent();

		// 2. 초기 설정 및 업무 구분 변경
		$P.fnResetAndChangeBiz($("#layout-navbar input[name='taskSeCd']:checked").val());

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

</script>
