<%@ 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 p-3">
		<div class="row mb-3 justify-content-start">
			<div class="col-md-12">
				<div class="float-start">
					<button type="button" name="btnPrintNhtPdf01" class="btn btn-info">고지서출력(PDF-A4)</button>
<%--					
					<button type="button" name="btnPrintNhtPdf02" class="btn btn-info">고지서서출력(PDF-Letter)</button>
--%>
					<button type="button" name="btnPrintNhtOutsourcing" class="btn btn-info">고지서출력(외주파일)</button>
					<button type="button" name="btnOpenOtptStng" class="btn btn-primary">설정</button>
				</div>
			</div>
		</div>

		<div class="card-datatable text-nowrap mb-3">
			<div class="dataTables_wrapper dt-bootstrap5 no-footer">
				<div class="table-responsive ox-scroll oy-scroll h-px-300">
					<table name="table" class="table-layout-fixed dataTable datatables-ajax table table-bordered no-footer">
						<thead class="sticky-thead" >
							<tr name="theadTr">
								<th style="width:50px">
									<input type="checkbox" class="form-check-input" checked
									name="gridAllCheckbox"
									onchange="GRID.checkbox.sync(this, this.checked);" />
								</th>
								<th style="width:120px">시군구명</th>
								<th style="width:180px">과태료명</th>
								<th style="width:120px">차량번호</th>
								<th style="width:120px">대체차량번호</th>
								<th style="width:200px">단속일시</th>
								<th style="width:200px">단속장소</th>
								<th style="width:120px">고지번호</th>
								<th style="width:120px">잔액</th>
								<th style="width:300px">가상계좌번호</th>
								<th style="width:120px">처리상태</th>
								<th style="width:120px">성명</th>
								<th style="width:400px">주소</th>
								<th style="width:400px">번지</th>
							</tr>
						</thead>
						<tbody name="tbody">
						</tbody>
						<template is="curly-brackets" name="found">
							<tr data-key="CRDN_ID" onclick="pageObject['${pageName}'].clickGrid(this);">
								<td>
									<input type="checkbox" class="form-check-input" name="gridCheckbox" value="CRDN_ID" checked
									onchange="GRID.checkbox.sync(this, this.checked);" />
								</td>
								<td>SGG_NM</td>
								<td>TASK_SE_NM</td>
								<td>VHRNO</td>
								<td>RPM_SZR_VHRNO</td>
								<td>CRDN_YMD_TM</td>
								<td>CRDN_PLC</td>
								<td>GOJI_NO</td>
								<td>LAST_AMT</td>
								<td>VR_ACTNO</td>
								<td>CRDN_STTS_NM</td>
								<td>RTPYR_NM</td>
								<td>RTPYR_ADDR</td>
								<td>RTPYR_DTL_ADDR</td>
							</tr>
						</template>
					</table>
				</div>
			</div>
		</div>

		<form name="frmEdit">


		</form>

	</div>
</div>

<script>

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

pageObject.childReq = [];
pageObject.childReq.push({
	getInfo : function(){ return null; },
	isAllSameTask : function(){ return false; }
});

