(function() { 'use strict'; class NewPatientPage { constructor() { this.choicesInstances = new Map(); this.data = { nationality: '', nationalityCode: '', // 선택된 국적 코드 저장용 visitPath: '' }; this.isInitialized = false; this.KOREA_CODE = 'C202404180007'; this.allowSystemCheck = false; } init() { if (this.isInitialized) return; if (!this.validateDependencies() || !this.validateDOM()) { this.scheduleRetry(); return; } this.initChoices(); this.loadCommonCategories(); this.bindEvents(); this.isInitialized = true; } validateDependencies() { return !!($ && window.Choices); } validateDOM() { return !!(document.querySelector('#selectNationality')); } scheduleRetry() { setTimeout(() => this.init(), 150); } bindEvents() { const $rrn1 = $('input[name="modalUserRrn1"]'); const $rrn2 = $('input[name="modalUserRrn2"]'); $rrn2.on('keyup input', (e) => { const rrn1Val = $rrn1.val(); const rrn2Val = $(e.target).val(); if (rrn1Val.length === 6 && rrn2Val.length >= 1) { this.handleRrnInput(rrn1Val, rrn2Val.charAt(0)); } }); const nationalityInstance = this.choicesInstances.get('nationality'); if (nationalityInstance) { const element = nationalityInstance.passedElement.element; element.addEventListener('change', (event) => { this.data.nationalityCode = event.detail.value; // 국적 코드 업데이트 this.updateUIByNationality(event.detail.value); }); } $('#modalAddress, #btnSearchAddress').on('click', () => { this.openAddrSearch(); }); // 체크박스 직접 클릭 방지 및 안내 문구 출력 const consentIds = ['#agreePrivacy', '#agreeProcedure', '#agreeTerms', '#refusePhoto']; $(consentIds.join(', ')).on('click', (e) => { if (!this.allowSystemCheck) { e.preventDefault(); alert('동의서 보기 버튼을 클릭하여 내용을 확인하신 후 [동의함] 버튼을 눌러주세요.'); } }); } updateUIByNationality(selectedCode) { const $rrnLabel = $('label[for="modalUserRrn1"], .form-row:has(input[name="modalUserRrn1"]) label').first(); const $passportBox = $('.foreigner_box'); if (selectedCode === this.KOREA_CODE) { $rrnLabel.text('주민등록번호'); $passportBox.hide(); } else { $rrnLabel.text('외국인등록번호'); $passportBox.show(); } } handleRrnInput(rrn1, genderDigitStr) { const genderDigit = parseInt(genderDigitStr, 10); const isMale = [1, 3, 5, 7].includes(genderDigit); if (isMale) $('#genderM').prop('checked', true); else $('#genderF').prop('checked', true); let yearPrefix = [1, 2, 5, 6].includes(genderDigit) ? '19' : '20'; const year = yearPrefix + rrn1.substring(0, 2); const month = rrn1.substring(2, 4); const day = rrn1.substring(4, 6); $('#modalBirthday').val(`${year}${month}${day}`); const today = new Date(); let age = today.getFullYear() - parseInt(year); const birthDate = new Date(year, month - 1, day); const m = today.getMonth() - birthDate.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) age--; $('.txtAge').text(`만 ${age}세`); } initChoices() { const choicesConfig = { searchEnabled: true, itemSelectText: '', shouldSort: false, placeholderValue: '선택하세요' }; ['nationality', 'channel'].forEach(key => { const selector = key === 'nationality' ? '#selectNationality' : '#selectChannel'; this.choicesInstances.set(key, new Choices(selector, choicesConfig)); }); } loadCommonCategories() { const categories = [{ code: 'C202404110001', key: 'nationality' }, { code: 'C202404110003', key: 'channel' }]; categories.forEach(({ code, key }) => this.fetchCategory(code, key)); } fetchCategory(code, choicesKey) { $.post('/kiosk/getCategoryItem.do', { categoryCode: code }, (data) => { if (data.rows?.length > 0) { const choices = data.rows.map(item => ({ value: item.categoryItemCode || item.commonCode, label: item.categoryItemName || item.codeName })); const instance = this.choicesInstances.get(choicesKey); if (instance) { instance.setChoices(choices, 'value', 'label', true); if (choicesKey === 'nationality') { instance.setChoiceByValue(this.KOREA_CODE); this.data.nationalityCode = this.KOREA_CODE; // 초기 국적 설정 this.updateUIByNationality(this.KOREA_CODE); } } } }); } openAddrSearch() { // 1. 다이얼로그를 담을 컨테이너 생성 (없으면 생성) let $addrDialog = $('#addrSearchDialog'); if ($addrDialog.length === 0) { $addrDialog = $('
').appendTo('body'); } // 2. jQuery UI Dialog 초기화 $addrDialog.dialog({ modal: true, title: '주소 검색', width: 500, height: 500, resizable: false, draggable: true, open: function() { const guideElement = document.getElementById('addrSearchDialog'); // 3. daum.Postcode를 해당 div 내(embed)에 실행 new daum.Postcode({ oncomplete: (data) => { let addr = data.userSelectedType === 'R' ? data.roadAddress : data.jibunAddress; document.getElementById("modalAddress").value = addr; document.getElementById("modalAddressDetail").focus(); // 선택 완료 후 다이얼로그 닫기 $addrDialog.dialog('close'); }, width: '100%', height: '100%' }).embed(guideElement); }, close: function() { $(this).dialog('destroy').empty(); } }); } } /** * [Modal] 고객 검색 팝업 클래스 * 작성일 : 2024. 04. 02. * 작성자 : NTsoft (Refactored to Class) */ /** * [Modal] 고객 검색 팝업 클래스 (jQuery UI Dialog 버전) */ class UserIntroSelectModal { constructor() { this.callback = null; this.dataList = null; this.modalId = 'userIntroSelectModal'; } init() { $(`#${this.modalId}`).remove(); $('body').append(this.getHtmlTemplate()); $(`#${this.modalId}`).dialog({ autoOpen: false, modal: true, width: 450, // 3개 항목이므로 너비를 좀 더 슬림하게 조정 resizable: false, draggable: true, dialogClass: 'user-select-dialog', // CSS 커스텀 클래스 연결 open: function() { $(".ui-dialog-titlebar").hide(); // 타이틀바 숨김 $('.ui-widget-overlay').css({ 'opacity': 0.5, 'background': '#000' }); } }); this.setEvent(); } setEvent() { const $modal = $(`#${this.modalId}`); $modal.find('.btnCancle').on("click", () => $modal.dialog("close")); $modal.find('#searchIntroUserBtn').on('click', () => this.searchIntroUserList()); $modal.find('#introUserSearchKeyword').on('keypress', (e) => { if (e.which === 13) this.searchIntroUserList(); }); } searchIntroUserList() { const searchKeyword = document.querySelector("#introUserSearchKeyword").value; if (searchKeyword.length < 2) { alert("검색어를 2자 이상 입력해주세요."); return; } const formData = new FormData(); formData.append("menuClass", window.menuClass || ""); formData.append("userSearchKeywordParam", searchKeyword); // 정렬 파라미터 추가 formData.append("userSort", "BIRTHDAY DESC"); $.ajax({ url: encodeURI('/webuser/selectListUserOption.do'), data: formData, dataType: "json", processData: false, contentType: false, type: 'POST', success: (data) => { if (data.msgCode === '0') this.renderTable(data.rows); } }); } renderTable(rows) { const tbody = document.querySelector(`#${this.modalId} tbody`); tbody.innerHTML = ""; this.dataList = rows; if (!rows || rows.length === 0) { tbody.innerHTML = '