/* ===== 부적합 현황 (Nonconformity List) ===== */ const CATEGORY_TYPE = 'nonconformity'; const STATUS_LABELS = { reported: '신고', received: '접수', in_progress: '처리중', completed: '완료', closed: '종료' }; const STATUS_BADGE = { reported: 'badge-blue', received: 'badge-orange', in_progress: 'badge-purple', completed: 'badge-green', closed: 'badge-gray' }; function getReportUrl() { const h = location.hostname; if (h.includes('technicalkorea.net')) return 'https://tkreport.technicalkorea.net/pages/safety/issue-report.html?type=nonconformity'; return location.protocol + '//' + h + ':30180/pages/safety/issue-report.html?type=nonconformity'; } function getIssueDetailUrl(reportId) { const h = location.hostname; if (h.includes('technicalkorea.net')) return `https://tkreport.technicalkorea.net/pages/safety/issue-detail.html?id=${reportId}&from=nonconformity`; return `${location.protocol}//${h}:30180/pages/safety/issue-detail.html?id=${reportId}&from=nonconformity`; } async function loadStats() { try { const data = await api(`/work-issues/stats/summary?category_type=${CATEGORY_TYPE}`); if (data.success && data.data) { document.getElementById('statReported').textContent = data.data.reported || 0; document.getElementById('statReceived').textContent = data.data.received || 0; document.getElementById('statProgress').textContent = data.data.in_progress || 0; document.getElementById('statCompleted').textContent = data.data.completed || 0; } } catch { document.getElementById('statsGrid').style.display = 'none'; } } async function loadIssues() { const params = new URLSearchParams(); params.append('category_type', CATEGORY_TYPE); const status = document.getElementById('filterStatus').value; const startDate = document.getElementById('filterStartDate').value; const endDate = document.getElementById('filterEndDate').value; if (status) params.append('status', status); if (startDate) params.append('start_date', startDate); if (endDate) params.append('end_date', endDate); try { const data = await api(`/work-issues?${params.toString()}`); if (data.success) renderIssues(data.data || []); } catch { document.getElementById('issueList').innerHTML = '
목록을 불러올 수 없습니다. 잠시 후 다시 시도해주세요.
'; } } function renderIssues(issues) { const el = document.getElementById('issueList'); if (!issues.length) { el.innerHTML = '

등록된 부적합 신고가 없습니다

새로운 부적합을 신고하려면 \'부적합 신고\' 버튼을 클릭하세요.

'; return; } el.innerHTML = issues.map(issue => { const reportDate = formatDateTime(issue.report_date); let loc = escapeHtml(issue.custom_location || ''); if (issue.factory_name) { loc = escapeHtml(issue.factory_name); if (issue.workplace_name) loc += ` - ${escapeHtml(issue.workplace_name)}`; } const title = escapeHtml(issue.issue_item_name || issue.issue_category_name || '부적합 신고'); const categoryName = escapeHtml(issue.issue_category_name || '부적합'); const reportId = parseInt(issue.report_id) || 0; const validStatuses = ['reported', 'received', 'in_progress', 'completed', 'closed']; const safeStatus = validStatuses.includes(issue.status) ? issue.status : 'reported'; const reporter = escapeHtml(issue.reporter_full_name || issue.reporter_name || '-'); const assigned = issue.assigned_full_name ? escapeHtml(issue.assigned_full_name) : ''; const photos = [issue.photo_path1, issue.photo_path2, issue.photo_path3, issue.photo_path4, issue.photo_path5].filter(Boolean); return `
#${reportId} ${STATUS_LABELS[issue.status] || escapeHtml(issue.status || '-')}
${categoryName} ${title}
${reporter} ${reportDate} ${loc ? `${loc}` : ''} ${assigned ? `담당: ${assigned}` : ''}
${photos.length > 0 ? `
${photos.slice(0, 3).map(p => `사진`).join('')}${photos.length > 3 ? `+${photos.length - 3}` : ''}
` : ''}
`; }).join(''); } /* ===== Init ===== */ (async function() { if (!await initAuth()) return; // 신고 버튼 URL 설정 document.getElementById('btnNewReport').href = getReportUrl(); // 필터 이벤트 document.getElementById('filterStatus').addEventListener('change', loadIssues); document.getElementById('filterStartDate').addEventListener('change', loadIssues); document.getElementById('filterEndDate').addEventListener('change', loadIssues); await Promise.all([loadStats(), loadIssues()]); })();