This commit is contained in:
2026-02-05 10:42:13 +09:00
67 changed files with 8090 additions and 1860 deletions

View File

@@ -1,8 +1,8 @@
import { w2grid, w2ui, w2popup, w2alert } from 'https://cdn.jsdelivr.net/gh/vitmalina/w2ui@master/dist/w2ui.es6.min.js'
const USE_YN_ITEMS = [
{ id: 'Y', text: '사용' },
{ id: 'N', text: '미사용' }
{ id: 'Y', text: '사용' },
{ id: 'N', text: '미사용' }
]
/* -------------------------------------------------
공통 유틸
@@ -14,7 +14,7 @@ function destroyGrid(name) {
}
function loadBaseCode(mainCd) {
return fetch(`/kngil/bbs/adm_comp.php?action=base_code&main_cd=${mainCd}`)
return fetch(`/admin/api/company?action=base_code&main_cd=${mainCd}`)
.then(res => res.json())
.then(json => {
if (json.status !== 'success') {
@@ -57,12 +57,12 @@ export function openProductPopup() {
onOpen(event) {
event.onComplete = () => {
// 1. 그리드를 생성합니다.
createProductGrid('#productGrid');
createProductGrid('#productGrid');
// 1. 추가 버튼
// 1. 추가 버튼
document.getElementById('prodAdd').onclick = () => {
const g = w2ui.productGrid
const g = w2ui.productGrid
if (!g) return
// 신규 row용 recid (음수로 충돌 방지)
const newRecid = -Date.now()
@@ -79,7 +79,7 @@ export function openProductPopup() {
};
// 삭제 버튼 이벤트 연결
const removeBtn = document.getElementById('prodRemove');
if (removeBtn) {
@@ -106,43 +106,43 @@ export function openProductPopup() {
// 3. 브라우저 기본 확인창 사용 (가장 확실함)
if (confirm(`선택한 ${ids.length}개의 상품을 삭제하시겠습니까?`)) {
fetch('/kngil/bbs/adm_product_popup_delete.php', {
fetch('/admin/api/product/delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'delete', ids: ids })
})
.then(res => {
// 서버 응답이 오면 일단 텍스트로 받아서 확인
return res.text();
})
.then(text => {
try {
const json = JSON.parse(text);
if (json.status === 'success') {
alert('삭제 완료');
loadProductData(); // 목록 새로고침
} else {
alert(json.message || '삭제 실패');
.then(res => {
// 서버 응답이 오면 일단 텍스트로 받아서 확인
return res.text();
})
.then(text => {
try {
const json = JSON.parse(text);
if (json.status === 'success') {
alert('삭제 완료');
loadProductData(); // 목록 새로고침
} else {
alert(json.message || '삭제 실패');
}
} catch (e) {
console.error('응답 파싱 에러:', text);
alert('서버 응답 처리 중 오류가 발생했습니다.');
}
} catch (e) {
console.error('응답 파싱 에러:', text);
alert('서버 응답 처리 중 오류가 발생했습니다.');
}
})
.catch(err => {
console.error('통신 에러:', err);
alert('서버와 통신할 수 없습니다.');
});
})
.catch(err => {
console.error('통신 에러:', err);
alert('서버와 통신할 수 없습니다.');
});
}
};
}
// 3. 저장 버튼
document.getElementById('prodSave').onclick = () => {
// 현재 사용 중인 grid
const g = w2ui.productGrid
const g = w2ui.productGrid
if (!g) return
const changes = g.getChanges()
if (!changes.length) {
@@ -163,20 +163,20 @@ export function openProductPopup() {
} else {
// UPDATE → PK + 변경 컬럼
updates.push({
itm_cd : merged.itm_cd,
itm_nm : merged.itm_nm,
area : merged.area,
itm_cd: merged.itm_cd,
itm_nm: merged.itm_nm,
area: merged.area,
itm_amt: merged.itm_amt,
use_yn : merged.use_yn?.id || merged.use_yn,
rmks : merged.rmks
use_yn: merged.use_yn?.id || merged.use_yn,
rmks: merged.rmks
})
}
})
console.log('INSERTS', inserts)
console.log('UPDATES', updates)
fetch('/kngil/bbs/adm_product_popup_save.php', {
fetch('/admin/api/product/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -186,26 +186,26 @@ export function openProductPopup() {
})
})
.then(res => {
// 서버가 준 응답이 괜찮은지 확인
if (!res.ok) throw new Error('서버 응답 오류');
return res.json(); // 처음부터 깔끔하게 데이터로 읽기
})
.then(res => {
// 서버가 준 응답이 괜찮은지 확인
if (!res.ok) throw new Error('서버 응답 오류');
return res.json(); // 처음부터 깔끔하게 데이터로 읽기
})
.then(json => {
// 이제 json.status를 바로 쓸 수 있습니다.
if (json.status === 'success') {
w2alert('저장 완료');
w2ui.productGrid.save(); // 빨간 삼각형 없애기
loadProductData(); // 목록 새로고침
} else {
w2alert(json.message || '저장 실패');
}
})
.catch(err => {
console.error('에러 발생:', err);
w2alert('처리 중 오류가 발생했습니다.');
});
.then(json => {
// 이제 json.status를 바로 쓸 수 있습니다.
if (json.status === 'success') {
w2alert('저장 완료');
w2ui.productGrid.save(); // 빨간 삼각형 없애기
loadProductData(); // 목록 새로고침
} else {
w2alert(json.message || '저장 실패');
}
})
.catch(err => {
console.error('에러 발생:', err);
w2alert('처리 중 오류가 발생했습니다.');
});
};
}
@@ -220,7 +220,7 @@ export async function createProductGrid(boxId) {
const authItems = await loadBaseCode('BS210')
const grid = new w2grid({
name: 'productGrid',
box: boxId,
show: {
@@ -230,27 +230,27 @@ export async function createProductGrid(boxId) {
},
columns: [
{ field: 'itm_cd', text: '상품코드', size: '80px',style: 'text-align: center', attr: 'align=center', editable: { type: 'text' } ,sortable: true}, // name 아님!
{ field: 'itm_nm', text: '상품명', size: '120px', style: 'text-align: center', editable: { type: 'text' } ,sortable: true}, // name 아님!
{ field: 'area', text: '제공량', size: '100px', attr: 'align=center',render: 'number:0' , editable: { type: 'float' } ,sortable: true}, // volume 아님!
{ field: 'itm_amt', text: '단가', size: '120px', attr: 'align=center',render: 'number:0', editable: { type: 'int' } ,sortable: true}, //
{ field: 'itm_cd', text: '상품코드', size: '80px', style: 'text-align: center', attr: 'align=center', editable: { type: 'text' }, sortable: true }, // name 아님!
{ field: 'itm_nm', text: '상품명', size: '120px', style: 'text-align: center', editable: { type: 'text' }, sortable: true }, // name 아님!
{ field: 'area', text: '제공량', size: '100px', attr: 'align=center', render: 'number:0', editable: { type: 'float' }, sortable: true }, // volume 아님!
{ field: 'itm_amt', text: '단가', size: '120px', attr: 'align=center', render: 'number:0', editable: { type: 'int' }, sortable: true }, //
{
field: 'use_yn',
text: '사용여부',
size: '80px',
attr: 'align=center',
editable: {
type: 'list',
items: USE_YN_ITEMS,
showAll: true,
openOnFocus: true
field: 'use_yn',
text: '사용여부',
size: '80px',
attr: 'align=center',
editable: {
type: 'list',
items: USE_YN_ITEMS,
showAll: true,
openOnFocus: true
},
render(record, extra) {
return extra?.value?.text || ''
},
sortable: true
},
render(record, extra) {
return extra?.value?.text || ''
},
sortable: true
},
{ field: 'rmks', text: '비고', size: '200px', editable: { type: 'text' } ,sortable: true} // memo 아님!
{ field: 'rmks', text: '비고', size: '200px', editable: { type: 'text' }, sortable: true } // memo 아님!
],
records: [] // 처음엔 비워둠
});
@@ -266,12 +266,10 @@ export async function createProductGrid(boxId) {
async function loadProductData() {
try {
w2ui.productGrid.lock('조회 중...', true);
const response = await fetch('/kngil/bbs/adm_product_popup.php'); // PHP 파일 호출
let data = await response.json();
data = normalizeProductUseYn(data)
const response = await fetch('/kngil/bbs/adm_product_popup.php'); // PHP 파일 호출
const data = await response.json();
w2ui.productGrid.clear();
w2ui.productGrid.add(data);
w2ui.productGrid.unlock();
@@ -284,11 +282,11 @@ async function loadProductData() {
}
function normalizeProductUseYn(records) {
return records.map(r => {
const item = USE_YN_ITEMS.find(u => u.id === r.use_yn)
return {
...r,
use_yn: item || null
}
})
return records.map(r => {
const item = USE_YN_ITEMS.find(u => u.id === r.use_yn)
return {
...r,
use_yn: item || null
}
})
}