list.vue 11 KB

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