<%@ 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" data-doctx="${pageName}">
    <!-- Content -->
    <div class="container flex-grow-1 px-0">
        <div class="card wrapper-pop">
            <!-- 입력 영역 -->
            <form name="frmEdit">
                <input type="hidden" name="sggCd" />
                <input type="hidden" name="taskSeCd" />
                <input type="hidden" name="vltnCd" />

                <div class="row g-1">
                    <div class="col-md-12 text-end px-2">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end">총건수 / 총금액</label>
                        <input is="id-input" type="text" class="form-control w-px-80  text-end" name="tnocs" data-fmt-type="number" readonly />
                        <input is="id-input" type="text" class="form-control w-px-140 text-end" name="gramt" data-fmt-type="number" readonly />
                    </div>
                    <div class="col-md-4">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="docNo">문서번호</label>
                        <input is="id-input" type="text" class="form-control w-55" name="docNo" autocomplete="off" />
                    </div>
                    <div class="col-md-4">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="sndngYmd">발송일자</label>
                        <input is="id-input" type="text" class="form-control form-date" name="sndngYmd"
                            data-fmt-type="day" autocomplete="off" title="날짜 선택" maxlength="10" required />
                        <button type="button" class="bx bx-lg bx-calendar bg-white" name="btnSndngYmd"></button>
                    </div>
                    <div class="col-md-4" name="divSndngEndYmd">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="sndngEndYmd">납기일자</label>
                        <input is="id-input" type="text" class="form-control form-date" name="sndngEndYmd"
                            data-fmt-type="day" autocomplete="off" title="날짜 선택" maxlength="10" />
                        <button type="button" class="bx bx-lg bx-calendar bg-white" name="btnSndngEndYmd"></button>
                    </div>
                    <div class="col-md-12">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="ttlNm">제목</label>
                        <input is="id-input" type="text" class="form-control w-87" name="ttlNm" autocomplete="off" />
                    </div>
                    <div class="col-md-12">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end align-top" for="etcCn">기타내용</label>
                        <textarea is="id-textarea" class="form-control w-87" name="etcCn" rows="2" data-maxlengthb="1000" autocomplete="off"></textarea>
                    </div>
                </div> <!-- <div class="row g-1"> -->
            </form>
            <!-- 입력 영역 -->

            <!-- 업무 버튼 및 건수 표시 -->
            <div>
                <span class="container-page-btn" name="gridButtonArea">
                    <!-- 건수, 페이지 표시 -->
                    <div class="d-flex flex-row justify-content-between">
                        <span is="paging-info" class="dataTables_info" name="dataPagingInfo" role="status" aria-live="polite"></span>
                        <ul class="pagination pagination-primary" name="dataPaging">
                        </ul>
                    </div>
                    <!-- 업무 버튼 -->
                    <span class="container-window-btn-right">
                        <button type="button" class="btn btn-primary w-px-120" name="btnSave" title="저장">
                            저장
                        </button>
                    </span>
                </span>
            </div> <!-- 업무 버튼 및 건수 표시 -->

            <!-- DataTables(그리드) -->
            <div class="card-datatable text-nowrap">
                <div class="dataTables_wrapper dt-bootstrap5 no-footer">
                    <div class="table-responsive ox-scroll oy-scroll h-px-300" name="tableRspns">
                        <table class="table-layout-fixed dataTable datatables-ajax table table-bordered no-footer" aria-describedby="DataTables_Table_0_info">
                            <thead class="sticky-thead">
                                <tr name="theadTr" data-search-target="[data-doctx='${pageName}']">
                                    <th class="cmn" style="width: 72px;">No.</th>
                                    <th class="cmn" style="width: 120px;">계도일자</th>
                                    <th class="cmn" style="width: 160px;">계도사유</th>
<%--
                                    <th class="cmn" style="width: 180px;">민원신청번호</th>
                                    <th class="cmn" style="width: 180px;">민원접수번호</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: 160px;">위반항목</th>
                                    <th class="cmn" style="width: 160px;">단속법정동</th>
                                    <th class="cmn" style="width: 280px;">단속장소</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: 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: 180px;">수정일시</th>
                                    <th class="cmn" style="width: 140px;">수정사용자</th>
                                    <th class="cmn dummy-th"></th>
                                </tr>
                            </thead>
                            <tbody name="tbodyList">
                            </tbody>
                            <template is="curly-brackets" name="tmpltRows">
                                <tr data-index="{data-index}">
                                    <td class="cmn text-center" onclick ondblclick>{ROW_NUM}</td>
                                    <td class="cmn text-center" onclick ondblclick>{LEVY_EXCL_YMD}</td>
                                    <td class="cmn text-center" onclick ondblclick>{LEVY_EXCL_RSN_NM}</td>
