ajax페이지 호출로 변경

This commit is contained in:
주우성
2025-06-17 14:45:17 +09:00
parent a3b00ea643
commit ef5d815949
9 changed files with 783 additions and 1415 deletions

View File

@@ -82,195 +82,7 @@
</div>
<div class="modal-content">
<div class="modal-content-inner">
<form id="popupForm">
<input type="hidden" name="id" id="id">
<input type="hidden" name="transferType" id="transferType">
<p class="form-desc">필수입력</p>
<section class="form-group">
<!-- 재배형태 -->
<div class="select-group">
<div class="select-label">
<p class="label-txt">
재배형태
</p>
<span class="label-sub-txt">임산물 수입이 있는 경우, 등록해 주세요.</span>
</div>
<div id="cropCodeSelect" class="component-select bottom-sheet" data-props-default="재배형태를 선택해 주세요"
data-props-type="bottomSheet">
<input type="hidden" name="cropCode" id="cropCode"/>
<button type="button" class="select-box">
<span class="select-txt">재배형태를 선택해 주세요</span>
</button>
<div class="select-options">
<div class="select-header">
<p>재배형태</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<th:block th:each="item : ${codeRecordCropList}">
<li class="option" th:data-value="${item.id}"
th:text="${item.codeText}">
</li>
</th:block>
</ul>
</div>
</div>
</div>
</div>
</section>
<hr>
<section class="form-group">
<!-- 수입의 종류 -->
<div class="select-group">
<div class="select-label">
<p class="label-txt">
수입의 종류
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</p>
</div>
<div id="transferCategorySelect" class="component-select bottom-sheet" data-props-default="수입 종류를 선택해 주세요"
data-props-type="bottomSheet">
<input type="hidden" name="transferCategory" id="transferCategory"/>
<button type="button" class="select-box">
<span class="select-txt"></span>
</button>
<div class="select-options">
<div class="select-header">
<p>수입의 종류</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<th:block th:each="item : ${transferCategoryList}">
<li class="option" th:data-value="${item.id}"
th:text="${item.codeText}">
</li>
</th:block>
</ul>
</div>
</div>
</div>
<!-- 수당 인풋 -->
<!-- transferCategory+Text-->
<th:block th:each="item : ${transferCategoryList}">
<div class="component-input " th:data-option="${item.codeText}">
<div class="input-field">
<input type="text" th:id="${item.id}+'_value'" th:name="${item.id}+'_value'" value="" placeholder="수입 대상을 입력해 주세요." maxlength="30">
</div>
<ul class="input-info">
<li style="display:none">수입 대상을 입력해 주세요.</li>
<li class="txt-blue" th:if="${item.msgCode}" th:text="${item.msgCode}"></li>
</ul>
</div>
</th:block>
</div>
<!-- 수입원 -->
<div class="component-input">
<div class="input-label">
<label for="sourcePurpose" class="label-txt">
수입원
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</label>
</div>
<div class="input-field">
<input type="text" id="sourcePurpose" placeholder="수입원을 입력해 주세요" name="sourcePurpose" maxlength="30">
</div>
</div>
</section>
<hr>
<section class="form-group">
<!-- 수량 -->
<div class="component-input">
<div class="input-label">
<label for="count" class="label-txt">
수량
</label>
</div>
<div class="input-field">
<input type="number" id="count" placeholder="수량을 입력해 주세요" name="count" class="limitDecimalLength">
</div>
<ul class="guide-info">
<li>예 : 2, 2.5</li>
</ul>
</div>
<!-- 단위 -->
<div class="select-group">
<div class="select-label">
<p class="label-txt">
단위
</p>
</div>
<div id="unitCodeSelect" class="component-select bottom-sheet" data-props-default="단위를 선택해 주세요"
data-props-type="bottomSheet">
<input type="hidden" name="unitCode" id="unitCode">
<button type="button" class="select-box">
<span class="select-txt">선택</span>
</button>
<div class="select-options">
<div class="select-header">
<p>단위</p>
<button type="button" class="select-close">
<span class="hide-txt">닫기</span>
</button>
</div>
<div class="select-scroll">
<ul class="">
<th:block th:each="item : ${unitList}">
<li class="option" th:data-value="${item.id}"
th:text="${item.codeText}">option1
</li>
</th:block>
</ul>
</div>
</div>
</div>
</div>
</section>
<hr>
<section class="form-group">
<!-- 현금 -->
<div class="component-input ">
<div class="input-label">
<label for="price" class="label-txt">
현금
<i class="ico-required-mark" role="img" aria-label="필수">*</i>
</label>
</div>
<div class="input-field type-price">
<input type="number" id="price" placeholder="금액을 입력해 주세요" name="price" class="limitAmountLength">
<span class="input-field-txt">원</span>
</div>
<ul class="input-info" style="display:none">
<li>금액을 입력해 주세요.</li>
</ul>
<ul class="guide-info">
<li>예 : 30000</li>
</ul>
</div>
</section>
<div class="component-btns">
<div class="btns-row">
<button type="button" class="btn btn-full btn-l btn-primary" onclick="formControl.saveFormData()">
<span class="btn-txt">등록</span>
</button>
</div>
</div>
</form>
</div>
</div>
<button type="button" class="modal-close"></button>
@@ -311,9 +123,10 @@
},
elementRefs: {
noDataCheckbox: document.getElementById("forestProductStatus"),
addButton: {
button: null,
icon: null
select:{
cropCodeSelect : null,
transferCategorySelect : null,
unitCodeSelect : null,
}
},
isSubmitted: false
@@ -334,7 +147,6 @@
bindDecimalLimit() {
document.querySelectorAll(".limitDecimalLength").forEach(input => {
input.addEventListener("input", () => {
alert('22');
let val = input.value.replace(/[^0-9.]/g, '');
const parts = val.split('.');
if (parts.length > 2) val = parts[0] + '.' + parts.slice(1).join('');
@@ -420,15 +232,55 @@
}
},
openAddForm() {
const modalContent = document.querySelector('.modal-content');
setTimeout(() => {
modalContent.scrollTop = 0;
}, 0);
//초기화 안됨
['cropCodeSelect', 'transferCategorySelect', 'unitCodeSelect']
.forEach(id => etUI.components.SelectBox().core.init(document.getElementById(id)));
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('#transferCategorySelect');
ENV.elementRefs.select.transferCategorySelect = new etUI.components.SelectBox();
ENV.elementRefs.select.transferCategorySelect.core.init($select2,{
selectItemCallback({selectValue, dataValue}){
document.querySelector('#transferCategory').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'
);
ENV.module.modalPopup.open();
},
handleNoDataToggle() {
if (!ENV.data.editable && ENV.data.currentStatus == "NOTHING") {
@@ -472,7 +324,9 @@
},
saveFormData() {
const form = document.getElementById('popupForm');
kri.form.errorInit(form);
const selects = ['cropCode', 'transferCategory', 'unitCode'];
selects.forEach(id => {
const sel = document.getElementById(id + 'Select');
@@ -481,8 +335,8 @@
const errors = [];
if (!form.transferCategory.value) errors.push({field: 'transferCategory', message: '수입종류를 선택해주세요.'});
if (form.transferCategory.value && document.getElementsByName(form.transferCategory.value+"_value")
&& !document.getElementsByName(form.transferCategory.value+"_value").value){
if (form.transferCategory.value && document.getElementById(form.transferCategory.value+"_value")
&& !document.getElementById(form.transferCategory.value+"_value").value){
errors.push({field: form.transferCategory.value+"_value", message: '수입대상을 입력해주세요.'});
}
if (!form.sourcePurpose.value) errors.push({field: 'sourcePurpose', message: '수입원을 입력해주세요.'});
@@ -492,18 +346,20 @@
message: '단위를 선택해주세요.'
});
if (!form.price.value) errors.push({field: 'price', message: '금액을 입력해주세요.'});
console.log(errors) //////////////////////////
kri.form.error(errors);
if (errors.length > 0) return;
if (errors.length > 0) {
return;
}
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.productList.findIndex(item => item.id == product.id);
if (idx !== -1) ENV.data.productList[idx] = product;
else ENV.data.productList.push(product);
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);
@@ -523,6 +379,39 @@
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;
});
ENV.elementRefs.select.cropCodeSelect.setValue(product.cropCode);
ENV.elementRefs.select.transferCategorySelect.setValue(product.transferCategory);
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();
},
}
@@ -531,98 +420,68 @@
//화면에 아이템 추가
addItem(product, isEdit) {
const listBody = document.getElementById('listBody');
const form = document.getElementById('popupForm');
form.reset();
listBody.style.display = '';
const format = val => Number(val).toLocaleString() || '-';
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 tag01 = product.transferCategory == 'code.bank.input.99' ? product[`${product.transferCategory}_value`] :getCategory(product.transferCategory) ;
const categoryCode = product.transferCategory;
const categoryValue = product[`${categoryCode}_value`];
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 tag1 = product.landArea ? `<span>${format(product.landArea)}평</span>` : '';
let tag2 = '';
if (product.town && product.streetNum) tag2 = `<li><span>${product.town} ${product.streetNum}</span></li>`;
else if (product.town) tag2 = `<li><span>${product.town}</span></li>`;
else if (product.streetNum) tag2 = `<li><span>${product.streetNum}</span></li>`;
const tag3 = product.landType ? `<li><p>지목</p><span>${getPurpose(product.landType)}</span></li>` : '';
const tag4 = product.availableArea ? `<li><p>가능면적</p><span>${format(product.availableArea)}평</span></li>` : '';
let tag5 = '';
if (product.mainYield && product.mainSaleAmount) {
tag5 = `<li><p>주생산물 수확량 / 판매량</p><span>${format(product.mainYield)}${getUnit(product.mainYieldUnitCode)} / ${format(product.mainSaleAmount)}${getUnit(product.mainSaleUnitCode)}</span></li>`;
} else if (product.mainYield) {
tag5 = `<li><p>주생산물 수확량</p><span>${format(product.mainYield)}${getUnit(product.mainYieldUnitCode)}</span></li>`;
} else if (product.mainSaleAmount) {
tag5 = `<li><p>주생산물 판매량</p><span>${format(product.mainSaleAmount)}${getUnit(product.mainSaleUnitCode)}</span></li>`;
}
let tag6 = '';
if (product.subYield && product.subSaleAmount) {
tag6 = `<li><p>부생산물 수확량 / 판매량</p><span>${format(product.subYield)}${getUnit(product.subYieldUnitCode)} / ${format(product.subSaleAmount)}${getUnit(product.subSaleUnitCode)}</span></li>`;
} else if (product.subYield) {
tag6 = `<li><p>부생산물 수확량</p><span>${format(product.subYield)}${getUnit(product.subYieldUnitCode)}</span></li>`;
} else if (product.subSaleAmount) {
tag6 = `<li><p>부생산물 판매량</p><span>${format(product.subSaleAmount)}${getUnit(product.subSaleUnitCode)}</span></li>`;
}
let buttonGroupHtml = '';
if (isEdit) {
buttonGroupHtml = `
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>
<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 div = document.createElement('div');
div.className = 'list-item';
div.dataset.id = product.id;
div.innerHTML = `
<div class="item-tit-group">
<p class="item-name">${product.cropName} ${tag1}</p>
${buttonGroupHtml}
</div>
<ul class="detail-list">${tag2}${tag3}${tag4}${tag5}${tag6}</ul>
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(div, existing) : listBody.appendChild(div);
existing ? listBody.replaceChild(item, existing) : listBody.appendChild(item);
formControl.updateLayout();
}
};
</script>
`<div class="list-item">
<div class="item-tit-group">
<p class="item-name">${tag01} <span>(${product.sourcePurpose})</span></p>
${buttonGroupHtml}
</div>`
<ul class="detail-list">
<li>
<p>재배형태</p>
<span>${getCrop(product.cropCode)}</span>
</li>
<li>
<p>수입원</p>
<span>회사</span>
</li>
<li>
<p>수량</p>
<span>1대</span>
</li>
<li>
<p>현금</p>
<span>1,100,000원</span>
</li>
</ul>
</div>
`