list.vue 8.1 KB

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