[FO] 개인정보변경 주소 지역,세부지역 셀렉트박스 계층형으로 변경

This commit is contained in:
kangsunlee
2025-06-30 16:26:14 +09:00
parent 141816dc99
commit 2dba290a35
7 changed files with 154 additions and 74 deletions

View File

@@ -258,4 +258,93 @@ $(function() {
$el.val($el.val().replace('.', ''));
}
})
})
})
/**
* 공통코드 기반의 2단계 셀렉트박스(부모/자식) UI를 구성하는 함수
*
* @param {Object} codeList - 공통코드 리스트 객체
* @param {string} parentSelector - 부모 셀렉트박스 셀렉터 (ex. '#regionSubCode')
* @param {string} childSelector - 자식 셀렉트박스 셀렉터 (ex. '#regionDetailCode')
* @param {string} selectedParentCode - 초기 선택할 부모 코드값 (ex. 'code.region.sub.31')
* @param {string} selectedChildCode - 초기 선택할 자식 코드값 (ex. 'code.region.detail.9')
*/
kri.form.setSelectBoxUiCode = function({
codeList,
parentSelector,
childSelector,
selectedParentCode = '',
selectedChildCode = ''
}) {
const $parent = $(parentSelector);
const $child = $(childSelector);
if (!codeList?.nodes || !$parent.length || !$child.length) return;
const renderOptions = ($el, list, selected, inputSelector) => {
let html = '';
list.forEach(item => {
const isCurrent = item.id === selected ? 'current' : '';
html += `<li class="option ${isCurrent}" data-value="${item.id}">${item.codeText}</li>`;
});
$el.html(html);
// 항목 클릭 시 hidden input에 값 반영
$el.find('li.option').off('click').on('click', function () {
const value = $(this).data('value');
const text = $(this).text();
// 표시 텍스트 업데이트
$el.closest('.component-select').find('.select-txt').text(text);
// 선택 클래스 처리
$el.find('li.option').removeClass('current');
$(this).addClass('current');
// hidden input 값 반영
$el.closest('.component-select').find('input[data-type="select"]').val(value).trigger('change');
});
};
let childSelectUI = null;
const loadChildren = (parentId, selectedChild = '') => {
if (!parentId) return;
const $childEl = document.querySelector(childSelector);
if($childEl.ui){
$childEl.ui.core.destroy();
}
const parent = codeList.nodes.find(n => n.id === parentId);
if (!parent?.nodes) return;
const $childList = $child.find('ul');
renderOptions($childList, parent.nodes, selectedChild);
childSelectUI = etUI.components.SelectBox();
childSelectUI.core.init($childEl, {})
};
// 초기 렌더링
const $parentList = $parent.find('ul');
renderOptions($parentList, codeList.nodes, selectedParentCode);
const $parentEl = document.querySelector(parentSelector);
const parentSelectUI = new etUI.components.SelectBox();
parentSelectUI.core.init($parentEl, {});
if (selectedParentCode) {
loadChildren(selectedParentCode, selectedChildCode);
}
// 부모 셀렉션 변경 시 자식 재로드
$parent.find('ul').on('click', 'li.option', function () {
const newParentCode = $(this).data('value');
loadChildren(newParentCode);
});
return {
getParentValue: () => parentSelectUI.getValue(),
getChildValue: () => childSelectUI?.getValue() ?? ''
};
}