<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>

<!-- Page Body -->
<div class="content-wrapper">
	<!-- 입력 영역 -->
	<form id="frmEdit--${pageName}" name="frmEdit">
		<!-- hidden -->
		<input type="hidden" id="opnnId--${pageName}" name="opnnId" data-map="OPNN_ID" />

		<div class="d-flex flex-row justify-content-evenly">
			<!-- 화면 왼쪽 -->
			<div class="col-xl-9 mx-1">
				<!-- 의견제출 정보 -->
				<div class="card">
					<!-- 업무 버튼 -->
					<div class="container-page-btn">
						<label class="w-px-120 bg-label-danger pe-2 col-form-label text-sm-center">의견제출 정보</label>
						<!-- 버튼 우측 정렬 -->
						<span class="container-window-btn-right">
							<button type="button" class="btn btn-primary" id="btnCreateOpnnSbmsn--${pageName}" title="의견제출 등록" onclick="fnCreateOpnnSbmsn${pageName}();">
								의견제출 등록
							</button>
							<button type="button" class="btn btn-primary" id="btnUpdateOpnnSbmsn--${pageName}" title="의견제출 수정" onclick="fnUpdateOpnnSbmsn${pageName}();">
								의견제출 수정
							</button>
							<button type="button" class="btn btn-primary" id="btnRemoveOpnnSbmsn--${pageName}" title="의견제출 삭제" onclick="fnRemoveOpnnSbmsn${pageName}();">
								의견제출 삭제
							</button>
							<button type="button" class="btn btn-primary" id="btnPrintDlbrtLtfr--${pageName}" title="심의의결서 출력" onclick="fnPrintDlbrtLtfr${pageName}();">
								심의의결서 출력
							</button>
						</span>
					</div> <!-- <div class="container-page-btn"> -->

					<div class="row g-1">
						<!-- 접수 번호 -->
						<div class="col-md-4">
							<label for="rcptNo--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">접수 번호</label>
							<input type="text" class="form-control w-30" id="rcptNo--${pageName}" name="rcptNo" data-map="RCPT_NO" readonly />
						</div>
						<!-- 접수 일자 -->
						<div class="col-md-4">
							<label for="rcptYmd--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">접수 일자</label>
							<input type="text" class="form-control w-30" id="rcptYmd--${pageName}" name="rcptYmd" data-map="RCPT_YMD" readonly />
						</div>
						<!-- 접수 구분 -->
						<div class="col-md-4">
							<label for="rcptSeNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">접수 구분</label>
							<input type="text" class="form-control w-30" id="rcptSeNm--${pageName}" name="rcptSeNm" data-map="RCPT_SE_NM" readonly />
						</div>
						<!-- 진술자 이름 -->
						<div class="col-md-4">
							<label for="sttrNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">성명</label>
							<input type="text" class="form-control w-40" id="sttrNm--${pageName}" name="sttrNm" data-map="STTR_NM" readonly />
						</div>
						<!-- 진술자 생년월일 -->
						<div class="col-md-4">
							<label for="sttrBrdt--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">생년월일</label>
							<input type="text" class="form-control w-25" id="sttrBrdt--${pageName}" name="sttrBrdt" data-map="STTR_BRDT_FORMAT" placeholder="YY-MM-DD" readonly />
						</div>
						<!-- 소유주 관계 구분 명 -->
						<div class="col-md-4">
							<label for="ownrRelNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">소유주 관계 구분</label>
							<input type="text" class="form-control w-40" id="ownrRelNm--${pageName}" name="ownrRelNm" data-map="OWNR_REL_NM" readonly />
						</div>
						<!-- 진술자 주소 --><!-- 진술자 우편번호 -->
						<div class="col-md-12">
							<label for="sttrAddr--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">주소</label>
							<input type="text" class="form-control w-80" id="sttrAddr--${pageName}" name="sttrAddr" data-map="STTR_ADDR" readonly />
							<input type="text" class="form-control w-px-75" id="sttrZip--${pageName}" name="sttrZip" data-map="STTR_ZIP" readonly />
						</div>
						<!-- 진술자 상세주소 -->
						<div class="col-md-12">
							<label for="sttrDaddr--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">상세 주소</label>
							<input type="text" class="form-control w-87" id="sttrDaddr--${pageName}" name="sttrDaddr" data-map="STTR_DADDR" readonly />
						</div>
						<!-- 진술자 연락처 -->
						<div class="col-md-4">
							<label for="sttrCttpc--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">연락처</label>
							<input type="text" class="form-control w-35" id="sttrCttpc--${pageName}" name="sttrCttpc" data-map="STTR_CTTPC" readonly />
						</div>
						<!-- 진술자 이메일 -->
						<div class="col-md-8">
							<label for="sttrEml--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">이메일</label>
							<input type="text" class="form-control w-35" id="sttrEml--${pageName}" name="sttrEml" data-map="STTR_EML" readonly />
						</div>
						<!-- 의견 제출 내용 -->
						<div class="col-md-12">
							<label for="opnnSbmsnCn--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">의견제출 내용</label>
							<textarea type="text" class="form-control w-87" id="opnnSbmsnCn--${pageName}" name="opnnSbmsnCn" data-map="OPNN_SBMSN_CN" rows="4" data-maxlengthb="4000" readonly>
							</textarea>
						</div>
						<!-- 의견 제출 구분 명 -->
						<div class="col-md-4">
							<label for="opnnSbmsnSeNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">의견 제출 구분</label>
							<input type="text" class="form-control w-40" id="opnnSbmsnSeNm--${pageName}" name="opnnSbmsnSeNm" data-map="OPNN_SBMSN_SE_NM" readonly />
						</div>
						<!-- 의견 제출 요지 -->
						<div class="col-md-8">
							<label for="opnnSbmsnGist--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">의견제출 요지</label>
							<input type="text" class="form-control w-80" id="opnnSbmsnGist--${pageName}" name="opnnSbmsnGist" data-map="OPNN_SBMSN_GIST" data-maxlengthb="300" readonly />
						</div>
						<!-- 담당자 검토 의견 -->
						<div class="col-md-12">
							<label for="picRvwOpnn--${pageName}" class="w-px-120  bg-lighter pe-2 col-form-label text-sm-end">검토 의견</label>
							<textarea class="form-control w-87" id="picRvwOpnn--${pageName}" name="picRvwOpnn" data-map="PIC_RVW_OPNN" rows="3" data-maxlengthb="1000" readonly>
							</textarea>
						</div>
						<!-- 첨부 파일 테이블 -->
						<div class="table-responsive">
							<table class="table table-bordered table-hover table-striped" id="fileList--${pageName}">
								<thead>
									<th class="text-center" style="width: 24px">NO.</th>
									<th class="text-center" style="width: 200px">파일 번호</th>
									<th class="text-center">파일 이름</th>
									<th class="text-center" style="width: 200px">파일 크기</th>
									<th class="text-center" style="width: 120px">다운로드</th>
								</thead>
								<tbody></tbody>
							</table>
						</div> <!-- 첨부 파일 테이블 <div class="table-responsive"> -->
					</div> <!-- <div class="row g-1"> -->
				</div> <!-- 의견제출 정보 <div class="card"> -->
			</div> <!-- <div class="col-xl-9 mx-1"> -->

			<!-- 화면 오른쪽 -->
			<div class="col-xl-3 mx-1">
				<!-- 심의 정보 -->
				<div class="card">
					<!-- 업무 버튼 -->
					<div class="container-page-btn">
						<label class="w-px-120 bg-label-danger pe-2 col-form-label text-sm-center">심의 정보</label>
						<!-- 버튼 우측 정렬 -->
						<span class="container-window-btn-right">
							<button type="button" class="btn btn-primary" id="btnUpdateOpnnSbmsnDlbrt--${pageName}" title="의견제출 심의" onclick="fnUpdateOpnnSbmsnDlbrt${pageName}();">
								의견제출 심의
							</button>
						</span>
					</div> <!-- <div class="container-page-btn"> -->

					<div class="row g-1">
						<!-- 문서 번호 -->
						<div class="col-md-12">
							<label for="docNo--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">문서 번호</label>
							<input type="text" class="form-control w-45" id="docNo--${pageName}" name="docNo" data-map="DOC_NO" readonly />
						</div>
						<!-- 통보 구분 -->
						<div class="col-md-12">
							<label for="ntfctnSeNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">통보 구분</label>
							<input type="text" class="form-control w-30" id="ntfctnSeNm--${pageName}" name="ntfctnSeNm" data-map="NTFCTN_SE_NM" readonly />
						</div>
						<!-- 의견 제출 상태 코드 -->
						<div class="col-md-12">
							<label for="opnnSbmsnSttsNm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">처리 결과</label>
							<input type="text" class="form-control w-30" id="opnnSbmsnSttsNm--${pageName}" name="opnnSbmsnSttsNm" data-map="OPNN_SBMSN_STTS_NM" readonly />
						</div>
						<!-- 답변일시 -->
						<div class="col-md-12">
							<label for="ansYmdTm--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">처리 일시</label>
							<input type="text" class="form-control w-45" id="ansYmdTm--${pageName}" name="ansYmdTm" data-map="ANS_YMD_TM" readonly />
						</div>
						<!-- 답변 내용 -->
						<div class="col-md-12">
							<label for="ansCn--${pageName}" class="w-px-120 bg-lighter pe-2 col-form-label text-sm-end">처리 내용</label>
						</div>
						<div class="col-md-12">
							<textarea type="text" class="form-control w-100" id="ansCn--${pageName}" name="ansCn" data-map="ANS_CN" rows="14" data-maxlengthb="4000">
							</textarea>
						</div>
					</div>
				</div> <!-- 심의 정보 <div class="card"> -->
			</div> <!-- <div class="col-xl-3 mx-0"> -->
		</div> <!-- <div class="d-flex flex-row justify-content-evenly"> -->
	</form>
