index.vue 6.7 KB

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