feat: OTC 라벨 프리셋 삭제 기능 + 디버깅 로그 추가

This commit is contained in:
thug0bin 2026-03-02 17:08:48 +09:00
parent b71d511c7a
commit c154537c87

View File

@ -191,6 +191,11 @@
color: white;
}
.btn-print:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.3); }
.btn-delete {
background: #fee2e2;
color: #dc2626;
}
.btn-delete:hover { background: #fecaca; }
/* 미리보기 */
.preview-container {
@ -334,6 +339,7 @@
</div>
<div class="btn-group">
<button type="button" class="btn btn-print" onclick="printLabel()">🖨️ 인쇄</button>
<button type="button" class="btn btn-delete" onclick="deleteLabel()">🗑️ 삭제</button>
</div>
</form>
</div>
@ -503,21 +509,27 @@
usage_tip: document.getElementById('usageTip').value
};
console.log('저장 payload:', payload);
try {
const res = await fetch('/api/admin/otc-labels', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
console.log('저장 응답 status:', res.status);
const data = await res.json();
console.log('저장 응답 data:', data);
if (data.success) {
showToast('저장 완료!', 'success');
loadLabelList();
} else {
showToast(data.error, 'error');
showToast(data.error || '알 수 없는 오류', 'error');
}
} catch (err) {
console.error('저장 오류:', err);
showToast('저장 오류: ' + err.message, 'error');
}
}
@ -559,6 +571,43 @@
}
}
// 삭제
async function deleteLabel() {
if (!currentBarcode) {
showToast('삭제할 프리셋이 없습니다', 'error');
return;
}
if (!confirm(`"${currentDrugName}" 프리셋을 삭제하시겠습니까?`)) {
return;
}
try {
const res = await fetch(`/api/admin/otc-labels/${currentBarcode}`, {
method: 'DELETE'
});
const data = await res.json();
if (data.success) {
showToast('삭제 완료!', 'success');
// 폼 초기화
currentBarcode = '';
currentDrugName = '';
document.getElementById('barcode').value = '';
document.getElementById('displayName').value = '';
document.getElementById('effect').value = '';
document.getElementById('dosageInstruction').value = '';
document.getElementById('usageTip').value = '';
document.getElementById('previewContainer').innerHTML = '<div class="preview-placeholder">미리보기를 클릭하면 라벨이 표시됩니다</div>';
loadLabelList();
} else {
showToast(data.error || '삭제 실패', 'error');
}
} catch (err) {
showToast('삭제 오류: ' + err.message, 'error');
}
}
// 목록 로드
async function loadLabelList() {
try {