list.vue 8.7 KB

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