Files
korea-research/front/src/main/resources/templates/info/bank/output.html
2025-11-11 17:53:04 +09:00

618 lines
20 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html layout:decorate="~{layout/layout-none}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<div layout:fragment="content" th:classappend="'mypage'">
<main id="content" role="main">
<div class="inner">
<hgroup class="tit-group">
<h3>
[[${currentMonthlyInfo.koreanMonth}]]의 <br>
<strong>은행 자동이체(지출) 내역 <span id="totalItems">[[${bankList.totalElements}]]</span>건 등록</strong> 되었습니다.
</h3>
<p>지출 내역을 등록해 주세요.</p>
</hgroup>
<section class="regist-item-area">
<p class="total" style="display: none" id="listHeader">
<span>총 <strong id="listCount">0</strong>건</span>
<button type="button" class="btn-reset" onclick="formControl.clearAllItems()" id="clearAllItems">
<i class="ico-reset ico-small" aria-hidden="true"></i>
<span>초기화</span>
</button>
</p>
<div class="item-list" style="display: none" id="listBody">
</div>
<button type="button" class="btn btn-m btn-secondary btn-full" style="margin-bottom:1.2rem"
id="addItemBtn" onclick="formControl.openAddForm()">
<i class="ico-add ico-small" aria-hidden="true"></i>
<span class="btn-txt">추가 등록</span>
</button>
<button type="button" class="btn btn-m btn-link btn-full" id="callPastInfoBtn" onclick="formControl.checkUsePastData()">
<span class="btn-txt">이전 정보 불러오기</span>
</button>
</section>
</div>
</main>
<!-- 하단 고정 버튼 -->
<div class="component-btns fixed">
<div class="btns-row">
<!-- 비활성화 스타일/ 버튼 속성 disabled 추가-->
<button type="button" class="btn btn-l btn-primary" id="complateBtn" disabled onclick="formControl.goSave()">
<span class="btn-txt">등록 완료</span>
</button>
</div>
</div>
<!-- 모달 팝업 -->
<div class="layer-wrap">
<div class="component-modal mypage-wrap addPopup" data-props-dimm-click="true" >
<div class="modal-dimm"></div>
<div class="modal-frame">
<div class="modal-container">
<div class="modal-header">
<h3 class="modal-tit">은행 자동이체(지출) 등록</h3>
</div>
<div class="modal-content">
<div class="modal-content-inner">
</div>
</div>
<button type="button" class="modal-close"></button>
</div>
</div>
</div>
</div>
<!-- //모달 팝업 -->
</div>"/api/front/info/bank/create"
<section layout:fragment="script">
<script th:inline="javascript">
// ✅ ENV 구조 (전역 설정 및 상태)
let ENV = {
httpUrl: {
root: /*[[#{uri.front.info.bank.path}]]*/ 'rootUrl',
preMonth: /*[[|/info/bank/create/output|]]*/ 'preMonthUrl',
save: /*[[|/api/front#{uri.front.info.bank.path}/create|]]*/ 'saveUrl'
},
module: {
modalPopup: null
},
modal: {
// 등록 영역
selector: '.addPopup',
},
data: {
transferCategoryCodeList: /*[[${transferCategoryList}]]*/ [],
codeRecordCropList: /*[[${codeRecordCropList}]]*/ [],
countList: /*[[${countList}]]*/ [],
bankList : /*[[${bankList.content}]]*/ [],
pastBankList : /*[[${pastBankList.content}]]*/ [],
id: /*[[${currentMonthlyInfo.id}]]*/'',
currentMonth: /*[[${currentMonthlyInfo.month}]]*/'',
currentStatus: /*[[${currentMonthlyInfo.bankAutoTransferOutputStatus}]]*/'',
pastStatus: /*[[${pastMonthlyInfo?.bankAutoTransferOutputStatus}]]*/'',
pastBankId: /*[[${pastMonthlyInfo?.id}]]*/'',
pastMonth: /*[[${pastMonthlyInfo?.month}]]*/'',
editable: /*[[${editable}]]*/,
preEditable: /*[[${preEditable}]]*/,
},
elementRefs: {
// noDataCheckbox: document.getElementById("forestProductStatus"),
select:{
transferCategoryCodeSelect : null,
unitCodeSelect : null,
}
},
isSubmitted: false
};
const formControl = {
init() {
this.cacheElements();
this.bindDecimalLimit();
this.bindAmountLimit();
this.loadingLayout();
},
cacheElements() {
ENV.module.modalPopup = document.querySelector(".addPopup").ui;
},
bindDecimalLimit() {
document.querySelectorAll(".limitDecimalLength").forEach(input => {
input.addEventListener("input", () => {
let val = input.value.replace(/[^0-9.]/g, '');
const parts = val.split('.');
if (parts.length > 2) val = parts[0] + '.' + parts.slice(1).join('');
if (parts[1]) parts[1] = parts[1].slice(0, 2);
if (val.length > 10) val = val.slice(0, 10);
input.value = parts.join('.');
});
});
},
bindAmountLimit() {
document.querySelectorAll(".limitAmountLength").forEach(input => {
input.addEventListener("input", () => {
let val = input.value.replace(/[^0-9]/g, '');
if (val.length > 10) {
val = val.slice(0, 10);
}
input.value = val;
});
});
},
checkUsePastData() {
etUI.dialog.alert({
title: "이전 정보 불러오기",
message: "이번달 정보를 아직 입력하지 않으셨네요.\n지난달 정보를 불러와 수정하여 등록하시겠어요?\n\n‘예’ 를 선택하시면 지난달 정보를 불러오고\n‘아니오’를 선택하시면 신규 등록이 가능합니다.\n계속 진행하시겠습니까?",
type: "confirm",
dialogType: "confirm",
positiveText: "예",
negativeText: "아니오",
callback: function () {
ENV.data.bankList = JSON.parse(JSON.stringify(ENV.data.pastBankList));
ENV.data.bankList.forEach(data => productRenderer.addItem(data, true));
formControl.updateLayout();
},
});
},
loadingLayout() {
//아이템 추가 버튼
const addItemBtn = document.getElementById("addItemBtn");
const icon = addItemBtn.querySelector("i");
//이전 데이터 취득 버튼
const callPastInfoBtn = document.getElementById("callPastInfoBtn");
//등록 완료 버튼
const next = document.getElementById('complateBtn');
const clearAllItems = document.getElementById('clearAllItems');
if (ENV.data.editable) {
//if (ENV.data.preEditable && ENV.data.pastBankList.length === 0 && ENV.data.currentMonth >= "202508") {
if (ENV.data.preEditable && ENV.data.pastBankList.length === 0) {
callPastInfoBtn.disabled = true;
const handlePageShow = function(event) {
if ('sessionStorage' in window && window['sessionStorage'] !== null) {
// history.back으로 돌아온 경우 (navigation.type == 2)
if (event.persisted || (window.performance && window.performance.navigation.type === 2)) {
sessionStorage.removeItem('pastOutputAlertShown'); // 플래그 제거
return; // 알림창 표시하지 않음
}else if (event.persisted || (window.performance && window.performance.navigation.type <= 1)) {
// 페이지가 처음 로드되었거나 새로고침된 경우 (navigation.type == 0 또는 1)
kri.isReturn = true;
const hasShownAlert = sessionStorage.getItem('pastOutputAlertShown');
if (hasShownAlert !== ENV.data.currentMonth && hasShownAlert !== ENV.data.pastMonth && ENV.data.pastBankList.length === 0) {
callPastInfoBtn.disabled = true;
etUI.dialog.alert({
title: '지난달 정보 등록하기',
message: '지난달 정보를 아직 입력하지 않으셨네요.\n정확한 조사를 위해 지난달 정보를 입력해주세요.\n\n확인 버튼을 누르시면 지난달 은행자동이체 내역등록으로 이동합니다.',
type: 'alert',
callback: function() {
sessionStorage.setItem('pastOutputAlertShown', ENV.data.pastMonth);
location.href = ENV.httpUrl.preMonth + "/" + ENV.data.pastBankId;
},
});
} else if (hasShownAlert === ENV.data.pastMonth) {
sessionStorage.removeItem('pastOutputAlertShown');
}
}
}
};
// 초기 로드 시 실행
handlePageShow({ persisted: false, performance: window.performance });
}
if (ENV.data.currentStatus == "NONE") {
if (ENV.data.pastStatus && ENV.data.pastStatus == "REGISTERED" && ENV.data.pastBankList.length > 0) {
this.checkUsePastData();
}
} else if (ENV.data.currentStatus == "REGISTERED") {
if (ENV.data.bankList.length > 0) {
ENV.data.bankList.forEach(data => productRenderer.addItem(data, true));
this.updateLayout();
} else {
}
}
} else {
if (ENV.data.currentStatus == "REGISTERED") {
if (ENV.data.bankList.length > 0) {
ENV.data.bankList.forEach(data => productRenderer.addItem(data, false));
const header = document.getElementById('listHeader');
const count = document.getElementById('listCount');
const total = ENV.data.bankList.length;
header.style.display = total > 0 ? '' : 'none';
count.textContent = total;
}
}
addItemBtn.disabled = true;
icon.classList.toggle("ico-add", false);
icon.classList.toggle("ico-add-disabled", true);
callPastInfoBtn.disabled = true;
// forestProductStatus.disabled = true;
next.disabled = true;
next.style.display = "none";
clearAllItems.style.display = "none";
}
},
openAddForm(callback) {
ajaxUtil._ajaxAsyncMethod(
"/api/front/info/bank/create/output/from",
{},
function(rstHtml, status) {
$('.addPopup').find('.modal-content-inner').html(rstHtml);
const $select2 = document.querySelector('#transferCategoryCodeSelect');
ENV.elementRefs.select.transferCategoryCodeSelect = new etUI.components.SelectBox();
ENV.elementRefs.select.transferCategoryCodeSelect.core.init($select2,{
selectItemCallback({selectValue, dataValue}){
// document.querySelector('#transferCategory').value=selectValue;
document.querySelector('#transferCategoryCode').value=dataValue;
document.querySelectorAll('div[data-option]').forEach(el => {
el.style.display = 'none';
});
const target = document.querySelector(`div[data-option="${selectValue}"]`);
if (target) {
target.style.display = 'block';
}
}
});
const $select3 = document.querySelector('#unitCodeSelect');
ENV.elementRefs.select.unitCodeSelect = new etUI.components.SelectBox();
ENV.elementRefs.select.unitCodeSelect.core.init($select3,{
selectItemCallback({selectValue, dataValue}){
document.querySelector('#unitCode').value=dataValue;
if(dataValue === "code.count.unit.self") {
document.querySelector('#unit').value="";
document.querySelector('#unitDiv').style.display ='block';
} else {
document.querySelector('#unit').value="";
document.querySelector('#unitDiv').style.display ='none';
}
}
});
ENV.module.modalPopup.open();
window.location.hash = 'modal-open';
document.querySelector('.modal-content').scrollTop = 0;
// 모두 로드된 후 콜백 실행
if (typeof callback === 'function') callback();
},
function(code, rstData) {
kri.logger.error('Do nothing. code: '+ code, rstData);
},
'get',
'html'
);
},
handleNoDataToggle() {
if (!ENV.data.editable && ENV.data.currentStatus == "NOTHING") {
ENV.elementRefs.noDataCheckbox.checked = true;
return;
}
this.updateLayout();
},
updateLayout() {
const callPastInfoBtn = document.getElementById("callPastInfoBtn");
const next = document.getElementById('complateBtn');
const header = document.getElementById('listHeader');
const count = document.getElementById('listCount');
const totalItems = document.getElementById('totalItems');
const total = ENV.data.bankList.length;
const isData = total > 0;
header.style.display = isData ? '' : 'none';
// status.style.display = total > 0 ? 'none' : '';
callPastInfoBtn.style.display = isData ? 'none' : '';
count.textContent = total;
totalItems.textContent = total;
if (isData) {
next.disabled = !isData;
} else {
next.disabled = total <= 0;
}
},
saveFormData() {
const form = document.getElementById('popupForm');
kri.form.errorInit(form);
const selects = [ 'transferCategoryCode', 'unitCode'];
selects.forEach(id => {
const sel = document.getElementById(id + 'Select');
if (sel && sel.value) form[id].value = sel.value;
});
const errors = [];
if (!form.transferCategoryCode.value) errors.push({field: 'transferCategoryCode', message: '지출 종류를 선택해 주세요.'});
if(document.getElementById(form.transferCategoryCode.value+"_value")){
if (form.transferCategoryCode.value && document.getElementById(form.transferCategoryCode.value+"_value")
&& !document.getElementById(form.transferCategoryCode.value+"_value").value){
errors.push({field: form.transferCategoryCode.value+"_value", message: '지출의 종류를 입력해주세요.'});
}
}
if (form.count.value && form.count.value <= 0) errors.push({field: 'count', message: '입력값은 0보다 커야 합니다. '});
if(form.count.value){
if(!form.unitCode.value){
errors.push({
field: 'unitCode',
message: '단위를 선택해주세요.'
});
} else if (form.unitCode.value && form.unitCode.value =="code.count.unit.self" && !form.unit.value){
errors.push({
field: 'unit',
message: '단위를 입력해주세요.'
});
}
}
if (!form.price.value) errors.push({field: 'price', message: '금액을 입력해주세요.'});
else if (form.price.value && form.price.value <= 0) errors.push({field: 'price', message: '입력값은 0보다 커야 합니다. '});
// console.log(errors) //////////////////////////
kri.form.error(errors);
if (errors.length > 0) {
return;
}
if(document.getElementById(form.transferCategoryCode.value+"_value")){
form.transferCategory.value = document.getElementById(form.transferCategoryCode.value+"_value").value;//입력값
}
const formData = new FormData(form);
const product = {};
formData.forEach((value, key) => product[key] = value);
product.id = product.id ? Number(product.id) : Math.floor(Math.random() * 1000000) + 1;
const idx = ENV.data.bankList.findIndex(item => item.id == product.id);
if (idx !== -1) ENV.data.bankList[idx] = product;
else ENV.data.bankList.push(product);
ENV.module.modalPopup.close();
setTimeout(() => productRenderer.addItem(product, true), 300);
},
getCategoryLabel(code) {
const found = ENV.data.transferCategoryCodeList.find(i => i.id === code);
return found ? found.codeText : '-';
},
// 단위 코드
getUnitLabel(code) {
const found = ENV.data.countList.find(i => i.id === code);
return found ? found.codeText : '-';
},
// 재배형태
getCropLabel(code) {
const found = ENV.data.codeRecordCropList.find(i => i.id === code);
return found ? found.codeText : '-';
},
editItemById(id) {
const product = ENV.data.bankList.find(p => p.id == id);
if (!product) return;
this.openAddForm(() => {
const form = document.getElementById('popupForm');
if (!form) return;
Object.entries(product).forEach(([key, val]) => {
const field = form.elements.namedItem(key);
if (field) {
field.value = val;
if (key === 'transferCategoryCode' && val === "code.bank.output.self") {
document.getElementById(val + "_value").value = product["transferCategory"];
}
if (key === 'unitCode' && val === "code.count.unit.self") {
document.getElementById("unitDiv").style.display = "";
}
}
});
if (product.transferCategoryCode === "code.bank.output.self") {
const transferCategoryInput = document.getElementById(product.transferCategoryCode + "_value");
if (transferCategoryInput) {
transferCategoryInput.value = product.transferCategory || "";
}
}
// 단위 입력 필드 표시 여부 처리
if (product.unitCode === "code.count.unit.self") {
const unitDiv = document.getElementById("unitDiv");
if (unitDiv) {
unitDiv.style.display = "";
}
}
ENV.elementRefs.select.transferCategoryCodeSelect.setValue(product.transferCategoryCode);
ENV.elementRefs.select.unitCodeSelect.setValue(product.unitCode);
document.getElementById("unit").value = product.unit;
});
},
// 선택 아이템 삭제
deleteItemById(id) {
etUI.dialog.alert({
title: '삭제 안내',
message: '등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.',
type: 'confirm',
dialogType: 'confirm',
callback: function () {
ENV.data.bankList = ENV.data.bankList.filter(p => p.id != id);
const target = document.querySelector(`#listBody div[data-id='${id}']`);
if (target) target.remove();
formControl.updateLayout();
},
});
},
// 전체 초기화
clearAllItems() {
etUI.dialog.alert({
title: '초기화 안내',
message: '등록하신 모든 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.',
type: 'confirm',
dialogType: 'confirm',
callback: function () {
ENV.data.bankList = [];
document.getElementById('listBody').innerHTML = '';
formControl.updateLayout();
},
});
},
goSave() {
ajaxUtil._ajaxAsync(
ENV.httpUrl.save,
{
// status: ENV.elementRefs.noDataCheckbox.checked,
id: ENV.data.id,
transferType:"code.bank.output",
bankList: ENV.data.bankList
},
function (rstData, status) {
if (rstData.code === 'SUCCESS') {
ajaxUtil._alert('등록이 완료되었습니다.', null, function () {
location.href = '/info/bank/' + ENV.data.currentMonth;
});
} else if (rstData.code === 'ERROR') {
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', null);
}
},
);
}
}
const productRenderer = {
//화면에 아이템 추가
addItem(product, isEdit) {
const listBody = document.getElementById('listBody');
listBody.style.display = '';
const format = val => {
const num = Number(val);
return isNaN(num) ? '-' : num.toLocaleString();
};
const getUnit = formControl.getUnitLabel;
const getCategory = formControl.getCategoryLabel;
const categoryCode = product.transferCategoryCode;
const categoryCodeInputValue = product.transferCategory;
const categoryValue = product[`${categoryCode}_value`] ? product[`${categoryCode}_value`] : categoryCodeInputValue;
const tagTitle = categoryCode === 'code.bank.output.self'
? categoryCodeInputValue
: `${getCategory(categoryCode)}`;
let tagCount = '';
if (product.count > 0) {
const unitText = product.unitCode !== 'code.count.unit.self'
? getUnit(product.unitCode)
: product.unit;
tagCount = `<li><p>수량</p><span>${format(product.count)}${unitText}</span></li>`;
} else {
tagCount = '';
}
const buttonGroupHtml = isEdit
? `
<div class="btn-group">
<button type="button" class="delete" onclick="formControl.deleteItemById(${product.id})">
<span class="hide-txt">삭제</span>
</button>
<button type="button" class="edit" onclick="formControl.editItemById(${product.id})">
<span class="hide-txt">수정</span>
</button>
</div>
`
: '';
const itemHtml = `
<div class="item-tit-group">
<p class="item-name">${tagTitle}</p>
${buttonGroupHtml}
</div>
<ul class="detail-list">
${product.sourcePurpose != null && product.sourcePurpose != ''
? `<li><p>용도</p><span>${product.sourcePurpose}</span></li>`
: ''}
${tagCount}
<li><p>현금</p><span>${format(product.price)}원</span></li>
</ul>
`;
const item = document.createElement('div');
item.className = 'list-item';
item.dataset.id = product.id;
item.innerHTML = itemHtml;
const existing = listBody.querySelector(`[data-id="${product.id}"]`);
existing ? listBody.replaceChild(item, existing) : listBody.appendChild(item);
formControl.updateLayout();
}
};
</script>
`
</section>
</html>