jasan/models.php
2026-02-09 01:19:02 +09:00

719 lines
No EOL
43 KiB
PHP

<?php require_once 'auth_check.php'; ?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DB 관리 | FKI ASSET</title>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Pretendard:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/style.css">
<style>
body {
font-family: 'Pretendard', sans-serif;
}
[x-cloak] {
display: none !important;
}
.modal-bg {
background-color: rgba(15, 23, 42, 0.7);
backdrop-filter: blur(4px);
}
</style>
</head>
<body class="bg-[#f8fafc] text-slate-800" x-data="dbManagement()">
<?php include 'nav.php'; ?>
<main class="max-w-[1600px] mx-auto p-8 pt-10">
<header class="mb-10 flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<h2 class="text-3xl font-extrabold text-slate-900 tracking-tight">DB 마스터 관리</h2>
<p class="text-slate-500 mt-1">시스템 운영을 위한 기초 자산 모델 및 조직 정보를 관리합니다.</p>
</div>
<div class="flex items-center gap-3">
<!-- Search Bar for Models -->
<div x-show="currentTab === 'models'" class="relative group">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<svg class="h-4 w-4 text-slate-400 group-focus-within:text-blue-500 transition-colors"
fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</div>
<input type="text" x-model="searchQuery"
class="block w-64 pl-10 pr-3 py-2.5 border border-slate-200 rounded-xl leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all text-sm shadow-sm"
placeholder="모델명, 제조사, CPU 검색...">
</div>
<!-- Search Bar for Departments -->
<div x-show="currentTab === 'depts'" class="relative group">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<svg class="h-4 w-4 text-slate-400 group-focus-within:text-blue-500 transition-colors"
fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</div>
<input type="text" x-model="deptSearchQuery"
class="block w-64 pl-10 pr-3 py-2.5 border border-slate-200 rounded-xl leading-5 bg-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all text-sm shadow-sm"
placeholder="부서명 검색...">
</div>
<div class="flex gap-2">
<button x-show="currentTab === 'models'" @click="openAddModal()"
class="bg-blue-600 text-white px-5 py-2.5 rounded-xl font-bold shadow-lg shadow-blue-200 hover:bg-blue-700 transition-all shrink-0">신규
모델 등록</button>
<button x-show="currentTab === 'depts'" @click="openAddDeptModal()"
class="bg-blue-600 text-white px-5 py-2.5 rounded-xl font-bold shadow-lg shadow-blue-200 hover:bg-blue-700 transition-all shrink-0">신규
부서 생성</button>
</div>
</div>
</header>
<!-- Tabs -->
<div class="flex items-center space-x-2 mb-8 bg-slate-100 p-1.5 rounded-2xl w-fit">
<button @click="currentTab = 'models'"
:class="currentTab === 'models' ? 'bg-white shadow-sm text-blue-600' : 'text-slate-500 hover:text-slate-700'"
class="px-6 py-2 rounded-xl text-sm font-black transition-all">노트북 모델</button>
<button @click="currentTab = 'depts'"
:class="currentTab === 'depts' ? 'bg-white shadow-sm text-blue-600' : 'text-slate-500 hover:text-slate-700'"
class="px-6 py-2 rounded-xl text-sm font-black transition-all">부서 관리</button>
</div>
<!-- Tab 1: Laptop Models -->
<div x-show="currentTab === 'models'" x-transition>
<!-- Bulk Actions -->
<div x-show="selectedIds.length > 0" x-transition x-cloak
class="mb-6 bg-slate-900 text-white px-6 py-3 rounded-2xl flex items-center justify-between shadow-xl">
<div class="flex items-center gap-4">
<div class="flex items-center gap-2">
<span class="text-blue-400 font-black" x-text="selectedIds.length"></span>
<span class="text-xs font-bold text-slate-400">개 선택됨</span>
</div>
<div class="h-4 w-px bg-slate-700"></div>
<div class="flex items-center gap-3">
<span class="text-xs font-bold text-slate-400 uppercase">일괄 변경:</span>
<input type="text" x-model="bulkManufacturer" placeholder="제조사 일괄 변경..."
class="bg-slate-800 border-none rounded-lg text-xs font-bold px-3 py-1.5 focus:ring-1 focus:ring-blue-500 w-40 text-white">
<input type="text" x-model="bulkProductName" placeholder="품명 일괄 변경..."
class="bg-slate-800 border-none rounded-lg text-xs font-bold px-3 py-1.5 focus:ring-1 focus:ring-blue-500 w-40 text-white">
<button @click="applyBulkUpdate"
class="bg-blue-500 hover:bg-blue-600 px-4 py-1.5 rounded-lg text-xs font-black transition-all">적용</button>
</div>
</div>
<button @click="selectedIds = []" class="text-slate-400 hover:text-white transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<!-- Model List Table -->
<div class="bg-white rounded-3xl shadow-sm border border-slate-200 overflow-x-auto no-scrollbar">
<table class="min-w-full divide-y divide-slate-100">
<thead class="bg-slate-50/50">
<tr>
<th class="px-6 py-4 text-left w-10">
<input type="checkbox" @change="toggleSelectAll($event.target.checked)"
class="w-4 h-4 rounded border-slate-300 text-blue-600 focus:ring-blue-500">
</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider">
취득년도</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider">
취득일</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider">
제조사</th>
<th
class="px-6 py-4 text-left text-[10px] font-bold text-slate-500 uppercase tracking-wider">
모델명</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider font-mono">
CPU</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider font-mono">
RAM</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider font-mono text-blue-500">
HDD 0</th>
<th
class="px-4 py-4 text-left text-[10px] font-bold text-slate-400 uppercase tracking-wider">
정격입출력</th>
<th
class="px-6 py-4 text-right text-[10px] font-bold text-slate-500 uppercase tracking-wider whitespace-nowrap">
관리</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-50">
<template x-for="model in filteredModels" :key="model.id">
<tr class="hover:bg-slate-50/80 transition-colors group">
<td class="px-6 py-4">
<input type="checkbox" :value="model.id" x-model="selectedIds"
class="w-4 h-4 rounded border-slate-300 text-blue-600 focus:ring-blue-500">
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-xs font-medium text-slate-500"
@click="editModel(model)">
<span
x-text="model.purchase_date ? model.purchase_date.substring(0,4) : '-'"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-[11px] text-slate-400"
@click="editModel(model)">
<span x-text="model.purchase_date || '-'"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer" @click="editModel(model)">
<span
class="px-2 py-0.5 bg-slate-100 text-slate-600 rounded text-[10px] font-black uppercase tracking-widest"
x-text="model.manufacturer"></span>
</td>
<td class="px-6 py-4 whitespace-nowrap cursor-pointer" @click="editModel(model)">
<span class="text-sm font-bold text-slate-800" x-text="model.model_name"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-xs font-mono text-slate-500"
@click="editModel(model)">
<span x-text="model.cpu || '-'"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-xs font-mono text-slate-600 font-bold"
@click="editModel(model)">
<span x-text="model.ram || '-'"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-xs font-mono text-blue-600 font-bold"
@click="editModel(model)">
<span x-text="model.hdd0_capacity || '-'"></span>
</td>
<td class="px-4 py-4 whitespace-nowrap cursor-pointer text-[10px] text-slate-400"
@click="editModel(model)">
<span x-text="model.power_rating || '-'"></span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right">
<button @click="editModel(model)"
class="text-[11px] font-black text-blue-600 hover:underline px-2 py-1 rounded-lg hover:bg-blue-50 transition-all uppercase">EDIT</button>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<div x-show="filteredModels.length === 0" class="p-20 text-center bg-white rounded-3xl border border-dashed border-slate-300 mt-6">
<p class="text-slate-400 font-medium italic">일치하는 모델 정보가 없습니다.</p>
</div>
</div>
<!-- Tab 2: Departments -->
<div x-show="currentTab === 'depts'" x-transition>
<div class="bg-white rounded-3xl shadow-sm border border-slate-200 overflow-hidden">
<table class="min-w-full divide-y divide-slate-100">
<thead class="bg-slate-50/50">
<tr>
<th class="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">
부서명 (계층구조)</th>
<th class="px-6 py-4 text-left text-xs font-bold text-slate-500 uppercase tracking-wider">
인원수</th>
<th class="px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider">
관리</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-50">
<template x-for="dept in filteredDepts" :key="dept.id">
<tr class="hover:bg-slate-50/80 transition-colors group">
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div :style="'margin-left: ' + (getDeptLevel(dept.path) * 20) + 'px'"
class="flex items-center">
<div class="w-2 h-2 rounded-full mr-3"
:class="getDeptLevel(dept.path) === 0 ? 'bg-blue-600' : 'bg-slate-300'">
</div>
<span class="text-sm font-bold text-slate-900" x-text="dept.name"></span>
<span class="ml-2 text-[10px] text-slate-400 font-medium"
x-show="getDeptLevel(dept.path) > 0" x-text="dept.path"></span>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<button @click="viewDeptMembers(dept)"
class="text-sm font-black text-blue-600 hover:underline">
<span x-text="dept.member_count || 0"></span>명 확인
</button>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right">
<button @click="editDept(dept)"
class="text-xs font-bold text-slate-400 hover:text-blue-600 px-3 py-1 rounded-lg hover:bg-blue-50 transition-all">수정</button>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<div x-show="filteredDepts.length === 0" class="p-20 text-center bg-white rounded-3xl border border-dashed border-slate-300 mt-6">
<p class="text-slate-400 font-medium italic">일치하는 부서 정보가 없습니다.</p>
</div>
</div>
</main>
<!-- Model Modal -->
<div x-show="showModal" x-cloak class="fixed inset-0 z-[110] flex items-center justify-center p-4">
<div class="fixed inset-0 modal-bg" @click="showModal = false"></div>
<div class="bg-white rounded-3xl p-8 max-w-4xl w-full relative z-[111] shadow-2xl max-h-[90vh] overflow-y-auto">
<h3 class="text-2xl font-black mb-6" x-text="isEdit ? '모델 정보 수정' : '신규 모델 등록'"></h3>
<form @submit.prevent="submitModel" class="space-y-6">
<!-- 기본 정보 -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">제조사</label>
<input type="text" x-model="formData.manufacturer" required placeholder="예: SAMSUNG"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">모델명</label>
<input type="text" x-model="formData.model_name" required placeholder="예: NT750XEV"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">품명</label>
<input type="text" x-model="formData.product_name" placeholder="예: 노트북"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
</div>
<!-- 핵심 사양 -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">CPU (프로세서)</label>
<input type="text" x-model="formData.cpu" placeholder="예: i5-1135G7"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">NPU (AI Boost)</label>
<input type="text" x-model="formData.npu" placeholder="예: Intel AI Boost"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">RAM</label>
<input type="text" x-model="formData.ram" placeholder="예: 16GB"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
</div>
<!-- 저장 장치 -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 bg-slate-50 p-4 rounded-2xl">
<div class="space-y-4">
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest">Storage 0
(Main)</label>
<div class="grid grid-cols-2 gap-2">
<input type="text" x-model="formData.hdd0_model" placeholder="타입/모델"
class="w-full px-4 py-2 bg-white border border-slate-200 rounded-lg text-sm outline-none">
<input type="text" x-model="formData.hdd0_capacity" placeholder="용량 (예: 512GB)"
class="w-full px-4 py-2 bg-white border border-slate-200 rounded-lg text-sm outline-none">
</div>
</div>
<div class="space-y-4">
<label class="block text-[10px] font-black text-slate-400 uppercase tracking-widest">Storage 1
(Sub)</label>
<div class="grid grid-cols-2 gap-2">
<input type="text" x-model="formData.hdd1_model" placeholder="타입/모델"
class="w-full px-4 py-2 bg-white border border-slate-200 rounded-lg text-sm outline-none">
<input type="text" x-model="formData.hdd1_capacity" placeholder="용량"
class="w-full px-4 py-2 bg-white border border-slate-200 rounded-lg text-sm outline-none">
</div>
</div>
</div>
<!-- 자산 정보 (취득일) -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2 text-blue-600">취득일</label>
<input type="date" x-model="formData.purchase_date"
class="w-full px-4 py-3 bg-blue-50 border border-blue-100 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
</div>
<!-- 기타 사양 -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">정격입출력</label>
<input type="text" x-model="formData.power_rating" placeholder="예: 20V / 3.25A"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">판매사</label>
<input type="text" x-model="formData.vendor" placeholder="예: 오픈마켓"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">옵션</label>
<input type="text" x-model="formData.options" placeholder="예: 지문인식"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">비고 (특기사항)</label>
<textarea x-model="formData.remarks" rows="2" placeholder="기타 참고할 사양 정보"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none resize-none"></textarea>
</div>
<div class="pt-4 flex gap-3">
<button type="button" @click="showModal = false"
class="flex-1 py-4 bg-slate-100 rounded-2xl font-bold">취소</button>
<button type="submit"
class="flex-1 py-4 bg-blue-600 text-white rounded-2xl font-bold shadow-lg shadow-blue-200"
x-text="isEdit ? '수정 완료' : '모델 등록'"></button>
</div>
</form>
</div>
</div>
<!-- Dept Modal -->
<div x-show="showDeptModal" x-cloak class="fixed inset-0 z-[110] flex items-center justify-center p-4">
<div class="fixed inset-0 modal-bg" @click="showDeptModal = false"></div>
<div class="bg-white rounded-3xl p-8 max-w-md w-full relative z-[111] shadow-2xl">
<h3 class="text-2xl font-black mb-6" x-text="isDeptEdit ? '부서 정보 수정' : '신규 부서 생성'"></h3>
<form @submit.prevent="submitDept" class="space-y-4">
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">부서명</label>
<input type="text" x-model="deptFormData.name" required
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
</div>
<div>
<label class="block text-xs font-bold text-slate-500 uppercase mb-2">상위 부서</label>
<select x-model="deptFormData.parent_id"
class="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500 outline-none">
<option value="">없음 (최상위)</option>
<template x-for="d in depts" :key="d.id">
<option :value="d.id" x-text="d.path" :disabled="d.id == deptFormData.id"></option>
</template>
</select>
</div>
<div class="pt-4 flex gap-3">
<button type="button" @click="showDeptModal = false"
class="flex-1 py-3 bg-slate-100 rounded-xl font-bold">취소</button>
<button type="submit" class="flex-1 py-3 bg-blue-600 text-white rounded-xl font-bold"
x-text="isDeptEdit ? '수정 완료' : '부서 생성'"></button>
</div>
<div x-show="isDeptEdit" class="pt-4 mt-4 border-t border-slate-100">
<button type="button" @click="deleteDept()"
class="w-full py-3 text-sm font-bold text-rose-500 hover:text-white hover:bg-rose-500 border border-rose-200 rounded-xl transition-all">
이 부서 삭제하기
</button>
<p class="text-[10px] text-slate-400 mt-2 text-center">※ 삭제 시 소속 인원은 '미소속'으로 이동됩니다.</p>
</div>
</form>
</div>
</div>
<!-- Members Modal -->
<div x-show="showMembersModal" x-cloak class="fixed inset-0 z-[110] flex items-center justify-center p-4">
<div class="fixed inset-0 modal-bg" @click="showMembersModal = false"></div>
<div
class="bg-white rounded-3xl p-8 max-w-2xl w-full relative z-[111] shadow-2xl overflow-hidden flex flex-col max-h-[80vh]">
<div class="flex justify-between items-center mb-6">
<h3 class="text-2xl font-black text-slate-900" x-text="selectedDept?.name + ' 부서원'"></h3>
<span class="text-xs font-bold text-blue-600 bg-blue-50 px-3 py-1 rounded-full"><span
x-text="members.length"></span>명</span>
</div>
<div class="flex-1 overflow-y-auto pr-2 no-scrollbar">
<table class="min-w-full divide-y divide-slate-100">
<thead class="bg-slate-50 sticky top-0">
<tr>
<th class="px-4 py-3 text-left text-xs font-bold text-slate-500">이름</th>
<th class="px-4 py-3 text-left text-xs font-bold text-slate-500">사번/직위</th>
<th class="px-4 py-3 text-right text-xs font-bold text-slate-500">이동</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-50">
<template x-for="user in members" :key="user.id">
<tr :class="getPositionInfo(user.position).bgClass"
:style="getPositionInfo(user.position).gradientStyle">
<td class="px-4 py-3">
<div class="flex items-center gap-2">
<div class="text-sm font-black text-slate-900" x-text="user.name"></div>
<template x-if="getPositionInfo(user.position).isVIP">
<span
class="text-[9px] px-1.5 py-0.5 rounded-md font-black uppercase tracking-tighter"
:class="getPositionInfo(user.position).tagClass"
x-text="user.position"></span>
</template>
</div>
<div class="text-[10px] font-bold text-slate-400" x-text="user.emp_id"></div>
</td>
<td class="px-4 py-3">
<div class="text-xs font-black text-slate-900" x-text="user.position || '-'"></div>
</td>
<td class="px-4 py-3 text-right">
<select @change="reassignMember(user.id, $event.target.value)"
class="text-[10px] font-bold bg-slate-50 border-none rounded-lg px-2 py-1 outline-none focus:ring-1 focus:ring-blue-500">
<option value="">부서 이동...</option>
<template x-for="d in depts" :key="d.id">
<option :value="d.id" x-text="d.name"
:selected="d.id == user.department_id"></option>
</template>
</select>
</td>
</tr>
</template>
</tbody>
</table>
<div x-show="members.length === 0" class="py-10 text-center text-slate-400 italic text-sm">소속된 부서원이
없습니다.</div>
</div>
<div class="mt-6 pt-6 border-t border-slate-100 flex justify-end">
<button @click="showMembersModal = false"
class="px-6 py-2.5 bg-slate-900 text-white rounded-xl font-bold">닫기</button>
</div>
</div>
</div>
<script>
function dbManagement() {
return {
currentTab: 'models',
// Model Data
models: [],
showModal: false,
isEdit: false,
selectedIds: [],
searchQuery: '',
bulkManufacturer: '',
bulkProductName: '',
formData: {
id: '', manufacturer: '', model_name: '', product_name: '',
cpu: '', npu: '', ram: '',
hdd0_model: '', hdd0_capacity: '',
hdd1_model: '', hdd1_capacity: '',
asset_status: '', fixed_ip: '', assigned_user: '', purchase_date: '',
power_rating: '', vendor: '', options: '', remarks: '', specs: ''
},
get filteredModels() {
if (!this.searchQuery) return this.models;
const q = this.searchQuery.toLowerCase();
return this.models.filter(m =>
(m.model_name && m.model_name.toLowerCase().includes(q)) ||
(m.manufacturer && m.manufacturer.toLowerCase().includes(q)) ||
(m.cpu && m.cpu.toLowerCase().includes(q)) ||
(m.product_name && m.product_name.toLowerCase().includes(q))
);
},
// Dept Data
depts: [],
deptSearchQuery: '',
showDeptModal: false,
showMembersModal: false,
isDeptEdit: false,
selectedDept: null,
members: [],
deptFormData: { id: '', name: '', parent_id: '', level: 1 },
get filteredDepts() {
if (!this.deptSearchQuery) return this.depts;
const q = this.deptSearchQuery.toLowerCase();
return this.depts.filter(d =>
(d.name && d.name.toLowerCase().includes(q)) ||
(d.path && d.path.toLowerCase().includes(q))
);
},
init() {
this.fetchModels();
this.fetchDepts();
},
// Model Methods
fetchModels() {
const scrollPos = window.scrollY;
fetch('api.php?action=get_models').then(res => res.json()).then(data => {
this.models = data;
this.$nextTick(() => window.scrollTo(0, scrollPos));
});
},
toggleSelectAll(checked) {
this.selectedIds = checked ? this.models.map(m => m.id) : [];
},
applyBulkUpdate() {
if (this.selectedIds.length === 0) return;
if (!this.bulkManufacturer && !this.bulkProductName) {
window.showAlert('변경할 항목(제조사 또는 품명)을 입력해주세요.', '입력 오류', 'error');
return;
}
fetch('api.php?action=bulk_update_models', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
ids: this.selectedIds,
manufacturer: this.bulkManufacturer,
product_name: this.bulkProductName
})
}).then(res => res.json()).then(data => {
if (data.success) {
this.selectedIds = [];
this.bulkManufacturer = '';
this.bulkProductName = '';
this.fetchModels();
}
});
},
openAddModal() {
this.isEdit = false;
this.formData = {
id: '', manufacturer: '', model_name: '', product_name: '',
cpu: '', npu: '', ram: '', hdd0_model: '', hdd0_capacity: '', hdd1_model: '', hdd1_capacity: '',
purchase_date: '',
power_rating: '', vendor: '', options: '', remarks: '', specs: ''
};
this.showModal = true;
},
editModel(model) {
this.isEdit = true;
this.formData = { ...model };
this.showModal = true;
},
submitModel() {
const action = this.isEdit ? 'update_model' : 'add_model';
fetch(`api.php?action=${action}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.formData)
}).then(res => res.json()).then(data => {
if (data.success) {
this.showModal = false;
this.fetchModels();
}
});
},
// Dept Methods
fetchDepts() {
fetch('api.php?action=get_departments').then(res => res.json()).then(data => {
this.depts = data;
});
},
getDeptLevel(path) {
if (!path) return 0;
return (path.match(/>/g) || []).length;
},
openAddDeptModal() {
this.isDeptEdit = false;
this.deptFormData = { id: '', name: '', parent_id: '', level: 1 };
this.showDeptModal = true;
},
editDept(dept) {
this.isDeptEdit = true;
this.deptFormData = { id: dept.id, name: dept.name, parent_id: dept.parent_id || '', level: dept.level };
this.showDeptModal = true;
},
submitDept() {
const action = this.isDeptEdit ? 'update_dept' : 'add_dept';
if (this.deptFormData.parent_id) {
const parent = this.depts.find(d => d.id == this.deptFormData.parent_id);
this.deptFormData.level = this.getDeptLevel(parent.path) + 1;
} else {
this.deptFormData.level = 0;
}
fetch(`api.php?action=${action}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.deptFormData)
}).then(res => res.json()).then(data => {
if (data.success) {
this.showDeptModal = false;
this.fetchDepts();
}
});
},
viewDeptMembers(dept) {
this.selectedDept = dept;
fetch(`api.php?action=get_dept_users&dept_id=${dept.id}`).then(res => res.json()).then(data => {
// 직위 랭킹 정렬 적용
const getRank = (pos) => {
if (!pos) return 99;
if (pos.includes('부회장')) return 1;
if (pos.includes('총괄')) return 2;
if (pos.includes('원장')) return 3;
if (pos.includes('센터장')) return 4;
if (pos.includes('본부장')) return 5;
if (pos.includes('실장')) return 6;
if (pos.includes('부문장')) return 7;
if (pos.includes('팀장')) return 8;
return 90;
};
this.members = data.sort((a, b) => getRank(a.position) - getRank(b.position));
this.showMembersModal = true;
});
},
getPositionInfo(pos) {
if (!pos) return { bgClass: 'bg-white', iconClass: 'bg-slate-100 text-slate-500', isVIP: false };
const configs = [
{ key: '부회장', from: '#fbbf24', to: '#d97706', icon: 'bg-amber-100 text-amber-600', tag: 'bg-amber-500 text-white' },
{ key: '총괄', from: '#3b82f6', to: '#1d4ed8', icon: 'bg-blue-100 text-blue-600', tag: 'bg-blue-600 text-white' },
{ key: '원장', from: '#10b981', to: '#059669', icon: 'bg-emerald-100 text-emerald-600', tag: 'bg-emerald-600 text-white' },
{ key: '센터장', from: '#06b6d4', to: '#0891b2', icon: 'bg-cyan-100 text-cyan-600', tag: 'bg-cyan-600 text-white' },
{ key: '본부장', from: '#8b5cf6', to: '#7c3aed', icon: 'bg-purple-100 text-purple-600', tag: 'bg-purple-600 text-white' },
{ key: '실장', from: '#64748b', to: '#475569', icon: 'bg-slate-100 text-slate-600', tag: 'bg-slate-600 text-white' },
{ key: '부문장', from: '#f43f5e', to: '#e11d48', icon: 'bg-rose-100 text-rose-600', tag: 'bg-rose-600 text-white' },
{ key: '팀장', from: '#6366f1', to: '#4f46e5', icon: 'bg-indigo-100 text-indigo-600', tag: 'bg-indigo-600 text-white' }
];
const config = configs.find(c => pos.includes(c.key));
if (config) {
return {
isVIP: true,
gradientStyle: `background: linear-gradient(135deg, ${config.from}08 0%, ${config.to}05 100%)`,
bgClass: 'hover:bg-opacity-50',
iconClass: config.icon,
tagClass: config.tag
};
}
return { bgClass: 'bg-white', iconClass: 'bg-slate-100 text-slate-500', isVIP: false };
},
reassignMember(userId, newDeptId) {
if (!newDeptId) return;
fetch('api.php?action=reassign_user', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_ids: [userId], new_dept_id: newDeptId })
}).then(res => res.json()).then(data => {
if (data.success) {
this.viewDeptMembers(this.selectedDept);
this.fetchDepts();
}
});
},
deleteDept() {
const deptId = this.deptFormData.id;
const deptName = this.deptFormData.name;
window.showConfirm(
`'${deptName}' 부서를 정말 삭제하시겠습니까?\n삭제 후 소속 인원은 '미소속' 부서로 이동하며, 하위 부서들은 상위 계층으로 재배치됩니다.`,
() => {
fetch(`api.php?action=delete_dept&id=${deptId}`)
.then(res => res.json())
.then(data => {
if (data.success) {
window.showAlert('부서가 성공적으로 삭제되었습니다.', '성공', 'success');
this.showDeptModal = false;
this.fetchDepts();
} else {
window.showAlert('부서 삭제 중 오류: ' + (data.error || '알 수 없는 오류'), '삭제 실패', 'error');
}
})
.catch(err => {
console.error(err);
window.showAlert('서버 통신 중 오류가 발생했습니다.', '시스템 오류', 'error');
});
},
'부서 영구 삭제'
);
}
}
}
</script>
</body>
</html>