index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 admin--btn-primary" @click="handleSearch">
  19. 검색
  20. </button>
  21. <button class="admin--btn admin--btn-secondary" @click="handleReset">
  22. 초기화
  23. </button>
  24. </div>
  25. <div class="admin--search-actions">
  26. <button class="admin--btn admin--btn-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="isLoading">
  47. <td colspan="7" class="admin--table-loading">
  48. 데이터를 불러오는 중...
  49. </td>
  50. </tr>
  51. <tr v-else-if="!advisors || advisors.length === 0">
  52. <td colspan="7" class="admin--table-empty">
  53. 등록된 어드바이저가 없습니다.
  54. </td>
  55. </tr>
  56. <tr v-else v-for="(advisor, index) in advisors" :key="advisor.id">
  57. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  58. <td>
  59. <div class="admin--table-photo">
  60. <img v-if="advisor.photo_url" :src="advisor.photo_url" :alt="advisor.name">
  61. <div v-else class="admin--table-photo-empty">사진없음</div>
  62. </div>
  63. </td>
  64. <td>{{ advisor.service_center_name }}</td>
  65. <td class="admin--table-title">{{ advisor.name }}</td>
  66. <td>{{ advisor.main_phone }}</td>
  67. <td>{{ advisor.mobile }}</td>
  68. <td>
  69. <div class="admin--table-actions">
  70. <button
  71. class="admin--btn-small admin--btn-small-primary"
  72. @click="goToEdit(advisor.id)"
  73. >
  74. 수정
  75. </button>
  76. <button
  77. class="admin--btn-small admin--btn-small-danger"
  78. @click="handleDelete(advisor.id)"
  79. >
  80. 삭제
  81. </button>
  82. </div>
  83. </td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. </div>
  88. <!-- 페이지네이션 -->
  89. <div v-if="totalPages > 1" class="admin--pagination">
  90. <button
  91. class="admin--pagination-btn"
  92. :disabled="currentPage === 1"
  93. @click="changePage(currentPage - 1)"
  94. >
  95. 이전
  96. </button>
  97. <button
  98. v-for="page in visiblePages"
  99. :key="page"
  100. class="admin--pagination-btn"
  101. :class="{ 'is-active': page === currentPage }"
  102. @click="changePage(page)"
  103. >
  104. {{ page }}
  105. </button>
  106. <button
  107. class="admin--pagination-btn"
  108. :disabled="currentPage === totalPages"
  109. @click="changePage(currentPage + 1)"
  110. >
  111. 다음
  112. </button>
  113. </div>
  114. </div>
  115. </template>
  116. <script setup>
  117. import { ref, computed, onMounted } from 'vue'
  118. import { useRouter } from 'vue-router'
  119. definePageMeta({
  120. layout: 'admin',
  121. middleware: ['auth']
  122. })
  123. const router = useRouter()
  124. const { get, del } = useApi()
  125. const isLoading = ref(false)
  126. const advisors = ref([])
  127. const searchType = ref('all')
  128. const searchKeyword = ref('')
  129. const currentPage = ref(1)
  130. const perPage = ref(10)
  131. const totalCount = ref(0)
  132. const totalPages = ref(0)
  133. const visiblePages = computed(() => {
  134. const pages = []
  135. const maxVisible = 5
  136. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
  137. let end = Math.min(totalPages.value, start + maxVisible - 1)
  138. if (end - start < maxVisible - 1) {
  139. start = Math.max(1, end - maxVisible + 1)
  140. }
  141. for (let i = start; i <= end; i++) {
  142. pages.push(i)
  143. }
  144. return pages
  145. })
  146. const loadAdvisors = async () => {
  147. isLoading.value = true
  148. const params = {
  149. page: currentPage.value,
  150. per_page: perPage.value
  151. }
  152. if (searchKeyword.value) {
  153. params.search_type = searchType.value
  154. params.search_keyword = searchKeyword.value
  155. }
  156. const { data, error } = await get('/staff/advisor', params)
  157. if (data) {
  158. advisors.value = data.items || []
  159. totalCount.value = data.total || 0
  160. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  161. }
  162. isLoading.value = false
  163. }
  164. const handleSearch = () => {
  165. currentPage.value = 1
  166. loadAdvisors()
  167. }
  168. const handleReset = () => {
  169. searchType.value = 'all'
  170. searchKeyword.value = ''
  171. currentPage.value = 1
  172. loadAdvisors()
  173. }
  174. const changePage = (page) => {
  175. if (page < 1 || page > totalPages.value) return
  176. currentPage.value = page
  177. loadAdvisors()
  178. }
  179. const goToCreate = () => {
  180. router.push('/admin/staff/advisor/create')
  181. }
  182. const goToEdit = (id) => {
  183. router.push(`/admin/staff/advisor/edit/${id}`)
  184. }
  185. const handleDelete = async (id) => {
  186. if (!confirm('정말 삭제하시겠습니까?')) return
  187. const { error } = await del(`/staff/advisor/${id}`)
  188. if (error) {
  189. alert('삭제에 실패했습니다.')
  190. } else {
  191. alert('삭제되었습니다.')
  192. loadAdvisors()
  193. }
  194. }
  195. onMounted(() => {
  196. loadAdvisors()
  197. })
  198. </script>