521 lines
16 KiB
HTML
521 lines
16 KiB
HTML
<!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>
|
|
<strong>은행 자동이체(수입) 내역 0건 등록</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">
|
|
<span class="btn-txt">이전 정보 불러오기</span>
|
|
</button>
|
|
|
|
|
|
<div class="component-input align-center" id="forestProductStatusDiv">
|
|
<label class="checkbox-inner">
|
|
<input type="checkbox" id="forestProductStatus" name="forestProductStatus"
|
|
th:value="${MonthStatus.NOTHING}" onchange="formControl.handleNoDataToggle()">
|
|
<span class="checkbox-item"><span class="checkbox-txt">이번달 등록내용 없음</span></span>
|
|
</label>
|
|
</div>
|
|
|
|
</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',
|
|
save: /*[[|/api/front#{uri.front.info.bank.path}/create|]]*/ 'saveUrl'
|
|
},
|
|
module: {
|
|
modalPopup: null
|
|
},
|
|
data: {
|
|
transferCategoryCodeList: /*[[${transferCategoryList}]]*/ [],
|
|
codeRecordCropList: /*[[${codeRecordCropList}]]*/ [],
|
|
unitList: /*[[${unitList}]]*/ [],
|
|
bankList : /*[[${bankList.content}]]*/ [],
|
|
pastBankList : /*[[${pastBankList.content}]]*/ [],
|
|
id: /*[[${currentMonthlyInfo.id}]]*/'',
|
|
currentStatus: /*[[${currentMonthlyInfo.bankAutoTransferInputStatus}]]*/'',
|
|
pastStatus: /*[[${pastMonthlyInfo?.bankAutoTransferInputStatus}]]*/'',
|
|
editable: /*[[${editable}]]*/,
|
|
},
|
|
elementRefs: {
|
|
noDataCheckbox: document.getElementById("forestProductStatus"),
|
|
select:{
|
|
cropCodeSelect : null,
|
|
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;
|
|
});
|
|
});
|
|
},
|
|
loadingLayout() {
|
|
//아이템 추가 버튼
|
|
const addItemBtn = document.getElementById("addItemBtn");
|
|
const icon = addItemBtn.querySelector("i");
|
|
//이전 데이터 취득 버튼
|
|
const callPastInfoBtn = document.getElementById("callPastInfoBtn");
|
|
|
|
//데이터 없음 버튼
|
|
const forestProductStatus = document.getElementById("forestProductStatus");
|
|
|
|
//등록 완료 버튼
|
|
const next = document.getElementById('complateBtn');
|
|
|
|
const clearAllItems = document.getElementById('clearAllItems');
|
|
|
|
if (ENV.data.pastBankList.length == 0) {
|
|
callPastInfoBtn.disabled = true;
|
|
}
|
|
|
|
if (ENV.data.editable) {
|
|
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 == "NOTHING") {
|
|
|
|
|
|
addItemBtn.disabled = true;
|
|
icon.classList.toggle("ico-add", false);
|
|
icon.classList.toggle("ico-add-disabled", true);
|
|
callPastInfoBtn.disabled = true;
|
|
forestProductStatus.checked = true;
|
|
next.disabled = true;
|
|
|
|
} 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() {
|
|
ajaxUtil._ajaxAsyncMethod(
|
|
"/api/front/info/bank/create/input/from",
|
|
{},
|
|
function(rstHtml, status) {
|
|
$('.addPopup').find('.modal-content-inner').html(rstHtml);
|
|
|
|
|
|
const $select1 = document.querySelector('#cropCodeSelect');
|
|
ENV.elementRefs.select.cropCodeSelect = new etUI.components.SelectBox();
|
|
ENV.elementRefs.select.cropCodeSelect.core.init($select1,{
|
|
selectItemCallback({selectValue, dataValue}){
|
|
document.querySelector('#cropCode').value=dataValue;
|
|
}
|
|
});
|
|
|
|
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;
|
|
}
|
|
});
|
|
|
|
ENV.module.modalPopup.open();
|
|
},
|
|
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 isChecked = ENV.elementRefs.noDataCheckbox.checked;
|
|
const btn = document.getElementById("addItemBtn");
|
|
const icon = btn.querySelector("i");
|
|
|
|
const status = document.getElementById('forestProductStatusDiv');
|
|
const callPastInfoBtn = document.getElementById("callPastInfoBtn");
|
|
|
|
const next = document.getElementById('complateBtn');
|
|
const header = document.getElementById('listHeader');
|
|
const count = document.getElementById('listCount');
|
|
const total = ENV.data.bankList.length;
|
|
|
|
|
|
header.style.display = total > 0 ? '' : 'none';
|
|
status.style.display = total > 0 ? 'none' : '';
|
|
callPastInfoBtn.style.display = total > 0 ? 'none' : '';
|
|
count.textContent = total;
|
|
|
|
|
|
btn.disabled = isChecked;
|
|
icon.classList.toggle("ico-add", !isChecked);
|
|
icon.classList.toggle("ico-add-disabled", isChecked);
|
|
if (isChecked) {
|
|
next.disabled = !isChecked;
|
|
} else {
|
|
next.disabled = total <= 0;
|
|
}
|
|
|
|
},
|
|
saveFormData() {
|
|
|
|
const form = document.getElementById('popupForm');
|
|
kri.form.errorInit(form);
|
|
const selects = ['cropCode', '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 (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.sourcePurpose.value) errors.push({field: 'sourcePurpose', message: '수입원을 입력해주세요.'});
|
|
|
|
if (form.count.value && !form.unitCode.value) errors.push({
|
|
field: 'unitCode',
|
|
message: '단위를 선택해주세요.'
|
|
});
|
|
if (!form.price.value) errors.push({field: 'price', message: '금액을 입력해주세요.'});
|
|
console.log(errors) //////////////////////////
|
|
kri.form.error(errors);
|
|
if (errors.length > 0) {
|
|
return;
|
|
}
|
|
|
|
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.unitList.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();
|
|
|
|
setTimeout(function(){
|
|
|
|
const form = document.getElementById('popupForm');
|
|
|
|
Object.entries(product).forEach(([key, val]) => {
|
|
const field = form.elements.namedItem(key);
|
|
if (field) {
|
|
field.value = val;
|
|
if(key == 'transferCategoryCode'){
|
|
document.getElementById(val+"_value").value = product["transferCategory"];
|
|
}
|
|
}
|
|
});
|
|
|
|
ENV.elementRefs.select.cropCodeSelect.setValue(product.cropCode);
|
|
ENV.elementRefs.select.transferCategoryCodeSelect.setValue(product.transferCategoryCode);
|
|
ENV.elementRefs.select.unitCodeSelect.setValue(product.unitCode);
|
|
},100)
|
|
|
|
},
|
|
// 선택 아이템 삭제
|
|
deleteItemById(id) {
|
|
ENV.data.bankList = ENV.data.bankList.filter(p => p.id != id);
|
|
const target = document.querySelector(`#listBody div[data-id='${id}']`);
|
|
if (target) target.remove();
|
|
this.updateLayout();
|
|
},
|
|
// 전체 초기화
|
|
clearAllItems() {
|
|
location.reload();
|
|
},
|
|
|
|
goSave() {
|
|
|
|
|
|
ajaxUtil._ajaxAsync(
|
|
ENV.httpUrl.save,
|
|
{
|
|
status: ENV.elementRefs.noDataCheckbox.checked,
|
|
id: ENV.data.id,
|
|
bankList: ENV.data.bankList
|
|
},
|
|
function (rstData, status) {
|
|
if (rstData.code === 'SUCCESS') {
|
|
ajaxUtil._alert('등록이 완료되었습니다.', null, function () {
|
|
|
|
history.back()
|
|
});
|
|
} 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 getCrop = formControl.getCropLabel;
|
|
|
|
const categoryCode = product.transferCategoryCode;
|
|
const categoryCodeInputValue = product.transferCategory;
|
|
const categoryValue = product[`${categoryCode}_value`] ? product[`${categoryCode}_value`] : categoryCodeInputValue;
|
|
const tagTitle = categoryCode === 'code.bank.input.99'
|
|
? categoryValue
|
|
: `${getCategory(categoryCode)}<span>(${categoryValue})</span>`;
|
|
|
|
const tagCount = product.count
|
|
? `<li><p>수량</p><span>${format(product.count)}${getUnit(product.unitCode)}</span></li>`
|
|
: '';
|
|
|
|
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">
|
|
<li><p>재배형태</p><span>${getCrop(product.cropCode)}</span></li>
|
|
<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> |