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

                <div class="row g-1">
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcptNo">접수번호</label>
                        <input is="id-input" type="text" class="form-control w-30" name="rcptNo" data-map="RCPT_NO" readonly />
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="rcptYmd">접수일자</label>
                        <input is="id-input" type="text" class="form-control w-25" name="rcptYmd" data-map="RCPT_YMD" data-fmt-type="day" readonly />
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="sttrNm">성명</label>
                        <input is="id-input" type="text" class="form-control w-30" name="sttrNm" data-map="STTR_NM" readonly />
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end" for="opnnSbmsnSeNm">의견제출구분</label>
                        <input is="id-input" type="text" class="form-control w-50" name="opnnSbmsnSeNm" data-map="OPNN_SBMSN_SE_NM" readonly />
                    </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="opnnSbmsnGist">의견제출내용</label>
                        <textarea is="id-textarea" class="form-control w-85" name="opnnSbmsnGist" data-map="OPNN_SBMSN_CN" rows="2" data-maxlengthb="300" readonly></textarea>
                    </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="opnnSbmsnGist">의견제출요지</label>
                        <textarea is="id-textarea" class="form-control w-85" name="opnnSbmsnGist" data-map="OPNN_SBMSN_GIST" rows="2" data-maxlengthb="300" readonly></textarea>
                    </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="picRvwOpnn">검토의견</label>
                        <textarea is="id-textarea" class="form-control w-85" name="picRvwOpnn" data-map="PIC_RVW_OPNN" rows="3" data-maxlengthb="1000"></textarea>
                    </div>
                    <div class="col-md-6">
                        <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-40" name="docNo" data-map="DOC_NO" />
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="ntfctnSeCd">통보구분</label>
                        <select is="id-select" class="form-select" name="ntfctnSeCd" data-map="NTFCTN_SE_CD" required>
                            <option value="">선택하세요</option>
                            <c:forEach items="${FIM030List}" var="item">
                                <option value="${item.code}">${item.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="opnnSbmsnSttsCd">심의결과</label>
                        <select is="id-select" class="form-select" name="opnnSbmsnSttsCd" data-map="OPNN_SBMSN_STTS_CD" onchange="pageObject['${pageName}'].fnChangeOpnnSbmsnSttsCd(this.value);" required>
                            <option value="">선택하세요</option>
                            <c:forEach items="${FIM031List}" var="item">
                                <option value="${item.code}">${item.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="ansYmd">심의일시</label>
                        <input is="id-input" type="text" class="form-control form-date" name="ansYmd" data-map="ANS_YMD"
                            data-fmt-type="day" maxlength="10" required />
                        <button type="button" class="bx bx-lg bx-calendar bg-white" name="btnAnsYmd"></button>
                        <input is="id-input" type="text" class="form-control form-time" name="ansTm" data-map="ANS_TM"
                            data-fmt-type="time" maxlength="8" placeholder="시:분:초" required />
                    </div>
                    <div class="col-md-6" name="divRdctRsnCd">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="rdctRsnCd">감경사유</label>
                        <select is="id-select" class="form-select" name="rdctRsnCd" data-map="RDCT_RSN_CD">
                            <c:forEach items="${FIM019List}" var="item">
                                <option value="${item.code}">${item.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="col-md-6" name="divRdctAmt">
                        <label is="name-label" class="col-form-label bg-lighter pe-2 w-px-120 text-sm-end required" for="rdctAmt">감경금액</label>
                        <input is="id-input" type="text" class="form-control w-30 text-end" name="rdctAmt" data-map="RDCT_AMT" data-fmt-type="number" readonly />
                    </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="ansCn">심의내용</label>
                        <textarea is="id-textarea" class="form-control w-85" name="ansCn" data-map="ANS_CN" rows="5" data-maxlengthb="4000"></textarea>
                    </div>
                </div>
            </form>
            <!-- 입력 영역 -->

            <!-- 업무 버튼 및 건수 표시 -->
            <div>
                <span class="container-page-btn">
                    <!-- 업무 버튼 -->
                    <span class="container-window-btn-right">
                        <button type="button" class="btn btn-primary w-px-120" name="btnSave" title="저장">
                            저장
                        </button>
                    </span>
                </span>
            </div>
            <!-- 업무 버튼 및 건수 표시 -->
        </div> <!-- <div class="card"> -->
    </div> <!-- <div class="container flex-grow-1 px-0"> -->
    <!-- Content -->
</div>
<!-- inner page html <div class="content-pop"> -->

<script>
   LoadScript("excl02030Script", wctx.url("/resources/js/fims/excl/excl02030.js?ver=${ver}"));

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

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

        // URL
        $P.prefixUrl = "${prefixUrl}";
        // infoDialog 호출 용도(view 조회(편집불가), create 등록, update 수정)
        $P.callPurpose = "${callPurpose}";
        // datasetControl
        $P.ctrl = newExcl02030Control("${pageName}", "[data-doctx=${pageName}]");

        /**************************************************************************
         * 사용자 함수(function)
         **************************************************************************/
        // 의견제출 상태 코드 변경
        $P.fnChangeOpnnSbmsnSttsCd = (obj) => {
            // javascript를 이용한 visibility 변경 (이 방법을 사용하는 경우, 안에 있는 요소들이 보이지않지만 그 요소들이 할당 하고 있는 공간은 그대로 유지(공백처리))
//             document.getElementById("divRdctRsnCd--${pageName}").style.visibility = "hidden";
//             document.getElementById("divRdctRsnCd--${pageName}").style.visibility = "visible";
            $P.$findn("divRdctRsnCd").hide();
            $P.$findn("divRdctAmt").hide();
            $P.$findn("rdctRsnCd").attr("required", false);
            $P.$findn("rdctAmt").attr("required", false);

            if (obj == "04") {                                                  // 의견제출 상태 코드(FIM031) 04: 과태료감경
                // 필수 선택 추가 필요
                $P.$findn("divRdctRsnCd").show();
                $P.$findn("divRdctAmt").show();
                $P.$findn("rdctRsnCd").attr("required", true);
                $P.$findn("rdctAmt").attr("required", true);
            }
        }

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

            // 감경 사유 확인
            let opnnSbmsnSttsCd = $P.$findn("opnnSbmsnSttsCd").val();
            let rdctRsnCd = $P.$findn("rdctRsnCd").find("option:selected").val();
            let rdctRsnNm = $P.$findn("rdctRsnCd").find("option:selected").text();

            if (opnnSbmsnSttsCd == "04" && rdctRsnCd == "00")
                return dialog.alert({
                      content: "감경사유가 '" + rdctRsnNm + "' 입니다."
                            + "<br>" + "[" + $P.ctrl.prefixName + "]" + " 저장 실행이 취소되었습니다."
                    , init: () => { AppSupport.setDialogZindex(); }
                    , onOK: () => { }
                });

            // formFields
            let params = new FimsFormFields($P.selectorn("frmEdit")).get();

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

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

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

            // 기본 데이터 설정
            $P.$findn("ansYmd").datepicker("setDate", TODAY());                 // 답변 일자
            $P.$findn("ansTm").val(new Date().toTimeString().split(" ")[0]);    // 답변 시각

            // 화면 호출(callPurpose)이 view라면 버튼 비활성화 disabled = true
            if ($P.callPurpose == "view") {
                // input 요소들을 disabled
                $P.$findn("frmEdit").find("input,textarea,select").prop("disabled", true);

                // button 요소들을 disabled
                $P.$findn("btnAnsYmd").prop("disabled", true);                  // 답변 일자 달력 버튼
                $P.$findn("btnSave").prop("disabled", true);                    // 저장 버튼
            }
        }

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

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

        // 3. Dataset 설정
        $P.ctrl.setData([${Info}]);
    });

</script>
