list.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="admin--showroom-list">
  3. <!-- 상단 버튼 -->
  4. <div class="admin--search-box">
  5. <div class="admin--search-form"></div>
  6. <div class="admin--search-actions">
  7. <button class="admin--btn admin--btn-primary" @click="goToCreate">
  8. + 전시장 등록
  9. </button>
  10. </div>
  11. </div>
  12. <!-- 테이블 -->
  13. <div class="admin--table-wrapper">
  14. <table class="admin--table">
  15. <thead>
  16. <tr>
  17. <th>NO</th>
  18. <th>전시장명</th>
  19. <th>소속명</th>
  20. <th>대표번호</th>
  21. <th>주소</th>
  22. <th>상태</th>
  23. <th>관리</th>
  24. </tr>
  25. </thead>
  26. <tbody>
  27. <tr v-if="isLoading">
  28. <td colspan="7" class="admin--table-loading">
  29. 데이터를 불러오는 중...
  30. </td>
  31. </tr>
  32. <tr v-else-if="!showrooms || showrooms.length === 0">
  33. <td colspan="7" class="admin--table-empty">
  34. 등록된 전시장이 없습니다.
  35. </td>
  36. </tr>
  37. <tr v-else v-for="(showroom, index) in showrooms" :key="showroom.id">
  38. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  39. <td class="admin--table-title">{{ showroom.name }}</td>
  40. <td>{{ showroom.branch_name || '-' }}</td>
  41. <td>{{ showroom.main_phone }}</td>
  42. <td>{{ showroom.address }}</td>
  43. <td>
  44. <button
  45. class="admin--toggle-btn"
  46. :class="{ 'is-active': showroom.is_active == 1 }"
  47. @click="toggleActive(showroom.id, showroom.is_active)"
  48. >
  49. {{ showroom.is_active == 1 ? '사용' : '비사용' }}
  50. </button>
  51. </td>
  52. <td>
  53. <div class="admin--table-actions">
  54. <button
  55. class="admin--btn-small admin--btn-small-primary"
  56. @click="goToEdit(showroom.id)"
  57. >
  58. 수정
  59. </button>
  60. <button
  61. class="admin--btn-small admin--btn-small-danger"
  62. @click="deleteShowroom(showroom.id)"
  63. >
  64. 삭제
  65. </button>
  66. </div>
  67. </td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. </div>
  72. <!-- 페이지네이션 -->
  73. <div v-if="totalPages > 1" class="admin--pagination">
  74. <button
  75. class="admin--pagination-btn"
  76. :disabled="currentPage === 1"
  77. @click="changePage(currentPage - 1)"
  78. >
  79. 이전
  80. </button>
  81. <button
  82. v-for="page in visiblePages"
  83. :key="page"
  84. class="admin--pagination-btn"
  85. :class="{ 'is-active': page === currentPage }"
  86. @click="changePage(page)"
  87. >
  88. {{ page }}
  89. </button>
  90. <button
  91. class="admin--pagination-btn"
  92. :disabled="currentPage === totalPages"
  93. @click="changePage(currentPage + 1)"
  94. >
  95. 다음
  96. </button>
  97. </div>
  98. <!-- 알림 모달 -->
  99. <AdminAlertModal
  100. v-if="alertModal.show"
  101. :title="alertModal.title"
  102. :message="alertModal.message"
  103. :type="alertModal.type"
  104. @confirm="handleAlertConfirm"
  105. @cancel="handleAlertCancel"
  106. @close="closeAlertModal"
  107. />
  108. </div>
  109. </template>
  110. <script setup>
  111. import { ref, computed, onMounted } from 'vue'
  112. import { useRouter } from 'vue-router'
  113. import AdminAlertModal from '~/components/admin/AdminAlertModal.vue'
  114. definePageMeta({
  115. layout: 'admin',
  116. middleware: ['auth']
  117. })
  118. const router = useRouter()
  119. const { get, del, post } = useApi()
  120. const isLoading = ref(false)
  121. const showrooms = ref([])
  122. const currentPage = ref(1)
  123. const perPage = ref(10)
  124. const totalCount = ref(0)
  125. const totalPages = ref(0)
  126. // 알림 모달
  127. const alertModal = ref({
  128. show: false,
  129. title: '알림',
  130. message: '',
  131. type: 'alert',
  132. onConfirm: null
  133. })
  134. // 알림 모달 표시
  135. const showAlert = (message, title = '알림') => {
  136. alertModal.value = {
  137. show: true,
  138. title,
  139. message,
  140. type: 'alert',
  141. onConfirm: null
  142. }
  143. }
  144. // 확인 모달 표시
  145. const showConfirm = (message, onConfirm, title = '확인') => {
  146. alertModal.value = {
  147. show: true,
  148. title,
  149. message,
  150. type: 'confirm',
  151. onConfirm
  152. }
  153. }
  154. // 알림 모달 닫기
  155. const closeAlertModal = () => {
  156. alertModal.value.show = false
  157. }
  158. // 알림 모달 확인
  159. const handleAlertConfirm = () => {
  160. if (alertModal.value.onConfirm) {
  161. alertModal.value.onConfirm()
  162. }
  163. closeAlertModal()
  164. }
  165. // 알림 모달 취소
  166. const handleAlertCancel = () => {
  167. closeAlertModal()
  168. }
  169. // 보이는 페이지 번호 계산
  170. const visiblePages = computed(() => {
  171. const pages = []
  172. const maxVisible = 5
  173. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
  174. let end = Math.min(totalPages.value, start + maxVisible - 1)
  175. if (end - start < maxVisible - 1) {
  176. start = Math.max(1, end - maxVisible + 1)
  177. }
  178. for (let i = start; i <= end; i++) {
  179. pages.push(i)
  180. }
  181. return pages
  182. })
  183. // 데이터 로드
  184. const loadShowrooms = async () => {
  185. isLoading.value = true
  186. const params = {
  187. page: currentPage.value,
  188. per_page: perPage.value
  189. }
  190. const { data, error } = await get('/showroom/list', { params })
  191. console.log('[ShowroomList] API 응답:', { data, error })
  192. if (data?.success && data?.data) {
  193. showrooms.value = data.data.items || []
  194. totalCount.value = data.data.total || 0
  195. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  196. console.log('[ShowroomList] 로드 성공:', showrooms.value.length)
  197. }
  198. isLoading.value = false
  199. }
  200. // 페이지 변경
  201. const changePage = (page) => {
  202. if (page < 1 || page > totalPages.value) return
  203. currentPage.value = page
  204. loadShowrooms()
  205. window.scrollTo({ top: 0, behavior: 'smooth' })
  206. }
  207. // 전시장 등록 페이지로 이동
  208. const goToCreate = () => {
  209. router.push('/site-manager/showroom/create')
  210. }
  211. // 전시장 수정 페이지로 이동
  212. const goToEdit = (id) => {
  213. router.push(`/site-manager/showroom/edit/${id}`)
  214. }
  215. // 전시장 삭제
  216. const deleteShowroom = (id) => {
  217. showConfirm(
  218. '정말 삭제하시겠습니까?',
  219. async () => {
  220. const { data, error } = await del(`/showroom/${id}`)
  221. if (error || !data?.success) {
  222. showAlert(error?.message || data?.message || '삭제에 실패했습니다.', '오류')
  223. } else {
  224. showAlert(data.message || '전시장이 삭제되었습니다.', '성공')
  225. loadShowrooms()
  226. }
  227. },
  228. '전시장 삭제'
  229. )
  230. }
  231. // 사용/비사용 토글
  232. const toggleActive = (id, currentStatus) => {
  233. console.log('[toggleActive] 호출:', { id, currentStatus })
  234. const statusText = currentStatus == 1 ? '비사용' : '사용'
  235. showConfirm(
  236. `전시장을 ${statusText} 상태로 변경하시겠습니까?`,
  237. async () => {
  238. console.log('[toggleActive] API 호출:', `/showroom/${id}/toggle-active`)
  239. const { data, error } = await post(`/showroom/${id}/toggle-active`)
  240. console.log('[toggleActive] API 응답:', { data, error })
  241. if (error || !data?.success) {
  242. console.error('[toggleActive] 에러 상세:', error)
  243. showAlert(error?.message || data?.message || '상태 변경에 실패했습니다.', '오류')
  244. } else {
  245. showAlert(data.message || '전시장 상태가 변경되었습니다.', '성공')
  246. loadShowrooms()
  247. }
  248. },
  249. '상태 변경'
  250. )
  251. }
  252. onMounted(() => {
  253. loadShowrooms()
  254. })
  255. </script>
  256. <style scoped>
  257. .admin--search-actions .admin--btn-primary {
  258. background: var(--admin-accent-primary);
  259. color: white;
  260. border-color: var(--admin-accent-primary);
  261. font-weight: 500;
  262. padding: 8px 18px;
  263. font-size: 13px;
  264. border-radius: 8px;
  265. transition: all 0.3s ease;
  266. }
  267. .admin--search-actions .admin--btn-primary:hover {
  268. background: var(--admin-accent-hover);
  269. border-color: var(--admin-accent-hover);
  270. transform: translateY(-1px);
  271. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  272. }
  273. .admin--toggle-btn {
  274. padding: 6px 16px;
  275. font-size: 12px;
  276. border-radius: 20px;
  277. border: 1px solid #ddd;
  278. background: #f5f5f5;
  279. color: #666;
  280. cursor: pointer;
  281. transition: all 0.3s ease;
  282. font-weight: 500;
  283. }
  284. .admin--toggle-btn:hover {
  285. border-color: #bbb;
  286. background: #e8e8e8;
  287. }
  288. .admin--toggle-btn.is-active {
  289. background: var(--admin-accent-primary);
  290. color: white;
  291. border-color: var(--admin-accent-primary);
  292. }
  293. .admin--toggle-btn.is-active:hover {
  294. background: var(--admin-accent-hover);
  295. border-color: var(--admin-accent-hover);
  296. }
  297. </style>