<%--
                                    <td class="cmn text-center" onclick ondblclick>{CVLCPT_APLY_NO}</td>
                                    <td class="cmn text-center" onclick ondblclick>{CVLCPT_RCPT_NO}</td>
                                    <td class="cmn text-center" onclick ondblclick>{CVLCPT_RCPT_YMD}</td>
                                    <td class="cmn text-center" onclick ondblclick>{CVLCPT_PRCS_NM}</td>
--%>
                                    <td class="cmn text-center" onclick ondblclick>{CRDN_YMD_TM}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{VHRNO}</td>
                                    <td class="cmn text-center" onclick ondblclick>{VLTN_ARTCL}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{CRDN_STDG_NM}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{CRDN_PLC}</td>
                                    <td class="cmn text-end"    onclick ondblclick>{FFNLG_CRDN_AMT}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{CRDN_STTS_NM}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{RTPYR_NM}</td>
                                    <td class="cmn text-center" onclick ondblclick>{RTPYR_BRDT_MASK}</td>
                                    <td class="cmn text-center" onclick ondblclick>{ZIP}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{ADDR}</td>
                                    <td class="cmn text-start"  onclick ondblclick>{DTL_ADDR}</td>
                                    <td class="cmn text-center" onclick ondblclick>{REG_DT}</td>
                                    <td class="cmn text-center" onclick ondblclick>{RGTR_NM}</td>
                                    <td class="cmn text-center" onclick ondblclick>{MDFCN_DT}</td>
                                    <td class="cmn text-center" onclick ondblclick>{MDFR_NM}</td>
                                    <td class="cmn dummy-td"></td>
                                </tr>
                            </template>
                            <template name="tmpltNotFound">
                                <tr class="odd">
                                    <td valign="top" colspan="24" class="dataTables_empty text-center">${prefixName} 정보를 찾지 못했습니다.</td>
                                </tr>
                            </template>
                        </table>
                    </div>
                </div>
            </div> <!-- DataTables(그리드) -->
        </div> <!-- <div class="card wrapper-pop"> -->
        <!-- Page Body -->
    </div> <!-- <div class="container flex-grow-1 px-0"> -->
    <!-- / Content -->
</div>
<!-- / Inner page html -->