$(document).ready(function(){

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

	$P.crdnIds = ${crdnIds};

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

	//그리드클릭
	$P.clickGrid = (element) => {
		var key = element.dataset.key;

		$P.$findn("tbody").setCurrentRow(key);

		var info = $P.provided.getInfo(key);
		var formFields = new FimsFormFields($P.selectorn("frmEdit"));
		formFields.set(null,info);
	}

	$P.fnMakeFile = (fileType, paper) => {
		var checkboxes = $P.$findn("tbody").find("input[type='checkbox']:checked");
		if(checkboxes.length < 1){
			alert("체크된 자료가 없습니다.");
			return;
		}

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

		var checkedCrdnIds = [];
		checkboxes.each(function(){
			checkedCrdnIds.push(this.value);
		});

		if(!$P.provided.isAllSameTask(checkedCrdnIds)){
			alert("여러 건 출력시 과태료업무가 동일한 자료만 처리 가능합니다.")
			return;
		}

		var sample = checkedCrdnIds[0]; //체크된것중첫번째

		var taskSeCd = $P.provided.getInfo(sample).TASK_SE_CD;

		var url = "";
		var fileTypeName = "";
		if(fileType == "pdf"){
//			url = wctx.url("/sprt/sprt01/150/makeNhtPdf.do");
			url = wctx.url("/preview/notice.do");
			fileTypeName = "PDF 파일";
		} else if(fileType == "outsourcing"){
			url = wctx.url("/sprt/sprt01/150/makeNhtOutsourcing.do");
			fileTypeName = "외주 요청 파일";
		}

		var formFields = new FimsFormFields($P.selectorn("frmEdit"));
		var globalVariable = formFields.get();

		var submitParam = {
			sggCd : MY_INFO.info.sggCd,
			taskSeCd : taskSeCd,
			crdnIds : checkedCrdnIds.join(",")
		};

		var inBrowser = false;
		if(fileType == "pdf"){
			submitParam.paperSeCd = paper;
			inBrowser = true;
		}

		if(inBrowser){
			var parameter = toQuery(submitParam);
			var filenameInHeader = "";

			fetch(url + "?" + parameter)
			.then((response) => {
				var header = response.headers.get('Content-Disposition');
				if(!header){
					response.json().then((responseJson)=>{
						dialog.alert({
							content: fileTypeName+" 생성 중 오류가 발생하였습니다."
									+"<br/>"
									+responseJson.description,
							init: () => { AppSupport.setDialogZindex(); }
						});
					});
					new Error("");
				}
				var parts = header.split(';');
			    filenameInHeader = decodeURIComponent(parts[1].split('=')[1]);
				return response.blob();
			})
			.then((blob) => {
				AppSupport.openPDF(blob, filenameInHeader);
			})
			.catch(()=>{});
		} else {
			var parameter = toQuery(submitParam);
			document.location.href = url + "?" + parameter;
		}

	}

	$P.fnOpenOtptStng = () => {
		var checkboxes = $P.$findn("tbody").find("input[type='checkbox']:checked");
		if(checkboxes.length < 1){
			alert("체크된 자료가 없습니다.");
			return;
		}

		var checkedCrdnIds = [];
		checkboxes.each(function(){
			checkedCrdnIds.push(this.value);
		});

		var fix = "";
		if($P.provided.isAllSameTask(checkedCrdnIds)){
			var sample = checkedCrdnIds[0]; //체크된것중첫번째
			fix = $P.provided.getInfo(sample).TASK_SE_CD;
		}

		var url = wctx.url("/stng/stng01/010/main.do");

		ajax.post({
			url : url,
			data : {},
			success : (resp) => {
				let dialogName = "otptStngDialog";
				let dialogId = dialogName+"-"+uuid();

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

						AppSupport.setDialogZindex();

						let refDlgId = $P.refDlgId(dialogName);

						$("#"+refDlgId).find("form[name='frmSearch']").find("[name='sggCd']").val(MY_INFO.info.sggCd);

						if(fix != ""){
							var taskSeSelectbox = $("#"+refDlgId).find("form[name='frmSearch']").find("[name='taskSeCd']");
							taskSeSelectbox.val(fix);
							taskSeSelectbox.attr("disabled","disabled");
						}

						$("#"+refDlgId).find("form[name='frmSearch']").find("[name='sndngSeCd']").val("03");
					}
					, onClose : () => { }
				});
			}
		});

	}

	//버튼이벤트
	$P.$findn("btnPrintNhtPdf01").on("click", () => $P.fnMakeFile('pdf','01') );
	$P.$findn("btnPrintNhtPdf02").on("click", () => $P.fnMakeFile('pdf','02') );
	$P.$findn("btnPrintNhtOutsourcing").on("click", () => $P.fnMakeFile('outsourcing') );
	$P.$findn("btnOpenOtptStng").on("click", () => $P.fnOpenOtptStng() );

	//첫번째 줄 클릭
	$P.$findn("tbody").find("tr:eq(0)").click();
});
//# sourceURL= sprt01150-info.jsp
</script>