brochure.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. if (data) {
  151. brochures.value = data.items || []
  152. totalCount.value = data.total || 0
  153. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  154. }
  155. isLoading.value = false
  156. }
  157. const handleSearch = () => {
  158. currentPage.value = 1
  159. loadBrochures()
  160. }
  161. const handleReset = () => {
  162. searchKeyword.value = ''
  163. currentPage.value = 1
  164. loadBrochures()
  165. }
  166. const changePage = (page) => {
  167. if (page < 1 || page > totalPages.value) return
  168. currentPage.value = page
  169. loadBrochures()
  170. }
  171. const handleExcelDownload = () => {
  172. const params = searchKeyword.value ? { search_keyword: searchKeyword.value } : {}
  173. window.open(`/api/service/brochure/excel?${new URLSearchParams(params)}`, '_blank')
  174. }
  175. const handleStatusChange = async (id, status) => {
  176. const { error } = await put(`/service/brochure/${id}/status`, { status })
  177. if (error) {
  178. alert('상태 변경에 실패했습니다.')
  179. loadBrochures()
  180. } else {
  181. alert('상태가 변경되었습니다.')
  182. }
  183. }
  184. const handleDelete = async (id) => {
  185. if (!confirm('정말 삭제하시겠습니까?')) return
  186. const { error } = await del(`/service/brochure/${id}`)
  187. if (error) {
  188. alert('삭제에 실패했습니다.')
  189. } else {
  190. alert('삭제되었습니다.')
  191. loadBrochures()
  192. }
  193. }
  194. const formatDate = (dateString) => {
  195. if (!dateString) return '-'
  196. const date = new Date(dateString)
  197. return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`
  198. }
  199. onMounted(() => {
  200. loadBrochures()
  201. })
  202. </script>