656 lines
23 KiB
HTML
656 lines
23 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-wrap btm-fixbtn'">
|
||
<main id="content" role="main">
|
||
<div class="inner">
|
||
<hgroup class="tit-group">
|
||
<h3>
|
||
[[${currentMonthlyInfo.koreanMonth}]]의 <br>
|
||
<strong>임산물 현황 <span id="totalItems">[[${currentList.totalElements}]]</span>건 등록</strong> 되었습니다.
|
||
</h3>
|
||
<p>임산물 현황을 등록해 주세요.</p>
|
||
</hgroup>
|
||
|
||
<section class="regist-item-area">
|
||
<p class="total" style="display: none" id="listHeader">
|
||
<!-- th:style="${currentList.totalElements == 0 ? 'display:none':''}"-->
|
||
<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">
|
||
<!-- th:style="${currentList.totalElements == 0 ? 'display:none':''}"-->
|
||
|
||
</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">
|
||
<!-- th:style="${pastMonthlyInfo != null && currentList.totalElements == 0 ? '':'display:none'}"-->
|
||
<span class="btn-txt">이전 정보 불러오기</span>
|
||
</button>
|
||
|
||
|
||
<div class="component-input align-center" id="forestProductStatusDiv">
|
||
<!-- th:style="${currentList.totalElements == 0 ? '':'display:none'}"-->
|
||
<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>
|
||
|
||
<ul class="info-bullet-list">
|
||
<li>
|
||
임업과 관련하여 재배 및 채취된 모든 임산물(목재 포함)을 기록해주세요.
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</main>
|
||
|
||
<!-- 하단 고정 버튼 -->
|
||
<div class="component-btns fixed">
|
||
<div class="btns-row">
|
||
<!-- 비활성화 스타일/ 버튼 속성 disable 추가-->
|
||
<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>
|
||
|
||
|
||
<section layout:fragment="script">
|
||
<script th:inline="javascript">
|
||
let ENV = {
|
||
httpUrl: {
|
||
root: /*[[#{uri.front.info.monthly.path}]]*/ 'rootUrl',
|
||
save: /*[[|/api/front#{uri.front.info.monthly.path}/create|]]*/ 'rootUrl'
|
||
},
|
||
module: {
|
||
modalPopup: null
|
||
},
|
||
|
||
data: {
|
||
purposeList: /*[[${purposeList}]]*/ [],
|
||
unitList: /*[[${unitList}]]*/ [],
|
||
// productList: /*[[${currentList.content}]]*/ [],
|
||
productList: /*[[${currentList.content}]]*/[],
|
||
pastProductList: /*[[${pastList.content}]]*/ [],
|
||
id: /*[[${currentMonthlyInfo.id}]]*/'',
|
||
currentStatus: /*[[${currentMonthlyInfo.forestProductStatus}]]*/'',
|
||
pastStatus: /*[[${pastMonthlyInfo?.forestProductStatus}]]*/'',
|
||
editable: /*[[${editable}]]*/,
|
||
},
|
||
elementRefs: {
|
||
noDataCheckbox: document.getElementById("forestProductStatus"),
|
||
select:{
|
||
mainYieldUnitCodeSelect : null,
|
||
mainSaleUnitCodeSelect : null,
|
||
subYieldUnitCodeSelect : null,
|
||
subSaleUnitCodeSelect : null,
|
||
}
|
||
},
|
||
isSubmitted: false
|
||
};
|
||
|
||
|
||
const formControl = {
|
||
init() {
|
||
this.cacheElements();
|
||
this.bindDecimalLimit();
|
||
// this.updateLayout();
|
||
this.loadingLayout();
|
||
// this.checkUsePastData();
|
||
|
||
// ajaxUtil._alert('select 초기화/지정 방법?\n 6월의 카운트와 추가등록의 카운터의 차이?\n 신규 작성 이후 재진입시의 로직?\n 일단 저장데이터 뿌리는것은 막아둠',null);
|
||
},
|
||
checkUsePastData() {
|
||
etUI.dialog.alert({
|
||
title: "이전 정보 불러오기",
|
||
message: "이번달 정보를 아직 입력하지 않으셨네요.\n지난달 정보를 불러와 수정하여 등록하시겠어요?\n\n‘예’ 를 선택하시면 지난달 정보를 불러오고\n‘아니오’를 선택하시면 신규 등록이 가능합니다.\n계속 진행하시겠습니까?",
|
||
type: "confirm",
|
||
dialogType: "confirm",
|
||
positiveText: "예",
|
||
negativeText: "아니오",
|
||
callback: function () {
|
||
ENV.data.productList = JSON.parse(JSON.stringify(ENV.data.pastProductList));
|
||
ENV.data.productList.forEach(data => productRenderer.addItem(data, true));
|
||
formControl.updateLayout();
|
||
},
|
||
});
|
||
},
|
||
//모달창
|
||
cacheElements() {
|
||
ENV.module.modalPopup = document.querySelector(".addPopup").ui;
|
||
},
|
||
// 스크립트 단순화/고도화 필요.
|
||
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.pastProductList.length == 0) {
|
||
callPastInfoBtn.disabled = true;
|
||
}
|
||
|
||
if (ENV.data.editable) {
|
||
if (ENV.data.currentStatus == "NONE") {
|
||
if (ENV.data.pastStatus && ENV.data.pastStatus == "REGISTERED" && ENV.data.pastProductList.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.productList.length > 0) {
|
||
ENV.data.productList.forEach(data => productRenderer.addItem(data, true));
|
||
this.updateLayout();
|
||
} else {
|
||
|
||
}
|
||
}
|
||
} else {
|
||
|
||
if (ENV.data.currentStatus == "REGISTERED") {
|
||
if (ENV.data.productList.length > 0) {
|
||
ENV.data.productList.forEach(data => productRenderer.addItem(data, false));
|
||
const header = document.getElementById('listHeader');
|
||
const count = document.getElementById('listCount');
|
||
const total = ENV.data.productList.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";
|
||
}
|
||
},
|
||
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.productList.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;
|
||
}
|
||
|
||
},
|
||
//숫자입력
|
||
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('.');
|
||
});
|
||
});
|
||
},
|
||
setting() {
|
||
if (ENV.data.productList.length > 0) {
|
||
ENV.data.productList.forEach(data => productRenderer.addItem(data, true));
|
||
}
|
||
this.updateLayout();
|
||
},
|
||
pastMonthlyDataPopup() {
|
||
//pastProductList 출력하면도미.
|
||
},
|
||
//등록없음 선택에 따른 추가하기 버튼 잠금
|
||
toggleAddButtonState(isEnabled) {
|
||
const btn = document.getElementById("addItemBtn");
|
||
const icon = btn.querySelector("i");
|
||
btn.disabled = !isEnabled;
|
||
icon.classList.toggle("ico-add", isEnabled);
|
||
icon.classList.toggle("ico-add-disabled", !isEnabled);
|
||
},
|
||
//등록없음 버튼
|
||
handleNoDataToggle() {
|
||
if (!ENV.data.editable && ENV.data.currentStatus == "NOTHING") {
|
||
ENV.elementRefs.noDataCheckbox.checked = true;
|
||
return;
|
||
}
|
||
|
||
this.updateLayout();
|
||
|
||
},
|
||
// 등록폼 추가
|
||
openAddForm(callback) {
|
||
|
||
ajaxUtil._ajaxAsyncMethod(
|
||
"/api/front/info/monthly/create/from",
|
||
{},
|
||
function(rstHtml, status) {
|
||
$('.addPopup').find('.modal-content-inner').html(rstHtml);
|
||
|
||
const selectConfigs = [
|
||
|
||
{ id: 'mainYieldUnitCodeSelect', targetId: 'mainYieldUnitCode', key: 'mainYieldUnitCodeSelect' },
|
||
{ id: 'mainSaleUnitCodeSelect', targetId: 'mainSaleUnitCode', key: 'mainSaleUnitCodeSelect' },
|
||
{ id: 'subYieldUnitCodeSelect', targetId: 'subYieldUnitCode', key: 'subYieldUnitCodeSelect' },
|
||
{ id: 'subSaleUnitCodeSelect', targetId: 'subSaleUnitCode', key: 'subSaleUnitCodeSelect' }
|
||
];
|
||
|
||
selectConfigs.forEach(({ id, targetId, key }) => {
|
||
const $select = document.querySelector(`#${id}`);
|
||
const selectBox = new etUI.components.SelectBox();
|
||
selectBox.core.init($select, {
|
||
selectItemCallback({ selectValue, dataValue }) {
|
||
document.querySelector(`#${targetId}`).value = dataValue;
|
||
|
||
const withoutCode = targetId.replace(/Code$/, '');
|
||
console.log(withoutCode);
|
||
if(dataValue == "code.record.unit.self") {
|
||
console.log(dataValue + "close")
|
||
document.querySelector('#'+withoutCode).value="";
|
||
document.querySelector('#'+withoutCode+'Div').style.display ='block';
|
||
} else {
|
||
console.log(dataValue + "close")
|
||
document.querySelector('#'+withoutCode).value="";
|
||
document.querySelector('#'+withoutCode+'Div').style.display ='none';
|
||
}
|
||
}
|
||
});
|
||
ENV.elementRefs.select[key] = selectBox;
|
||
});
|
||
|
||
|
||
ENV.module.modalPopup.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'
|
||
);
|
||
},
|
||
// selectBox선택값으로 변경
|
||
setSelectBoxValue(selectBoxId, value) {
|
||
const selectBox = document.getElementById(selectBoxId);
|
||
const hiddenInput = selectBox.querySelector('input[type="hidden"]');
|
||
const label = selectBox.querySelector('.select-txt');
|
||
const option = selectBox.querySelector(`.option[data-value="${value}"]`);
|
||
|
||
if (option && hiddenInput && label) {
|
||
selectBox.querySelectorAll('.option').forEach(opt => opt.classList.remove('current'));
|
||
option.classList.add('current');
|
||
hiddenInput.value = value;
|
||
label.textContent = option.textContent;
|
||
}
|
||
},
|
||
//등록 아이템 저장
|
||
saveFormData() {
|
||
const form = document.getElementById('forestForm');
|
||
const selects = ['mainYieldUnitCode', 'mainSaleUnitCode', 'subYieldUnitCode', 'subSaleUnitCode'];
|
||
selects.forEach(id => {
|
||
const sel = document.getElementById(id + 'Select');
|
||
if (sel && sel.value) form[id].value = sel.value;
|
||
});
|
||
|
||
const errors = [];
|
||
if (!form.cropName.value) errors.push({field: 'cropName', message: '재배 작물명을 입력해주세요.'});
|
||
|
||
|
||
if(form.mainYield.value){
|
||
if(!form.mainYieldUnitCode.value){
|
||
errors.push({
|
||
field: 'mainYieldUnitCode',
|
||
message: '단위를 선택해주세요.'
|
||
});
|
||
} else if (form.mainYieldUnitCode.value && form.mainYieldUnitCode.value =="code.record.unit.self" && !form.mainYieldUnit.value){
|
||
|
||
errors.push({
|
||
field: 'mainYieldUnit',
|
||
message: '단위를 입력해주세요.'
|
||
});
|
||
}
|
||
}
|
||
|
||
if(form.mainSaleAmount.value){
|
||
if(!form.mainSaleUnitCode.value){
|
||
errors.push({
|
||
field: 'mainSaleUnitCode',
|
||
message: '단위를 선택해주세요.'
|
||
});
|
||
} else if (form.mainSaleUnitCode.value && form.mainSaleUnitCode.value =="code.record.unit.self" && !form.mainSaleUnit.value){
|
||
|
||
errors.push({
|
||
field: 'mainSaleUnit',
|
||
message: '단위를 입력해주세요.'
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
if(form.subYield.value){
|
||
if(!form.subYieldUnitCode.value){
|
||
errors.push({
|
||
field: 'subYieldUnitCode',
|
||
message: '단위를 선택해주세요.'
|
||
});
|
||
} else if (form.subYieldUnitCode.value && form.subYieldUnitCode.value =="code.record.unit.self" && !form.subYieldUnit.value){
|
||
|
||
errors.push({
|
||
field: 'subYieldUnit',
|
||
message: '단위를 입력해주세요.'
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
if(form.subSaleAmount.value){
|
||
if(!form.subSaleUnitCode.value){
|
||
errors.push({
|
||
field: 'subSaleUnitCode',
|
||
message: '단위를 선택해주세요.'
|
||
});
|
||
} else if (form.subSaleUnitCode.value && form.subSaleUnitCode.value =="code.record.unit.self" && !form.subSaleUnit.value){
|
||
|
||
errors.push({
|
||
field: 'subSaleUnit',
|
||
message: '단위를 입력해주세요.'
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
kri.form.error(errors);
|
||
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);
|
||
|
||
ENV.module.modalPopup.close();
|
||
setTimeout(() => productRenderer.addItem(product, true), 300);
|
||
},
|
||
// 선택 아이템 수정 (폼 노출)
|
||
editItemById(id) {
|
||
|
||
|
||
const product = ENV.data.productList.find(p => p.id == id);
|
||
if (!product) return;
|
||
|
||
this.openAddForm(() => {
|
||
const form = document.getElementById('forestForm');
|
||
if (!form) return;
|
||
|
||
Object.entries(product).forEach(([key, val]) => {
|
||
const field = form.elements.namedItem(key);
|
||
if (field) {
|
||
field.value = val;
|
||
if(key == 'mainYieldUnitCode' && val == "code.record.unit.self"){
|
||
document.getElementById("mainYieldUnitDiv").style.display = "block";
|
||
}
|
||
if(key == 'mainSaleUnitCode' && val == "code.record.unit.self"){
|
||
document.getElementById("mainSaleUnitDiv").style.display = "block";
|
||
}
|
||
if(key == 'subYieldUnitCode' && val == "code.record.unit.self"){
|
||
document.getElementById("subYieldUnitDiv").style.display = "block";
|
||
}
|
||
if(key == 'subSaleUnitCode' && val == "code.record.unit.self"){
|
||
document.getElementById("subSaleUnitDiv").style.display = "block";
|
||
}
|
||
}
|
||
});
|
||
|
||
ENV.elementRefs.select.mainYieldUnitCodeSelect.setValue(product.mainYieldUnitCode);
|
||
ENV.elementRefs.select.mainSaleUnitCodeSelect.setValue(product.mainSaleUnitCode);
|
||
ENV.elementRefs.select.subYieldUnitCodeSelect.setValue(product.subYieldUnitCode);
|
||
ENV.elementRefs.select.subSaleUnitCodeSelect.setValue(product.subSaleUnitCode);
|
||
document.getElementById("mainYieldUnit").value = product.mainYieldUnit;
|
||
document.getElementById("mainSaleUnit").value = product.mainSaleUnit;
|
||
document.getElementById("subYieldUnit").value = product.subYieldUnit;
|
||
document.getElementById("subSaleUnit").value = product.subSaleUnit;
|
||
});
|
||
},
|
||
// 선택 아이템 삭제
|
||
deleteItemById(id) {
|
||
etUI.dialog.alert({
|
||
title: '삭제 안내',
|
||
message: '등록하신 내용을 삭제하시겠어요?<br>삭제된 내용은 복구할 수 없습니다.',
|
||
type: 'confirm',
|
||
dialogType: 'confirm',
|
||
callback: function () {
|
||
ENV.data.productList = ENV.data.productList.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.productList = [];
|
||
document.getElementById('listBody').innerHTML = '';
|
||
formControl.updateLayout();
|
||
|
||
// TODO(ks): 선택 삭제 시 전체 count 미반영 중. 일단 전체 초기화에서만 count 갱신.
|
||
document.getElementById('totalItems').textContent = ENV.data.productList.length;
|
||
},
|
||
});
|
||
},
|
||
// 아이템 겟수 처리 아이템에 따른 레이아웃 정리
|
||
|
||
// 지목 코드
|
||
getPurposeLabel(code) {
|
||
const found = ENV.data.purposeList.find(i => i.id === code);
|
||
return found ? found.codeText : '-';
|
||
},
|
||
// 단위 코드
|
||
getUnitLabel(code,inputValue) {
|
||
if(code == "code.record.unit.self"){
|
||
return inputValue;
|
||
} else {
|
||
const found = ENV.data.unitList.find(i => i.id === code);
|
||
return found ? found.codeText : '-';
|
||
}
|
||
},
|
||
|
||
|
||
goSave() {
|
||
|
||
|
||
ajaxUtil._ajaxAsync(
|
||
ENV.httpUrl.save,
|
||
{
|
||
status: ENV.elementRefs.noDataCheckbox.checked,
|
||
id: ENV.data.id,
|
||
productList: ENV.data.productList
|
||
},
|
||
function (rstData, status) {
|
||
if (rstData.code === 'SUCCESS') {
|
||
ajaxUtil._alert('등록이 완료되었습니다.', null, function () {
|
||
/**
|
||
* TODO
|
||
* 내정보에서만 들어온다는 가정하에서 back을 하게함 SB에는 내정보로 이동하게 되어 있음.
|
||
*/
|
||
history.back()
|
||
});
|
||
} else if (rstData.code === 'ERROR') {
|
||
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', null);
|
||
}
|
||
},
|
||
);
|
||
}
|
||
};
|
||
|
||
|
||
const productRenderer = {
|
||
//화면에 아이템 추가
|
||
addItem(product, isEdit) {
|
||
const listBody = document.getElementById('listBody');
|
||
const form = document.getElementById('forestForm');
|
||
// form.reset();
|
||
listBody.style.display = '';
|
||
|
||
const format = val => Number(val).toLocaleString() || '-';
|
||
const getUnit = formControl.getUnitLabel;
|
||
const getPurpose = formControl.getPurposeLabel;
|
||
|
||
// const mainYieldUnit = !product.mainYieldUnitCode ? ''
|
||
// const mainSaleUnit
|
||
// const subYieldUnit
|
||
// const subSaleUnit
|
||
|
||
|
||
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>${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,product.mainYieldUnit)} / ${format(product.mainSaleAmount)}${getUnit(product.mainSaleUnitCode,product.mainSaleUnit)}</span></li>`;
|
||
} else if (product.mainYield) {
|
||
tag5 = `<li><p>주생산물 수확량</p><span>${format(product.mainYield)}${getUnit(product.mainYieldUnitCode,product.mainYieldUnit)}</span></li>`;
|
||
} else if (product.mainSaleAmount) {
|
||
tag5 = `<li><p>주생산물 판매량</p><span>${format(product.mainSaleAmount)}${getUnit(product.mainSaleUnitCode,product.mainSaleUnit)}</span></li>`;
|
||
}
|
||
|
||
let tag6 = '';
|
||
if (product.subYield && product.subSaleAmount) {
|
||
tag6 = `<li><p>부생산물 수확량 / 판매량</p><span>${format(product.subYield)}${getUnit(product.subYieldUnitCode,product.subYieldUnit)} / ${format(product.subSaleAmount)}${getUnit(product.subSaleUnitCode,product.subSaleUnit)}</span></li>`;
|
||
} else if (product.subYield) {
|
||
tag6 = `<li><p>부생산물 수확량</p><span>${format(product.subYield)}${getUnit(product.subYieldUnitCode,product.subYieldUnit)}</span></li>`;
|
||
} else if (product.subSaleAmount) {
|
||
tag6 = `<li><p>부생산물 판매량</p><span>${format(product.subSaleAmount)}${getUnit(product.subSaleUnitCode,product.subSaleUnit)}</span></li>`;
|
||
}
|
||
|
||
let buttonGroupHtml = '';
|
||
if (isEdit) {
|
||
buttonGroupHtml = `
|
||
<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 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 existing = listBody.querySelector(`[data-id="${product.id}"]`);
|
||
existing ? listBody.replaceChild(div, existing) : listBody.appendChild(div);
|
||
formControl.updateLayout();
|
||
}
|
||
};
|
||
|
||
|
||
</script>
|
||
|
||
</section>
|
||
|
||
</html> |