list.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="admin--field-list">
  3. <!-- 상단 검색/액션 영역 -->
  4. <div class="admin--search-box">
  5. <div class="admin--search-form">
  6. <select v-model="filterStatus" @change="onSearch" class="admin--form-select admin--search-select">
  7. <option value="">전체</option>
  8. <option value="Y">사용중</option>
  9. <option value="N">미사용</option>
  10. </select>
  11. <input
  12. v-model="searchQuery"
  13. type="text"
  14. placeholder="선상명, 지역명으로 검색"
  15. @keyup.enter="onSearch"
  16. class="admin--form-input admin--search-input"
  17. />
  18. <button @click="onSearch" class="admin--btn-small admin--btn-small-primary">검색</button>
  19. <button @click="resetSearch" class="admin--btn-small admin--btn-small-secondary">초기화</button>
  20. </div>
  21. <div class="admin--search-actions">
  22. <button class="admin--btn-add" @click="goToCreate">+ 새 선상 추가</button>
  23. </div>
  24. </div>
  25. <!-- 테이블 -->
  26. <div class="admin--table-wrapper">
  27. <table class="admin--table">
  28. <thead>
  29. <tr>
  30. <th style="width: 80px;">번호</th>
  31. <th style="width: 140px;">분야</th>
  32. <th style="width: 140px;">지역명</th>
  33. <th>선상명</th>
  34. <th style="width: 100px;">제휴업체</th>
  35. <th style="width: 100px;">상태</th>
  36. <th style="width: 120px;">등록일</th>
  37. <th style="width: 120px;">관리</th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. <tr v-if="isLoading">
  42. <td colspan="8" class="admin--table-loading">데이터를 불러오는 중...</td>
  43. </tr>
  44. <tr v-else-if="!onboards || onboards.length === 0">
  45. <td colspan="8" class="admin--table-empty">등록된 선상이 없습니다.</td>
  46. </tr>
  47. <tr
  48. v-else
  49. v-for="(item, index) in onboards"
  50. :key="item.id"
  51. class="admin--table-row-clickable"
  52. @click="goToDetail(item.id)"
  53. >
  54. <td class="date">{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  55. <td>{{ item.field_name || "-" }}</td>
  56. <td>{{ item.area_name || "-" }}</td>
  57. <td class="admin--table-title">{{ item.name }}</td>
  58. <td>
  59. <span :class="['admin--badge', item.partnership_YN === 'Y' ? 'admin--badge-active' : 'admin--badge-ended']">
  60. {{ item.partnership_YN === "Y" ? "제휴" : "비제휴" }}
  61. </span>
  62. </td>
  63. <td>
  64. <span :class="['admin--badge', getStatusBadgeClass(item.status_YN)]">
  65. {{ getStatusLabel(item.status_YN) }}
  66. </span>
  67. </td>
  68. <td class="date">{{ formatDate(item.created_at) }}</td>
  69. <td>
  70. <div class="admin--table-actions">
  71. <button class="admin--btn-small admin--btn-blue" @click.stop="goToEdit(item.id)">
  72. 수정
  73. </button>
  74. </div>
  75. </td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. </div>
  80. <!-- 페이지네이션 -->
  81. <div v-if="totalPages > 1" class="admin--pagination">
  82. <button
  83. v-if="totalPages > 2"
  84. class="admin--pagination-btn"
  85. :disabled="currentPage === 1"
  86. @click="changePage(1)"
  87. title="처음"
  88. >
  89. ◀◀
  90. </button>
  91. <button
  92. class="admin--pagination-btn"
  93. :disabled="currentPage === 1"
  94. @click="changePage(currentPage - 1)"
  95. title="이전"
  96. >
  97. </button>
  98. <button
  99. v-for="page in visiblePages"
  100. :key="page"
  101. class="admin--pagination-btn"
  102. :class="{ 'is-active': page === currentPage }"
  103. @click="changePage(page)"
  104. >
  105. {{ page }}
  106. </button>
  107. <button
  108. class="admin--pagination-btn"
  109. :disabled="currentPage === totalPages"
  110. @click="changePage(currentPage + 1)"
  111. title="다음"
  112. >
  113. </button>
  114. <button
  115. v-if="totalPages > 2"
  116. class="admin--pagination-btn"
  117. :disabled="currentPage === totalPages"
  118. @click="changePage(totalPages)"
  119. title="끝"
  120. >
  121. ▶▶
  122. </button>
  123. </div>
  124. </div>
  125. </template>
  126. <script setup>
  127. import { ref, computed, onMounted } from "vue";
  128. import { useRouter } from "vue-router";
  129. definePageMeta({
  130. layout: "admin",
  131. middleware: ["auth"],
  132. });
  133. const router = useRouter();
  134. const { get } = useApi();
  135. const isLoading = ref(false);
  136. const onboards = ref([]);
  137. const currentPage = ref(1);
  138. const perPage = ref(10);
  139. const totalCount = ref(0);
  140. const totalPages = ref(0);
  141. const searchQuery = ref("");
  142. const filterStatus = ref("");
  143. // 보이는 페이지 번호 계산
  144. const visiblePages = computed(() => {
  145. const pages = [];
  146. const maxVisible = 5;
  147. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  148. let end = Math.min(totalPages.value, start + maxVisible - 1);
  149. if (end - start < maxVisible - 1) {
  150. start = Math.max(1, end - maxVisible + 1);
  151. }
  152. for (let i = start; i <= end; i++) {
  153. pages.push(i);
  154. }
  155. return pages;
  156. });
  157. // 데이터 로드
  158. const loadOnboards = async () => {
  159. isLoading.value = true;
  160. const params = {
  161. page: currentPage.value,
  162. per_page: perPage.value,
  163. };
  164. if (searchQuery.value) params.search = searchQuery.value;
  165. if (filterStatus.value) params.status = filterStatus.value;
  166. const { data, error } = await get("/onboard/list", { params });
  167. if (error) {
  168. console.error("[OnboardList] 목록 로드 실패:", error);
  169. onboards.value = [];
  170. totalCount.value = 0;
  171. totalPages.value = 0;
  172. } else if (data?.success && data?.data) {
  173. onboards.value = data.data.items || [];
  174. totalCount.value = data.data.total || 0;
  175. totalPages.value = data.data.total_pages || 0;
  176. }
  177. isLoading.value = false;
  178. };
  179. // 검색
  180. const onSearch = () => {
  181. currentPage.value = 1;
  182. loadOnboards();
  183. };
  184. // 검색 초기화
  185. const resetSearch = () => {
  186. searchQuery.value = "";
  187. filterStatus.value = "";
  188. currentPage.value = 1;
  189. loadOnboards();
  190. };
  191. // 페이지 변경
  192. const changePage = (page) => {
  193. if (page < 1 || page > totalPages.value) return;
  194. currentPage.value = page;
  195. loadOnboards();
  196. window.scrollTo({ top: 0, behavior: "smooth" });
  197. };
  198. // 이동
  199. const goToCreate = () => router.push("/site-manager/onboard/create");
  200. const goToDetail = (id) => router.push(`/site-manager/onboard/detail/${id}`);
  201. const goToEdit = (id) => router.push(`/site-manager/onboard/edit/${id}`);
  202. // 상태 라벨 / 뱃지 클래스
  203. const getStatusLabel = (status) => (status === "Y" ? "사용중" : "미사용");
  204. const getStatusBadgeClass = (status) =>
  205. status === "Y" ? "admin--badge-active" : "admin--badge-ended";
  206. // 날짜 포맷
  207. const formatDate = (dateString) => {
  208. if (!dateString) return "-";
  209. const date = new Date(dateString.replace(" ", "T"));
  210. if (isNaN(date.getTime())) return dateString;
  211. return date.toLocaleDateString("ko-KR", {
  212. year: "numeric",
  213. month: "2-digit",
  214. day: "2-digit",
  215. });
  216. };
  217. onMounted(() => {
  218. loadOnboards();
  219. });
  220. </script>