import { state } from '../../core/state'; import { openHwModal } from '../../components/Modal/HWModal'; import { formatInline, sortAssets } from '../../core/utils'; import { createIcons, RefreshCcw } from 'lucide'; export function renderMobileList(container: HTMLElement) { const fullList = sortAssets(state.masterData.mobile); const filterBar = document.createElement('div'); filterBar.className = 'search-bar'; const corps = Array.from(new Set(fullList.map(a => a.법인))).filter(Boolean).sort(); filterBar.innerHTML = `
`; container.appendChild(filterBar); const tableWrapper = document.createElement('div'); tableWrapper.className = 'table-container'; const table = document.createElement('table'); table.innerHTML = ` No. 상태 구매법인 자산코드 명칭 보관위치 관리자 구매일 금액 `; tableWrapper.appendChild(table); container.appendChild(tableWrapper); const tbody = table.querySelector('tbody')!; const updateTable = () => { const keywordInput = document.getElementById('filter-keyword') as HTMLInputElement; const corpSelect = document.getElementById('filter-corp') as HTMLSelectElement; const keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : ''; const corp = corpSelect ? corpSelect.value : ''; const filtered = fullList.filter(asset => { const matchKeyword = !keyword || String(asset.자산코드||'').toLowerCase().includes(keyword) || String(asset.모델명||'').toLowerCase().includes(keyword) || String(asset.현사용조직||'').toLowerCase().includes(keyword); const matchCorp = !corp || asset.법인 === corp; return matchKeyword && matchCorp; }); tbody.innerHTML = ''; if (filtered.length === 0) { tbody.innerHTML = `검색 결과가 없습니다.`; return; } filtered.forEach((asset, idx) => { const tr = document.createElement('tr'); tr.style.cursor = 'pointer'; const statusColors: Record = { '대여중': '#3b82f6', '보관중': '#1E5149', '수리중': '#ef4444', '기타': '#6b7280' }; const statusColor = statusColors[asset.현재상태 || '보관중'] || '#6b7280'; const statusBadge = `${asset.현재상태 || '보관중'}`; tr.innerHTML = ` ${idx + 1} ${statusBadge} ${asset.법인} ${asset.자산코드 || '-'} ${formatInline(asset.명칭 || asset.모델명)} ${asset.보관위치 || '-'} ${formatInline(asset.관리자 || asset.담당자_정)} ${asset.구매일 || ''} ${asset.금액 || '0'} `; tr.addEventListener('click', (e) => { if (!(e.target as HTMLElement).closest('button')) openHwModal(asset, 'view'); }); tbody.appendChild(tr); }); }; document.getElementById('filter-keyword')?.addEventListener('input', updateTable); document.getElementById('filter-corp')?.addEventListener('change', updateTable); document.getElementById('btn-reset-filters')?.addEventListener('click', () => { (document.getElementById('filter-keyword') as HTMLInputElement).value = ''; (document.getElementById('filter-corp') as HTMLSelectElement).value = ''; updateTable(); }); updateTable(); }