index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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(1)"
  91. title="처음"
  92. >
  93. </button>
  94. <button
  95. class="admin--pagination-btn"
  96. :disabled="currentPage === 1"
  97. @click="changePage(currentPage - 1)"
  98. title="이전"
  99. >
  100. </button>
  101. <button
  102. v-for="page in visiblePages"
  103. :key="page"
  104. class="admin--pagination-btn"
  105. :class="{ 'is-active': page === currentPage }"
  106. @click="changePage(page)"
  107. >
  108. {{ page }}
  109. </button>
  110. <button
  111. class="admin--pagination-btn"
  112. :disabled="currentPage === totalPages"
  113. @click="changePage(currentPage + 1)"
  114. title="다음"
  115. >
  116. </button>
  117. <button
  118. class="admin--pagination-btn"
  119. :disabled="currentPage === totalPages"
  120. @click="changePage(totalPages)"
  121. title="끝"
  122. >
  123. </button>
  124. </div>
  125. </div>
  126. </template>
  127. <script setup>
  128. import { ref, computed, onMounted } from "vue";
  129. import { useRouter } from "vue-router";
  130. definePageMeta({
  131. layout: "admin",
  132. middleware: ["auth"],
  133. });
  134. const router = useRouter();
  135. const { get, del } = useApi();
  136. const { getImageUrl } = useImage();
  137. const advisors = ref([]);
  138. const searchType = ref("all");
  139. const searchKeyword = ref("");
  140. const currentPage = ref(1);
  141. const perPage = ref(10);
  142. const totalCount = ref(0);
  143. const totalPages = ref(0);
  144. const visiblePages = computed(() => {
  145. const pages = [];
  146. const maxVisible = 5;
  147. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  148. let end = Math.min(totalPages.value, start + maxVisible - 1);
  149. if (end - start < maxVisible - 1) {
  150. start = Math.max(1, end - maxVisible + 1);
  151. }
  152. for (let i = start; i <= end; i++) {
  153. pages.push(i);
  154. }
  155. return pages;
  156. });
  157. const loadAdvisors = async () => {
  158. const params = {
  159. page: currentPage.value,
  160. per_page: perPage.value,
  161. };
  162. if (searchKeyword.value) {
  163. params.search_type = searchType.value;
  164. params.search_keyword = searchKeyword.value;
  165. }
  166. const { data, error } = await get("/staff/advisor", { params });
  167. console.log("[Advisor] API 응답:", { data, error });
  168. // API 응답: { success: true, data: { items, total }, message }
  169. if (data?.success && data?.data) {
  170. advisors.value = data.data.items || [];
  171. totalCount.value = data.data.total || 0;
  172. totalPages.value = Math.ceil(totalCount.value / perPage.value);
  173. console.log("[Advisor] 로드 성공:", advisors.value.length);
  174. }
  175. };
  176. const handleSearch = () => {
  177. currentPage.value = 1;
  178. loadAdvisors();
  179. };
  180. const handleReset = () => {
  181. searchType.value = "all";
  182. searchKeyword.value = "";
  183. currentPage.value = 1;
  184. loadAdvisors();
  185. };
  186. const changePage = (page) => {
  187. if (page < 1 || page > totalPages.value) return;
  188. currentPage.value = page;
  189. loadAdvisors();
  190. window.scrollTo({ top: 0, behavior: 'smooth' });
  191. };
  192. const goToCreate = () => {
  193. router.push("/site-manager/staff/advisor/create");
  194. };
  195. const goToEdit = (id) => {
  196. router.push(`/site-manager/staff/advisor/edit/${id}`);
  197. };
  198. const handleDelete = async (id) => {
  199. if (!confirm("정말 삭제하시겠습니까?")) return;
  200. const { error } = await del(`/staff/advisor/${id}`);
  201. if (error) {
  202. alert("삭제에 실패했습니다.");
  203. } else {
  204. alert("삭제되었습니다.");
  205. loadAdvisors();
  206. }
  207. };
  208. onMounted(() => {
  209. loadAdvisors();
  210. });
  211. </script>
  212. <style scoped>
  213. /* 검색 영역 input/select 스타일 통일 */
  214. .admin--search-box .admin--form-input,
  215. .admin--search-box .admin--search-input,
  216. .admin--search-box .admin--form-select,
  217. .admin--search-box .admin--search-select {
  218. border: 1px solid var(--admin-border-color) !important;
  219. border-radius: 4px;
  220. height: 33px !important;
  221. padding: 6px 14px !important;
  222. font-size: 13px !important;
  223. }
  224. </style>