brochure.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="admin--brochure-list">
  3. <!-- 검색 영역 -->
  4. <div class="admin--search-box">
  5. <div class="admin--search-form">
  6. <input
  7. v-model="searchKeyword"
  8. type="text"
  9. class="admin--form-input admin--search-input"
  10. placeholder="신청자명으로 검색"
  11. @keyup.enter="handleSearch"
  12. >
  13. <button class="admin--btn admin--btn-primary" @click="handleSearch">
  14. 검색
  15. </button>
  16. <button class="admin--btn admin--btn-secondary" @click="handleReset">
  17. 초기화
  18. </button>
  19. </div>
  20. <div class="admin--search-actions">
  21. <button class="admin--btn admin--btn-secondary" @click="handleExcelDownload">
  22. 엑셀 다운로드
  23. </button>
  24. </div>
  25. </div>
  26. <!-- 테이블 -->
  27. <div class="admin--table-wrapper">
  28. <table class="admin--table">
  29. <thead>
  30. <tr>
  31. <th>NO</th>
  32. <th>신청자</th>
  33. <th>지점</th>
  34. <th>희망차종</th>
  35. <th>핸드폰</th>
  36. <th>구입예상</th>
  37. <th>신청일자</th>
  38. <th>상태</th>
  39. <th>관리</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. <tr v-if="isLoading">
  44. <td colspan="9" class="admin--table-loading">
  45. 데이터를 불러오는 중...
  46. </td>
  47. </tr>
  48. <tr v-else-if="!brochures || brochures.length === 0">
  49. <td colspan="9" class="admin--table-empty">
  50. 브로셔 요청이 없습니다.
  51. </td>
  52. </tr>
  53. <tr v-else v-for="(brochure, index) in brochures" :key="brochure.id">
  54. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  55. <td class="admin--table-title">{{ brochure.name }}</td>
  56. <td>{{ brochure.branch_name }}</td>
  57. <td>{{ brochure.car_model }}</td>
  58. <td>{{ brochure.phone }}</td>
  59. <td>{{ brochure.purchase_plan }}</td>
  60. <td>{{ formatDate(brochure.created_at) }}</td>
  61. <td>
  62. <select
  63. v-model="brochure.status"
  64. class="admin--status-select"
  65. @change="handleStatusChange(brochure.id, brochure.status)"
  66. >
  67. <option value="접수">접수</option>
  68. <option value="접수완료">접수완료</option>
  69. <option value="계약완료">계약완료</option>
  70. <option value="출고완료">출고완료</option>
  71. </select>
  72. </td>
  73. <td>
  74. <button
  75. class="admin--btn-small admin--btn-small-danger"
  76. @click="handleDelete(brochure.id)"
  77. >
  78. 삭제
  79. </button>
  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(currentPage - 1)"
  91. >
  92. 이전
  93. </button>
  94. <button
  95. v-for="page in visiblePages"
  96. :key="page"
  97. class="admin--pagination-btn"
  98. :class="{ 'is-active': page === currentPage }"
  99. @click="changePage(page)"
  100. >
  101. {{ page }}
  102. </button>
  103. <button
  104. class="admin--pagination-btn"
  105. :disabled="currentPage === totalPages"
  106. @click="changePage(currentPage + 1)"
  107. >
  108. 다음
  109. </button>
  110. </div>
  111. </div>
  112. </template>
  113. <script setup>
  114. import { ref, computed, onMounted } from 'vue'
  115. definePageMeta({
  116. layout: 'admin',
  117. middleware: ['auth']
  118. })
  119. const { get, put, del } = useApi()
  120. const isLoading = ref(false)
  121. const brochures = ref([])
  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. const visiblePages = computed(() => {
  128. const pages = []
  129. const maxVisible = 5
  130. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
  131. let end = Math.min(totalPages.value, start + maxVisible - 1)
  132. if (end - start < maxVisible - 1) {
  133. start = Math.max(1, end - maxVisible + 1)
  134. }
  135. for (let i = start; i <= end; i++) {
  136. pages.push(i)
  137. }
  138. return pages
  139. })
  140. const loadBrochures = async () => {
  141. isLoading.value = true
  142. const params = {
  143. page: currentPage.value,
  144. per_page: perPage.value
  145. }
  146. if (searchKeyword.value) {
  147. params.search_keyword = searchKeyword.value
  148. }
  149. const { data, error } = await get('/service/brochure', params)
  150. console.log('[Brochure] API 응답:', { data, error })
  151. // API 응답: { success: true, data: { items, total }, message }
  152. if (data?.success && data?.data) {
  153. brochures.value = data.data.items || []
  154. totalCount.value = data.data.total || 0
  155. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  156. console.log('[Brochure] 로드 성공:', brochures.value.length)
  157. }
  158. isLoading.value = false
  159. }
  160. const handleSearch = () => {
  161. currentPage.value = 1
  162. loadBrochures()
  163. }
  164. const handleReset = () => {
  165. searchKeyword.value = ''
  166. currentPage.value = 1
  167. loadBrochures()
  168. }
  169. const changePage = (page) => {
  170. if (page < 1 || page > totalPages.value) return
  171. currentPage.value = page
  172. loadBrochures()
  173. }
  174. const handleExcelDownload = () => {
  175. const params = searchKeyword.value ? { search_keyword: searchKeyword.value } : {}
  176. window.open(`/api/service/brochure/excel?${new URLSearchParams(params)}`, '_blank')
  177. }
  178. const handleStatusChange = async (id, status) => {
  179. const { error } = await put(`/service/brochure/${id}/status`, { status })
  180. if (error) {
  181. alert('상태 변경에 실패했습니다.')
  182. loadBrochures()
  183. } else {
  184. alert('상태가 변경되었습니다.')
  185. }
  186. }
  187. const handleDelete = async (id) => {
  188. if (!confirm('정말 삭제하시겠습니까?')) return
  189. const { error } = await del(`/service/brochure/${id}`)
  190. if (error) {
  191. alert('삭제에 실패했습니다.')
  192. } else {
  193. alert('삭제되었습니다.')
  194. loadBrochures()
  195. }
  196. }
  197. const formatDate = (dateString) => {
  198. if (!dateString) return '-'
  199. const date = new Date(dateString)
  200. return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`
  201. }
  202. onMounted(() => {
  203. loadBrochures()
  204. })
  205. </script>