</div>

<script>
	/**************************************************************************
	 * Global Variable
	 **************************************************************************/
	// URL
	var ${pageName}PrefixUrl = "/excl/excl02";
	// FormFields
 	var ${pageName}Fields = new FormFields("#frmEdit--${pageName}");
 	// 파일 리스트
 	var $fileListArr = new Array();

	/**************************************************************************
	 * DatasetControl
	 **************************************************************************/
	var ${pageName}Control = new DatasetControl({
		  prefix : "opnn"
		, prefixName : "의견제출"
		, keymapper : info => info ? info.OPNN_ID : ""
		, dataGetter : obj => obj.opnnSbmsn
		, formats : {
			  RCPT_YMD : dateFormat
			, ANS_YMD_TM : datetimeFormat
		}
	});

	${pageName}Control.onCurrentChange = item => {
		// Dataset 셋팅
		${pageName}Fields.set(item);

 		if (item.data.OPNN_ID != null) {
 			// 첨부파일 조회
 			fnSearchFileList${pageName}(item.data.OPNN_ID);
 		}
	}

	/**************************************************************************
	 * DatasetControl 이벤트
	 **************************************************************************/
	// 의견제출 dialog
	${pageName}Control.getInfo = (params) => {
		let dialogTitle = "";

		if (params.callPurpose == "create") {
			dialogTitle = ${pageName}Control.prefixName + " 등록";
		} else if (params.callPurpose == "update") {
			dialogTitle = ${pageName}Control.prefixName + " 수정";
		} else {
			return;
		}

		ajax.get({
			  url : wctx.url("/" + params.taskSeCd + ${pageName}PrefixUrl + "/020/info.do")
			, data : params || {}
			, success : resp => {
				if ((typeof resp) != "string") {
					if (resp.retMessage != "") {
						dialog.alert(resp.retMessage);
						return;
					}
				}

				dialog.open({
					  id : ${pageName}Control.prefixed("Dialog")
					, title : dialogTitle
					, content : resp
					, size : "xl"
					, onClose : () => { refreshDataInfo${pageName}(); }			// callback 자료 재조회
				});
			}
		});
	}

	// 삭제 callback
	${pageName}Control.onRemove = (resp) => {
		if (resp.saved) {
			refreshDataInfo${pageName}();										// 자료 재조회
		}
	}

	// 삭제
	${pageName}Control.removeOpnnSbmsn = (params) => {
		ajax.post({
			  url : wctx.url("/excl/excl02/010/remove.do")
			, data : params || {}
			, success : resp => ${pageName}Control.onRemove(resp)
		});
	}

	/**************************************************************************
	 * function
	 **************************************************************************/
	// 심의 dialog
	getInfoOpnnSbmsnDlbrt = (params) => {
		ajax.get({
			  url : wctx.url("/excl/excl02/030/info.do")
			, data : params || {}
			, success : resp => {
				dialog.open({
					  id : ${pageName}Control.prefixed("SbmsnDialog")
					, title : ${pageName}Control.prefixName + " 심의 처리"
					, content : resp
					, size : "lg"
					, onClose : () => { refreshDataInfo${pageName}(); }			// callback 자료 조회
				});
			}
		});
	}

	// 자료 재조회
	refreshDataInfo${pageName} = () => {
		let crdnId = $("#crdnId--${pageNameMain}").val();

		// 단속 ID 가 없다면.. return
		if (crdnId == null || crdnId == "") {
			return;
		}

		let params = {
			  callPurpose : "view"
			, crdnId : crdnId
			, delYn : "N"
		};

		ajax.get({
			  url : wctx.url("/sprt/sprt02/030/info.do")
			, headers: { Accept: "application/json; charset=utf-8" }			// json
			, data : params || {}
			, success : resp => {
				if (resp.opnnSbmsn) {
					${pageName}Control.setData([resp.opnnSbmsn]);
				} else {
					$("#frmEdit--${pageName}")[0].reset();
				}

				// 최상단 단속 Data 셋팅
				if (resp.totalInfo) {
					${pageNameMain}Control.setData([resp.totalInfo]);
				}
			}
		});
	}

	/**************************************************************************
	 * 초기 셋팅
	 **************************************************************************/
	// 검색조건 초기값 셋팅
	initForm${pageName} = () => {

	}

	// 이벤트 설정
	setEvent${pageName} = () => {

	}

	/**************************************************************************
	 * 버튼 clickEvent
	 **************************************************************************/
	// 의견제출 등록
	fnCreateOpnnSbmsn${pageName} = () => {
		let crdnId = $("#crdnId--${pageNameMain}").val();
		let sggCd = $("#sggCd--${pageNameMain}").val();
		let taskSeCd = $("#taskSeCd--${pageNameMain}").val();

		// 단속 ID 가 없다면.. return
		if (crdnId == null || crdnId == "") {
			return;
		}

		let params = {
			  callPurpose : "create"
			, crdnId : crdnId
			, sggCd : sggCd
			, taskSeCd : taskSeCd
		};

		${pageName}Control.getInfo(params);
	}

	// 의견제출 수정
	fnUpdateOpnnSbmsn${pageName} = () => {
		let crdnId = $("#crdnId--${pageNameMain}").val();
		let sggCd = $("#sggCd--${pageNameMain}").val();
		let taskSeCd = $("#taskSeCd--${pageNameMain}").val();
		let opnnId = ${pageName}Control.dataset.getValue("OPNN_ID");

		// 의견 ID 가 없다면.. return
		if (opnnId == null || opnnId == "") {
			return;
		}

		let params = {
			  callPurpose : "update"
			, crdnId : crdnId
			, sggCd : sggCd
			, taskSeCd : taskSeCd
			, opnnId : opnnId
		};

		${pageName}Control.getInfo(params);
	}

	// 의견제출 삭제
	fnRemoveOpnnSbmsn${pageName} = () => {
		let crdnId = $("#crdnId--${pageNameMain}").val();
		let sggCd = $("#sggCd--${pageNameMain}").val();
		let taskSeCd = $("#taskSeCd--${pageNameMain}").val();
		let opnnId = ${pageName}Control.dataset.getValue("OPNN_ID");

		// 의견 ID 가 없다면.. return
		if (opnnId == null || opnnId == "") {
			return;
		}
		// 단속 상태 코드
		let crdnSttsCd = ${pageName}Control.dataset.getValue("CRDN_STTS_CD");

		if (crdnSttsCd > "51") {
			dialog.alert(${pageName}Control.dataset.getValue("CRDN_STTS_NM") + " 자료는 의견제출을 삭제할 수 없습니다.");
			return;
		}

		let params = {
			  callPurpose : "remove"
			, crdnId : crdnId
			, sggCd : sggCd
			, taskSeCd : taskSeCd
			, opnnId : opnnId
		};

		dialog.alert({
			  content : "선택한 의견제출 정보를 삭제하시겠습니까?"
			, onOK : () => {
				${pageName}Control.removeOpnnSbmsn(params);
			}
		});
	}

	// 의견제출 심의
	fnUpdateOpnnSbmsnDlbrt${pageName} = () => {
		let opnnId = ${pageName}Control.dataset.getValue("OPNN_ID");
		let crdnId = ${pageName}Control.dataset.getValue("CRDN_ID");

		// 의견제출 ID 가 없다면.. return
		if (opnnId == null || opnnId == "") {
			return;
		}

		let params = {
			  callPurpose : "update"
			, opnnId : opnnId
			, crdnId : crdnId
		};

		getInfoOpnnSbmsnDlbrt(params);
	}

	// 심의의결서 출력
	fnPrintDlbrtLtfr${pageName} = () => {
		alert("심의의결서 출력");
	}

	// 첨부파일 조회
	fnSearchFileList${pageName} = (opnnId) => {
		// 의견제출 등록일 경우에는 첨부파일을 조회하지 안는다..
		if (opnnId == null || opnnId == "") {
			return;
		}

		let iLoop = 0;
		// 기존 table에 자료가 존재하면 table 삭제
		let fileListTable = document.getElementById("fileList--${pageName}");	// table element 찾기

		if (fileListTable.rows.length == 1) { iLoop = 2; }
		else { iLoop = 1; }

		for (iLoop; iLoop <= fileListTable.rows.length; iLoop++) {
			let newRow = fileListTable.deleteRow(fileListTable.rows.length-1);	// table 행(Row) 삭제
		}

	    // 첨부파일 리스트
	    ajax.get({
			  url : "file/list.do"
			, data : {
				  infoType : "110"
				, infoKeys : opnnId
				, fetchSize : 0
			}
			, success : resp => {
				let fileNo = 0;
				let fileList = resp.fileList;

				fileList.forEach(function (item, index, array) {
					fileNo = index + 1;

					let innerHtml = "";

					innerHtml += "<tr>";
					innerHtml += "<td class='text-center'>" + fileNo + "</td>";
					innerHtml += "<td class='text-center'>" + item.FILE_ID + "</td>";
					innerHtml += "<td class='text-center'>" + item.FILE_NM + "</td>";
					innerHtml += "<td class='text-center'>" + item.FILE_SIZE + " byte</td>";
					innerHtml += "<td class='text-center'>" + "<button type='button' class='btn' onclick='fnFileDownload${pageName}(" + item.FILE_ID + ");'><i class='bx bx-download me-1'></i></button>" + "</td>";
					innerHtml += "</tr>";

					$("#fileList--${pageName} > tbody:last").append(innerHtml);
				});
			}
		});
	}

	// 첨부파일 다운로드
	fnFileDownload${pageName} = (fileID) => {
		top.location.href = "/file/download.do?fileID=" + fileID;
	}

	/**************************************************************************
	 * script 진입
	 **************************************************************************/
	$(document).ready(function() {
		// 이벤트 설정
		setEvent${pageName}();

		// 화면 초기 설정
		initForm${pageName}();

		// 의견제출 정보 Data 셋팅
		let opnnSbmsn = ${opnnSbmsn};
		if (opnnSbmsn) {
			${pageName}Control.setData([opnnSbmsn]);
		}
	});

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