index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="admin--advisor-list">
  3. <!-- 검색 영역 -->
  4. <div class="admin--search-box">
  5. <div class="admin--search-form">
  6. <select v-model="searchType" class="admin--form-select admin--search-select">
  7. <option value="all">전체</option>
  8. <option value="name">이름</option>
  9. <option value="service_center">서비스센터</option>
  10. </select>
  11. <input
  12. v-model="searchKeyword"
  13. type="text"
  14. class="admin--form-input admin--search-input"
  15. placeholder="검색어를 입력하세요"
  16. @keyup.enter="handleSearch"
  17. />
  18. <button class="admin--btn-small admin--btn-small-primary" @click="handleSearch">
  19. 검색
  20. </button>
  21. <button class="admin--btn-small admin--btn-small-secondary" @click="handleReset">
  22. 초기화
  23. </button>
  24. </div>
  25. <div class="admin--search-actions">
  26. <button class="admin--btn-small admin--btn-small-primary" @click="goToCreate">
  27. + 어드바이저 등록
  28. </button>
  29. </div>
  30. </div>
  31. <!-- 테이블 -->
  32. <div class="admin--table-wrapper">
  33. <table class="admin--table">
  34. <thead>
  35. <tr>
  36. <th>NO</th>
  37. <th>사진</th>
  38. <th>서비스센터</th>
  39. <th>이름</th>
  40. <th>대표번호</th>
  41. <th>핸드폰</th>
  42. <th>관리</th>
  43. </tr>
  44. </thead>
  45. <tbody>
  46. <tr v-if="!advisors || advisors.length === 0">
  47. <td colspan="7" class="admin--table-empty">등록된 어드바이저가 없습니다.</td>
  48. </tr>
  49. <tr v-else v-for="(advisor, index) in advisors" :key="advisor.id">
  50. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  51. <td>
  52. <div class="admin--table-photo">
  53. <img
  54. v-if="advisor.photo_url"
  55. :src="getImageUrl(advisor.photo_url)"
  56. :alt="advisor.name"
  57. />
  58. <div v-else class="admin--table-photo-empty">사진없음</div>
  59. </div>
  60. </td>
  61. <td>{{ advisor.service_center_name }}</td>
  62. <td class="admin--table-title">{{ advisor.name }}</td>
  63. <td>{{ advisor.main_phone }}</td>
  64. <td>{{ advisor.direct_phone }}</td>
  65. <td>
  66. <div class="admin--table-actions">
  67. <button
  68. class="admin--btn-small admin--btn-small-primary"
  69. @click="goToEdit(advisor.id)"
  70. >
  71. 수정
  72. </button>
  73. <button
  74. class="admin--btn-small admin--btn-small-danger"
  75. @click="handleDelete(advisor.id)"
  76. >
  77. 삭제
  78. </button>
  79. </div>
  80. </td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. <!-- 페이지네이션 -->
  86. <div v-if="totalPages > 1" class="admin--pagination">
  87. <button
  88. class="admin--pagination-btn"
  89. :disabled="currentPage === 1"
  90. @click="changePage(currentPage - 1)"
  91. >
  92. 이전
  93. </button>
  94. <button
  95. v-for="page in visiblePages"
  96. :key="page"
  97. class="admin--pagination-btn"
  98. :class="{ 'is-active': page === currentPage }"
  99. @click="changePage(page)"
  100. >
  101. {{ page }}
  102. </button>
  103. <button
  104. class="admin--pagination-btn"
  105. :disabled="currentPage === totalPages"
  106. @click="changePage(currentPage + 1)"
  107. >
  108. 다음
  109. </button>
  110. </div>
  111. </div>
  112. </template>
  113. <script setup>
  114. import { ref, computed, onMounted } from "vue";
  115. import { useRouter } from "vue-router";
  116. definePageMeta({
  117. layout: "admin",
  118. middleware: ["auth"],
  119. });
  120. const router = useRouter();
  121. const { get, del } = useApi();
  122. const { getImageUrl } = useImage();
  123. const advisors = ref([]);
  124. const searchType = ref("all");
  125. const searchKeyword = ref("");
  126. const currentPage = ref(1);
  127. const perPage = ref(10);
  128. const totalCount = ref(0);
  129. const totalPages = ref(0);
  130. const visiblePages = computed(() => {
  131. const pages = [];
  132. const maxVisible = 5;
  133. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  134. let end = Math.min(totalPages.value, start + maxVisible - 1);
  135. if (end - start < maxVisible - 1) {
  136. start = Math.max(1, end - maxVisible + 1);
  137. }
  138. for (let i = start; i <= end; i++) {
  139. pages.push(i);
  140. }
  141. return pages;
  142. });
  143. const loadAdvisors = async () => {
  144. const params = {
  145. page: currentPage.value,
  146. per_page: perPage.value,
  147. };
  148. if (searchKeyword.value) {
  149. params.search_type = searchType.value;
  150. params.search_keyword = searchKeyword.value;
  151. }
  152. const { data, error } = await get("/staff/advisor", params);
  153. console.log("[Advisor] API 응답:", { data, error });
  154. // API 응답: { success: true, data: { items, total }, message }
  155. if (data?.success && data?.data) {
  156. advisors.value = data.data.items || [];
  157. totalCount.value = data.data.total || 0;
  158. totalPages.value = Math.ceil(totalCount.value / perPage.value);
  159. console.log("[Advisor] 로드 성공:", advisors.value.length);
  160. }
  161. };
  162. const handleSearch = () => {
  163. currentPage.value = 1;
  164. loadAdvisors();
  165. };
  166. const handleReset = () => {
  167. searchType.value = "all";
  168. searchKeyword.value = "";
  169. currentPage.value = 1;
  170. loadAdvisors();
  171. };
  172. const changePage = (page) => {
  173. if (page < 1 || page > totalPages.value) return;
  174. currentPage.value = page;
  175. loadAdvisors();
  176. };
  177. const goToCreate = () => {
  178. router.push("/admin/staff/advisor/create");
  179. };
  180. const goToEdit = (id) => {
  181. router.push(`/admin/staff/advisor/edit/${id}`);
  182. };
  183. const handleDelete = async (id) => {
  184. if (!confirm("정말 삭제하시겠습니까?")) return;
  185. const { error } = await del(`/staff/advisor/${id}`);
  186. if (error) {
  187. alert("삭제에 실패했습니다.");
  188. } else {
  189. alert("삭제되었습니다.");
  190. loadAdvisors();
  191. }
  192. };
  193. onMounted(() => {
  194. loadAdvisors();
  195. });
  196. </script>
  197. <style scoped>
  198. /* 검색 영역 input/select 스타일 통일 */
  199. .admin--search-box .admin--form-input,
  200. .admin--search-box .admin--search-input,
  201. .admin--search-box .admin--form-select,
  202. .admin--search-box .admin--search-select {
  203. border: 1px solid var(--admin-border-color) !important;
  204. border-radius: 4px;
  205. height: 33px !important;
  206. padding: 6px 14px !important;
  207. font-size: 13px !important;
  208. }
  209. </style>