<script>
    LoadScript("sndb01020Script", wctx.url("/resources/js/fims/sndb/sndb01020.js?ver=${ver}"));

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

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

        // URL
        $P.prefixUrl = "${prefixUrl}";
        // datasetControl
        $P.ctrl = newSndb01020Control("${pageName}", "[data-doctx=${pageName}]");
        // infoDialog 호출 용도(view 조회(편집불가), create 등록, update 수정)
        $P.callPurpose = "${callPurpose}";
        // main 의 검색 조건을 그대로 유지
        $P.mainQuery = ${mainQuery};

        /**************************************************************************
         * DataTables 이벤트
         **************************************************************************/
        // dataTable 클릭 이벤트
        $P.dataTableClick = (dataIndex) => {
            if (!dataIndex) return;

            $P.$findn("tbodyList").setCurrentRow(dataIndex);

            Apply.toDataset.current($P.ctrl.dataset, dataIndex);
        }

        // dataTable 더블 클릭 이벤트 - 개별총정보 dialog
        $P.dataTableDblClick = (dataIndex) => {
            if (!dataIndex) return;

            crdnTotalInfo({
                  callPageName: "${pageName}"
                , callPurpose: "view"
                , sggCd: $P.ctrl.getValue("SGG_CD")
                , taskSeCd: $P.ctrl.getValue("TASK_SE_CD")
                , crdnId: $P.ctrl.getValue("CRDN_ID")
            });
        }

        // DataTables에 스크롤이 맨 밑으로 이동했을 때 이벤트
        $P.scrollDataList = () => {
            // 페이지
            $P.ctrl.query.pageNum += 1;

            ajax.get({
                  url: $P.ctrl.urls.load
                , headers: { Accept: "application/json; charset=utf-8" }        // json
                , data: $P.ctrl.query
                , success: (resp) => {
                    $P.ctrl.addData(resp);
                }
            });
        }

        /**************************************************************************
         * 사용자 함수(function)
         **************************************************************************/


        /**************************************************************************
         * 버튼 clickEvent
         **************************************************************************/
        // 저장
        $P.fnSave = () => {
            // validate 확인
            if (!AppSupport.customValidate($P.$findn("frmEdit").find("input,select,textarea"))) return;

            dialog.alert({
                  content: "현재 " + $P.ctrl.prefixName + " 정보를 저장하시겠습니까?"
                , init: () => { AppSupport.setDialogZindex(); }
                , onOK: () => {
                    let formFields = new FimsFormFields($P.selectorn("frmEdit")).get(); // formFields

                    // 검색조건과 저장 파라미터 객체를 합친다.
                    let params = $.extend({}, $P.ctrl.query, formFields);
                    params.sndngRegSeCd = "01";                                 // 발송 등록 구분 코드(SNDNG_REG_SE_CD) - 01: 일괄
                    params.rsndYn = "N";                                        // 재발송 여부
                    params.delYn = "N";                                         // 삭제 여부

                    $P.ctrl.save(params);
                }
            });
        }

        /**************************************************************************
         * 초기 셋팅
         **************************************************************************/
        // 이벤트 설정
        $P.setEvent = () => {
            // 버튼 이벤트
            $P.$findn("btnSave").on("click", () => $P.fnSave());                // 저장

            // DataTables 스크롤을 위해서 다이얼로그 화면이 생성된 후 Dataset을 설정한다.
            let modalId = $(document.querySelector("[data-doctx='${pageName}']")).parents(".modal")[0].id;
            $("#" + modalId).on("shown.bs.modal", function (e) {
                $P.ctrl.setData( {List: ${List}, Paging :${Paging}} );

                $P.$findn("tnocs").val($P.ctrl.getValue("TOT_CNT"));            // 총건수
                $P.$findn("gramt").val($P.ctrl.getValue("GRAMT"));              // 총금액
                $P.$findn("sndngYmd").datepicker("setDate", TODAY());           // 발송 일자
                // 발송 종료 일자
                $P.$findn("sndngEndYmd").val("");
                $P.$findn("sndngEndYmd").prop("disabled", true);
                $P.$findn("divSndngEndYmd").hide();
                // 제목
                let ttlNm = $P.ctrl.getValue("TASK_SE_NM");
                if ($P.ctrl.query.schVltnCd) {                                  // 위반항목이 '전체'가 아니라면..
                	let vltnArtcl = $P.ctrl.getValue("VLTN_ARTCL");
                	if (!vltnArtcl.includes(vltnArtcl))
                    	ttlNm = ttlNm + " " + vltnArtcl;
                }
                $P.$findn("ttlNm").val(ttlNm + " 계도장");
            });

            // DataTables width 변경 조정
            Componentization.fnMakeResizableTable($P.findn("tableRspns"));
            // DataTables 스크롤 이벤트 생성
            Componentization.fnMakeScrollableTable($P.findn("tableRspns"), $P.scrollDataList);
        }

        // 초기화 이벤트
        $P.fnReset = () => {
            // 초기화
            $P.findn("frmEdit").reset();                                        // 화면 초기화
            AppSupport.initDatepicker($P.findn("frmEdit"));                     // 달력 초기화

            // 기본 데이터 설정
            $P.$findn("sggCd").val("${sggCd}");                                 // 시군구 코드
            $P.$findn("taskSeCd").val("${taskSeCd}");                           // 업무 구분 코드
            $P.$findn("vltnCd").val("${vltnCd}");                               // 위반 코드
            $P.$findn("sndngYmd").datepicker("setDate", TODAY());               // 발송 일자
            $P.$findn("sndngEndYmd").datepicker("setDate", TODAY());            // 납기 일자

            // 업무 구분에 따른 URL 설정
            $P.ctrl.urls.load   = wctx.url($P.prefixUrl + "/020/info.do");        // 조회
            $P.ctrl.urls.create = wctx.url($P.prefixUrl + "/020/createList.do");  // 등록

            // 검색 조건
            $P.ctrl.query = $P.mainQuery;
        }

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

        // 2. 초기 화면 설정
        $P.fnReset();

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

</script>
