Files
korea-research/admin/src/main/resources/templates/households/modal/modal-bank-auto-transfer-expense.html

273 lines
12 KiB
HTML

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout/layout}">
<div class="layer-wrap" th:fragment="modalFragment">
<!-- 은행자동이체(지출) 등록 모달 폼 -->
<form autocomplete="off" method="get" name="reqBankExpenseForm">
<input type="hidden" name="bankAutoTransferId">
<input type="hidden" name="householdSeq" th:value="${seq}">
<input type="hidden" name="recordMonth">
<input type="hidden" name="expenseCode">
<div class="component-modal mypage-wrap modal01 modal-bank-expense" data-props-dimm-click="true" data-state="close">
<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">
<!-- <i class="ico-required-mark" role="img" aria-label="필수">*</i><p>필수입력</p>-->
<table class="type-form confirm">
<colgroup>
<col width="10%" />
<col width="40%" />
<col width="10%" />
<col width="40%" />
</colgroup>
<tbody>
<tr>
<th>지출의 종류<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td>
<div class="d-flex">
<div class="component-select">
<select class="select-list" name="transferCategoryCode" onchange="selectedExpenseCategory(this);" required>
<option value="">선택</option>
<option th:each="item : ${bankOutputCodes}"
th:value="${item.id}"
th:text="${item.codeText}"
th:data-code-value="${item.codeValue}"
th:data-code-type="${item.codeType}">
</select>
</div>
<!-- 직접입력 항목 -->
<div class="component-input self-input">
<div class="input-field">
<input type="text" class="transfer-category-self" name="transferCategory" maxlength="30" disabled>
</div>
</div>
</div>
</td>
<th>용도</th>
<td>
<div class="component-input">
<div class="input-field">
<input type="text" id="sourcePurpose" name="sourcePurpose" maxlength="30">
</div>
</div>
</td>
</tr>
<tr>
<th>수량</th>
<td>
<div class="component-input">
<div class="input-field">
<input type="number" id="count" name="count"
maxlength="10" inputmode="decimal" oninput="limitMaxLength(this);">
</div>
</div>
</td>
<th>단위</th>
<td>
<div class="d-flex">
<div class="component-select">
<select class="select-list" name="unitCode" onchange="selectedSelf(this);" required>
<option value="">선택</option>
<option th:each="item : ${countUnitCodes}"
th:value="${item.id}"
th:text="${item.codeText}">
</select>
</div>
<!-- 직접입력 수량 단위 -->
<div class="component-input self-input">
<div class="input-field">
<input type="text" id="unit" name="unit" maxlength="30" disabled>
</div>
</div>
</div>
</td>
</tr>
<tr>
<th>현금(원)<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td >
<div class="component-input">
<div class="input-field">
<input type="number" id="price" name="price"
maxlength="10" inputmode="numeric" oninput="limitMaxLength(this);">
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div class="component-btns bottom-btn-group">
<div class="btns-row align-right">
<button type="button" class="btn btn-primary" onclick="saveBankExpense();">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</div>
</div>
<button type="button" class="modal-close"></button>
</div>
</div>
</div>
</form>
<script>
// 은행자동이체(수입) 모달창 띄우기
const showBankExpenseModal = (id) => {
const f = document.reqBankExpenseForm;
const reqForm = document.reqForm;
f.recordMonth.value = reqForm.recordMonth.value;
// 폼 초기화
resetBankExpenseForm();
if(id != null) {
f.bankAutoTransferId.value = id;
ajaxUtil._ajaxMethod(
`/api/household/bankAutoTransferExpense/${id}`,
{},
(response) => {
console.log("은행자동이체(지출) 상세 응답값 : ", response);
setBankExpenseFormData(response);
document.querySelector(".modal-bank-expense").ui.open();
},
function (code, rstData) {
console.log("error : ", code);
},
'get',
'json'
);
} else {
document.querySelector(".modal-bank-expense").ui.open();
}
}
// 은행이체내역(수입) 상세 값 set
const setBankExpenseFormData = (data) => {
const form = document.reqBankExpenseForm;
if (!form) return;
form.bankAutoTransferId.value = data.id ?? '';
form.householdSeq.value = data.householdSeq ?? '';
form.expenseCode.value = data.expenseCode ?? '';
form.count.value = data.count ?? '';
form.unitCode.value = data.unitCode ?? '';
form.unit.value = data.unit ?? '';
form.price.value = data.price ?? '';
form.sourcePurpose.value = data.sourcePurpose ?? '';
form.transferCategoryCode.value = data.transferCategoryCode ?? '';
toggleSelfInput(form.expenseCode.value, form.transferCategory);
toggleSelfInput(form.unitCode.value, form.unit);
}
</script>
<script>
// form 초기화
const resetBankExpenseForm = () => {
const form = document.reqBankExpenseForm;
if (!form) return;
const skipInputs = [
'householdSeq',
'recordMonth'
];
// input 초기화
form.querySelectorAll('input').forEach((el) => {
if (!skipInputs.includes(el.name)) {
el.value = '';
// 직접입력 영역이면 비활성화 처리
const wrapper = el.closest('.self-input') || el.closest('.target-input');
if (wrapper) {
el.disabled = true;
wrapper.classList.add('input-disabled');
}
}
});
// select 초기화
form.querySelectorAll('select').forEach((el) => {
el.selectedIndex = 0;
});
}
</script>
<script>
// 은행이체내역(수입) 저장 및 수정
const saveBankExpense = () => {
const f = document.reqBankExpenseForm;
if (!f) return;
let dataOj = $(f).serializeObject();
console.log("dataOj", dataOj);
ajaxUtil._ajaxMethod(
'/api/household/bank/expense/save',
JSON.stringify(dataOj),
() => { // 성공
alert("등록이 완료되었습니다.");
document.querySelector(".modal-bank-expense").ui.close();
getBankAutoTransfer();
},
function (code, rstData) {
if(code == 422) alert(rstData.responseJSON[0].defaultMessage);
},
'post',
'json',
{ handle422Type: 'alert' }
);
}
</script>
<script>
// 지출의 종류 선택에 따른 직접입력 input 과 대상 input disabled 처리
const selectedExpenseCategory = (el) => {
const f = document.reqBankExpenseForm;
f.expenseCode.value = '';
const selectedOption = el.options[el.selectedIndex];
const codeValue = selectedOption.dataset.codeValue;
f.expenseCode.value = codeValue;
const tr = el.closest('tr');
const selfArea = tr.querySelector('.self-input');
const selfInput = tr.querySelector('.self-input input');
if (el.value?.endsWith('.self')) {
selfInput.disabled = false;
selfArea.classList.remove('input-disabled');
} else {
selfInput.disabled = true;
selfInput.value = '';
selfArea.classList.add('input-disabled');
}
}
</script>
</div>
</html>