index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="admin--manager-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="branch_name">지점명</option>
  8. <option value="name">이름</option>
  9. <option value="user_id">아이디</option>
  10. <option value="email">이메일</option>
  11. </select>
  12. <input
  13. v-model="searchKeyword"
  14. type="text"
  15. class="admin--form-input admin--search-input"
  16. placeholder="검색어를 입력하세요"
  17. @keyup.enter="handleSearch"
  18. >
  19. <button class="admin--btn admin--btn-primary" @click="handleSearch">
  20. 검색
  21. </button>
  22. <button class="admin--btn admin--btn-secondary" @click="handleReset">
  23. 초기화
  24. </button>
  25. </div>
  26. <div class="admin--search-actions">
  27. <button class="admin--btn admin--btn-primary" @click="goToCreate">
  28. + 지점장 등록
  29. </button>
  30. </div>
  31. </div>
  32. <!-- 테이블 -->
  33. <div class="admin--table-wrapper">
  34. <table class="admin--table">
  35. <thead>
  36. <tr>
  37. <th>NO</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="6" class="admin--table-loading">
  48. 데이터를 불러오는 중...
  49. </td>
  50. </tr>
  51. <tr v-else-if="!managers || managers.length === 0">
  52. <td colspan="6" class="admin--table-empty">
  53. 등록된 지점장이 없습니다.
  54. </td>
  55. </tr>
  56. <tr v-else v-for="(manager, index) in managers" :key="manager.id">
  57. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  58. <td>{{ manager.branch_name }}</td>
  59. <td class="admin--table-title">{{ manager.name }}</td>
  60. <td>{{ manager.username }}</td>
  61. <td>{{ manager.email }}</td>
  62. <td>
  63. <div class="admin--table-actions">
  64. <button
  65. class="admin--btn-small admin--btn-small-primary"
  66. @click="goToEdit(manager.id)"
  67. >
  68. 수정
  69. </button>
  70. <button
  71. class="admin--btn-small admin--btn-small-danger"
  72. @click="handleDelete(manager.id)"
  73. >
  74. 삭제
  75. </button>
  76. </div>
  77. </td>
  78. </tr>
  79. </tbody>
  80. </table>
  81. </div>
  82. <!-- 페이지네이션 -->
  83. <div v-if="totalPages > 1" class="admin--pagination">
  84. <button
  85. class="admin--pagination-btn"
  86. :disabled="currentPage === 1"
  87. @click="changePage(currentPage - 1)"
  88. >
  89. 이전
  90. </button>
  91. <button
  92. v-for="page in visiblePages"
  93. :key="page"
  94. class="admin--pagination-btn"
  95. :class="{ 'is-active': page === currentPage }"
  96. @click="changePage(page)"
  97. >
  98. {{ page }}
  99. </button>
  100. <button
  101. class="admin--pagination-btn"
  102. :disabled="currentPage === totalPages"
  103. @click="changePage(currentPage + 1)"
  104. >
  105. 다음
  106. </button>
  107. </div>
  108. </div>
  109. </template>
  110. <script setup>
  111. import { ref, computed, onMounted } from 'vue'
  112. import { useRouter } from 'vue-router'
  113. definePageMeta({
  114. layout: 'admin',
  115. middleware: ['auth']
  116. })
  117. const router = useRouter()
  118. const { get, del } = useApi()
  119. const isLoading = ref(false)
  120. const managers = ref([])
  121. const searchType = ref('branch_name')
  122. const searchKeyword = ref('')
  123. const currentPage = ref(1)
  124. const perPage = ref(10)
  125. const totalCount = ref(0)
  126. const totalPages = ref(0)
  127. // 보이는 페이지 번호 계산
  128. const visiblePages = computed(() => {
  129. const pages = []
  130. const maxVisible = 5
  131. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
  132. let end = Math.min(totalPages.value, start + maxVisible - 1)
  133. if (end - start < maxVisible - 1) {
  134. start = Math.max(1, end - maxVisible + 1)
  135. }
  136. for (let i = start; i <= end; i++) {
  137. pages.push(i)
  138. }
  139. return pages
  140. })
  141. // 데이터 로드
  142. const loadManagers = async () => {
  143. isLoading.value = true
  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('/branch/manager', params)
  153. console.log('[BranchManager] API 응답:', { data, error })
  154. // API 응답: { success: true, data: { items, total }, message }
  155. if (data?.success && data?.data) {
  156. managers.value = data.data.items || []
  157. totalCount.value = data.data.total || 0
  158. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  159. console.log('[BranchManager] 로드 성공:', managers.value.length)
  160. }
  161. isLoading.value = false
  162. }
  163. // 검색
  164. const handleSearch = () => {
  165. currentPage.value = 1
  166. loadManagers()
  167. }
  168. // 초기화
  169. const handleReset = () => {
  170. searchType.value = 'branch_name'
  171. searchKeyword.value = ''
  172. currentPage.value = 1
  173. loadManagers()
  174. }
  175. // 페이지 변경
  176. const changePage = (page) => {
  177. if (page < 1 || page > totalPages.value) return
  178. currentPage.value = page
  179. loadManagers()
  180. }
  181. // 등록 페이지로 이동
  182. const goToCreate = () => {
  183. router.push('/admin/branch/manager/create')
  184. }
  185. // 수정 페이지로 이동
  186. const goToEdit = (id) => {
  187. router.push(`/admin/branch/manager/edit/${id}`)
  188. }
  189. // 삭제
  190. const handleDelete = async (id) => {
  191. if (!confirm('정말 삭제하시겠습니까?')) return
  192. const { error } = await del(`/branch/manager/${id}`)
  193. if (error) {
  194. alert('삭제에 실패했습니다.')
  195. } else {
  196. alert('삭제되었습니다.')
  197. loadManagers()
  198. }
  199. }
  200. onMounted(() => {
  201. loadManagers()
  202. })
  203. </script>
  204. <style scoped>
  205. .admin--search-actions .admin--btn-primary {
  206. background: var(--admin-accent-primary);
  207. color: white;
  208. border-color: var(--admin-accent-primary);
  209. font-weight: 500;
  210. padding: 8px 18px;
  211. font-size: 13px;
  212. border-radius: 8px;
  213. transition: all 0.3s ease;
  214. }
  215. .admin--search-actions .admin--btn-primary:hover {
  216. background: var(--admin-accent-hover);
  217. border-color: var(--admin-accent-hover);
  218. transform: translateY(-1px);
  219. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  220. }
  221. </style>