145 lines
7.4 KiB
JavaScript
145 lines
7.4 KiB
JavaScript
import { w2grid, w2ui, w2popup, w2alert } from 'https://cdn.jsdelivr.net/gh/vitmalina/w2ui@master/dist/w2ui.es6.min.js'
|
|
// 파일이 실제 존재하는지 확인 필수! 존재하지 않으면 아래 코드가 모두 멈춥니다.
|
|
import { bindProductPopupEvents } from '/kngil/js/adm_common.js'
|
|
|
|
|
|
|
|
export function openPurchaseHistoryPopup(memberId = '',isSuperAdmin='') {
|
|
// 기존 그리드 안전하게 제거
|
|
if (w2ui.purchaseHistoryGrid) {
|
|
w2ui.purchaseHistoryGrid.destroy();
|
|
}
|
|
|
|
w2popup.open({
|
|
title: '서비스 구매 이력',
|
|
width: 1100,
|
|
height: 600,
|
|
modal: true,
|
|
body:
|
|
/*
|
|
`
|
|
<div style="padding:8px">
|
|
<div id="purchaseHistoryGrid" style="height:520px;"></div>
|
|
</div>
|
|
*/
|
|
`
|
|
<div id="popupMainContainer" style="display: flex; flex-direction: column; height: 100%; padding: 10px; gap: 10px; box-sizing: border-box;">
|
|
|
|
<div id="searchFormArea" style="display: flex; align-items: center; gap: 10px; padding: 15px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 4px;">
|
|
<span style="font-weight: bold; color: #333;">회원 ID</span>
|
|
<input type="text" id="searchMemberId" value="${memberId}"
|
|
${!isSuperAdmin ? 'disabled' : ''}
|
|
style="width: 150px; padding: 6px; border: 1px solid #ccc; border-radius: 4px;"
|
|
placeholder="아이디 입력">
|
|
|
|
<button id="btnSearchHistory"
|
|
style="padding: 6px 20px; background: #1565c0; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: bold;">
|
|
검색
|
|
</button>
|
|
</div>
|
|
|
|
<div id="purchaseHistoryGrid" style="flex: 1; min-height: 450px; border: 1px solid #ddd;"></div>
|
|
</div>
|
|
|
|
`,
|
|
onOpen(event) {
|
|
event.onComplete = () => {
|
|
const searchBtn = document.getElementById('btnSearchHistory');
|
|
const searchInput = document.getElementById('searchMemberId');
|
|
|
|
// 조회 버튼 클릭 시 동작
|
|
if (searchBtn) {
|
|
searchBtn.onclick = () => {
|
|
loadPurchaseHistoryData(searchInput.value);
|
|
};
|
|
}
|
|
|
|
// 엔터키 지원
|
|
if (searchInput) {
|
|
searchInput.onkeydown = (e) => {
|
|
if (e.key === 'Enter') searchBtn.click();
|
|
};
|
|
}
|
|
|
|
createPurchaseHistoryGrid(memberId);
|
|
loadPurchaseHistoryData(memberId);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function createPurchaseHistoryGrid(memberId) {
|
|
new w2grid({
|
|
name: 'purchaseHistoryGrid',
|
|
box: '#purchaseHistoryGrid',
|
|
show: {
|
|
//toolbar: true,
|
|
footer: true,
|
|
lineNumbers: true // 행 번호를 표시하면 디버깅이 편합니다.
|
|
},
|
|
columns: [
|
|
// field 이름이 PHP에서 내려주는 JSON 키값과 정확히 일치해야 함!
|
|
{ field: 'member_id', text: '회원ID', size: '80px',style: 'text-align: center', attr: 'align=center',sortable: true }, // name 아님!
|
|
{ field: 'sq_no', text: '순번', size: '50px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'user_nm', text: '구매자', size: '80px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'co_nm', text: '회사명', size: '100px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'bs_no', text: '사업자번호', size: '100px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'buy_dt', text: '구입일자', size: '80px',style: 'text-align: center', attr: 'align=center',sortable: true }, // name 아님!
|
|
{ field: 'itm_nm', text: '상품명', size: '80px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'area', text: '상품면적', size: '80px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'itm_qty', text: '수량', size: '80px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'itm_area', text: '면적', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'add_area', text: '추가면적', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'sum_area', text: '합계면적', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'itm_amt', text: '단가', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'dis_rt', text: '할인율', size: '80px', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'buy_amt', text: '공급금액', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'vat_amt', text: '부가세', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'sum_amt', text: '합계', size: '100px',render: 'number:0' , attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'end_dt', text: '종료일', size: '80px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'ok_yn', text: '승인여부', size: '80px',style: 'text-align: center', attr: 'align=center' ,sortable: true}, // name 아님!
|
|
{ field: 'rmks', text: '비고', size: '150px',style: 'text-align: center', attr: 'align=center' ,sortable: true} // name 아님!
|
|
|
|
]
|
|
});
|
|
}
|
|
|
|
async function loadPurchaseHistoryData(memberId) {
|
|
try {
|
|
const grid = w2ui.purchaseHistoryGrid;
|
|
if (!grid) return;
|
|
|
|
grid.lock('조회 중...', true);
|
|
|
|
const searchParams = new URLSearchParams();
|
|
searchParams.append('member_id', memberId);
|
|
searchParams.append('member_nm', '');
|
|
searchParams.append('fbuy_dt', '');
|
|
searchParams.append('tbuy_dt', '');
|
|
|
|
const response = await fetch('/admin/api/purchase-history', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: searchParams
|
|
});
|
|
|
|
if (!response.ok) throw new Error(`서버 응답 오류: ${response.status}`);
|
|
|
|
const data = await response.json();
|
|
|
|
if (!Array.isArray(data)) {
|
|
throw new Error('응답 데이터 형식 오류');
|
|
}
|
|
|
|
grid.clear();
|
|
grid.add(data);
|
|
grid.unlock();
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
if (w2ui.purchaseHistoryGrid) w2ui.purchaseHistoryGrid.unlock();
|
|
w2alert('구매이력 조회 실패: ' + e.message);
|
|
}
|
|
}
|
|
////////////////////////////////////////////////////////////////////////
|