list.vue 11 KB

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