import { state } from '../../core/state'; import { openHwModal } from '../../components/Modal/HWModal'; import { formatInline, sortAssets, dynamicSort, getActionButtonsHTML } from '../../core/utils'; import { ASSET_SCHEMA, UI_TEXT } from '../../core/schema'; import { setupTableSorting, SortState } from '../../core/tableHandler'; import { createIcons, RefreshCcw, Download, Upload, FileSpreadsheet, Plus } from 'lucide'; /** * PC부품 자산 목록 뷰 */ export function renderPcPartList(container: HTMLElement) { // PC부품 데이터는 survey 또는 별도 테이블에 있을 수 있음. 여기선 equipment에서 필터링하거나 빈 배열 지원 const fullList = sortAssets(state.masterData.equipment?.filter((a: any) => a.category === 'PC부품') || []); let sortState: SortState = { key: '', direction: 'asc' }; const filterBar = document.createElement('div'); filterBar.className = 'search-bar'; filterBar.innerHTML = `
${getActionButtonsHTML()} `; container.appendChild(filterBar); const tableWrapper = document.createElement('div'); tableWrapper.className = 'table-container'; const table = document.createElement('table'); table.innerHTML = ` No. ${ASSET_SCHEMA.HW_STATUS.ui} ${ASSET_SCHEMA.ASSET_TYPE.ui} ${ASSET_SCHEMA.ASSET_MFR.ui} ${ASSET_SCHEMA.MODEL_NAME.ui} ${ASSET_SCHEMA.VOLUME.ui} ${ASSET_SCHEMA.MONITOR_INCH.ui} ${ASSET_SCHEMA.ASSET_COUNT.ui} ${ASSET_SCHEMA.LOCATION.ui}(건물) ${ASSET_SCHEMA.LOC_DETAIL.ui} ${ASSET_SCHEMA.MEMO.ui} `; tableWrapper.appendChild(table); container.appendChild(tableWrapper); const tbody = table.querySelector('tbody')!; const updateTable = () => { const keywordInput = document.getElementById('filter-keyword') as HTMLInputElement; const keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : ''; let filtered = fullList.filter(asset => { const matchKeyword = !keyword || String(asset[ASSET_SCHEMA.MODEL_NAME.key]||'').toLowerCase().includes(keyword) || String(asset[ASSET_SCHEMA.ASSET_TYPE.key]||'').toLowerCase().includes(keyword); return matchKeyword; }); if (sortState.key) { filtered = dynamicSort(filtered, sortState.key, sortState.direction); } tbody.innerHTML = ''; if (filtered.length === 0) { tbody.innerHTML = `${UI_TEXT.MESSAGES.NO_DATA}`; return; } filtered.forEach((asset, idx) => { const tr = document.createElement('tr'); tr.style.cursor = 'pointer'; tr.innerHTML = ` ${idx + 1} ${asset[ASSET_SCHEMA.HW_STATUS.key] || '보관중'} ${asset[ASSET_SCHEMA.ASSET_TYPE.key] || ''} ${asset[ASSET_SCHEMA.ASSET_MFR.key] || ''} ${formatInline(asset[ASSET_SCHEMA.MODEL_NAME.key] || '-')} ${asset[ASSET_SCHEMA.VOLUME.key] || '-'} ${asset[ASSET_SCHEMA.MONITOR_INCH.key] || '-'} ${asset[ASSET_SCHEMA.ASSET_COUNT.key] || '1'} ${asset[ASSET_SCHEMA.LOCATION.key] || '-'} ${asset[ASSET_SCHEMA.LOC_DETAIL.key] || '-'} ${formatInline(asset[ASSET_SCHEMA.MEMO.key]||'-')} `; tr.addEventListener('click', () => openHwModal(asset, 'view')); tbody.appendChild(tr); }); setupTableSorting(table, sortState, (key, dir) => { sortState = { key, direction: dir }; updateTable(); }); createIcons({ icons: { RefreshCcw, Download, Upload, FileSpreadsheet, Plus } }); }; document.getElementById('filter-keyword')?.addEventListener('input', updateTable); document.getElementById('btn-reset-filters')?.addEventListener('click', () => { (document.getElementById('filter-keyword') as HTMLInputElement).value = ''; updateTable(); }); updateTable(); }