index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <div class="admin--sales-list">
  3. <!-- 검색 영역 -->
  4. <div class="admin--search-box admin--search-box-large">
  5. <div class="admin--search-filters">
  6. <div class="admin--filter-row">
  7. <label class="admin--filter-label">전시장</label>
  8. <select v-model="filters.showroom" class="admin--form-select">
  9. <option value="">전체</option>
  10. <option v-for="showroom in showrooms" :key="showroom.id" :value="showroom.id">
  11. {{ showroom.name }}
  12. </option>
  13. </select>
  14. <label class="admin--filter-label">지점</label>
  15. <select v-model="filters.branch" class="admin--form-select">
  16. <option value="">전체</option>
  17. <option v-for="branch in branches" :key="branch.id" :value="branch.id">
  18. {{ branch.name }}
  19. </option>
  20. </select>
  21. <label class="admin--filter-label">팀</label>
  22. <select v-model="filters.team" class="admin--form-select">
  23. <option value="">전체</option>
  24. <option v-for="team in teams" :key="team.id" :value="team.id">
  25. {{ team.name }}
  26. </option>
  27. </select>
  28. </div>
  29. <div class="admin--filter-row">
  30. <label class="admin--filter-label">검색어</label>
  31. <input
  32. v-model="filters.keyword"
  33. type="text"
  34. class="admin--form-input"
  35. placeholder="이름으로 검색"
  36. @keyup.enter="handleSearch"
  37. >
  38. <button class="admin--btn admin--btn-primary" @click="handleSearch">
  39. 검색
  40. </button>
  41. <button class="admin--btn admin--btn-secondary" @click="handleReset">
  42. 초기화
  43. </button>
  44. </div>
  45. </div>
  46. <div class="admin--search-actions">
  47. <button class="admin--btn admin--btn-secondary" @click="handleExcelDownload">
  48. 엑셀 다운로드
  49. </button>
  50. <button class="admin--btn admin--btn-secondary" @click="handleA2Print">
  51. A2 출력하기
  52. </button>
  53. <button class="admin--btn admin--btn-primary" @click="goToCreate">
  54. + 사원 등록
  55. </button>
  56. </div>
  57. </div>
  58. <!-- 테이블 -->
  59. <div class="admin--table-wrapper">
  60. <table class="admin--table admin--table-sales">
  61. <thead>
  62. <tr>
  63. <th>NO</th>
  64. <th>사진</th>
  65. <th>전시장</th>
  66. <th>지점</th>
  67. <th>팀</th>
  68. <th>이름</th>
  69. <th>직책</th>
  70. <th>대표번호</th>
  71. <th>핸드폰</th>
  72. <th>이메일</th>
  73. <th>관리</th>
  74. </tr>
  75. </thead>
  76. <tbody>
  77. <tr v-if="isLoading">
  78. <td colspan="11" class="admin--table-loading">
  79. 데이터를 불러오는 중...
  80. </td>
  81. </tr>
  82. <tr v-else-if="!salesList || salesList.length === 0">
  83. <td colspan="11" class="admin--table-empty">
  84. 등록된 영업사원이 없습니다.
  85. </td>
  86. </tr>
  87. <tr v-else v-for="(sales, index) in salesList" :key="sales.id">
  88. <td>{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  89. <td>
  90. <div class="admin--table-photo">
  91. <img v-if="sales.photo_url" :src="sales.photo_url" :alt="sales.name">
  92. <div v-else class="admin--table-photo-empty">사진없음</div>
  93. </div>
  94. </td>
  95. <td>{{ sales.showroom_name }}</td>
  96. <td>{{ sales.branch_name }}</td>
  97. <td>{{ sales.team_name }}</td>
  98. <td class="admin--table-title">{{ sales.name }}</td>
  99. <td>{{ sales.position }}</td>
  100. <td>{{ sales.main_phone }}</td>
  101. <td>{{ sales.mobile }}</td>
  102. <td>{{ sales.email }}</td>
  103. <td>
  104. <div class="admin--table-actions admin--table-actions-col">
  105. <button
  106. class="admin--btn-small admin--btn-small-primary"
  107. @click="goToEdit(sales.id)"
  108. >
  109. 수정
  110. </button>
  111. <button
  112. class="admin--btn-small admin--btn-small-danger"
  113. @click="handleDelete(sales.id)"
  114. >
  115. 삭제
  116. </button>
  117. <button
  118. class="admin--btn-small admin--btn-small-secondary"
  119. @click="handlePrint(sales.id)"
  120. >
  121. 프린트
  122. </button>
  123. <button
  124. class="admin--btn-small admin--btn-small-secondary"
  125. @click="handleExcelExport(sales.id)"
  126. >
  127. 엑셀출력
  128. </button>
  129. </div>
  130. </td>
  131. </tr>
  132. </tbody>
  133. </table>
  134. </div>
  135. <!-- 페이지네이션 -->
  136. <div v-if="totalPages > 1" class="admin--pagination">
  137. <button
  138. class="admin--pagination-btn"
  139. :disabled="currentPage === 1"
  140. @click="changePage(currentPage - 1)"
  141. >
  142. 이전
  143. </button>
  144. <button
  145. v-for="page in visiblePages"
  146. :key="page"
  147. class="admin--pagination-btn"
  148. :class="{ 'is-active': page === currentPage }"
  149. @click="changePage(page)"
  150. >
  151. {{ page }}
  152. </button>
  153. <button
  154. class="admin--pagination-btn"
  155. :disabled="currentPage === totalPages"
  156. @click="changePage(currentPage + 1)"
  157. >
  158. 다음
  159. </button>
  160. </div>
  161. </div>
  162. </template>
  163. <script setup>
  164. import { ref, computed, onMounted } from 'vue'
  165. import { useRouter } from 'vue-router'
  166. definePageMeta({
  167. layout: 'admin',
  168. middleware: ['auth']
  169. })
  170. const router = useRouter()
  171. const { get, del } = useApi()
  172. const isLoading = ref(false)
  173. const salesList = ref([])
  174. const showrooms = ref([])
  175. const branches = ref([])
  176. const teams = ref([])
  177. const filters = ref({
  178. showroom: '',
  179. branch: '',
  180. team: '',
  181. keyword: ''
  182. })
  183. const currentPage = ref(1)
  184. const perPage = ref(10)
  185. const totalCount = ref(0)
  186. const totalPages = ref(0)
  187. // 보이는 페이지 번호 계산
  188. const visiblePages = computed(() => {
  189. const pages = []
  190. const maxVisible = 5
  191. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2))
  192. let end = Math.min(totalPages.value, start + maxVisible - 1)
  193. if (end - start < maxVisible - 1) {
  194. start = Math.max(1, end - maxVisible + 1)
  195. }
  196. for (let i = start; i <= end; i++) {
  197. pages.push(i)
  198. }
  199. return pages
  200. })
  201. // 필터 데이터 로드
  202. const loadFilters = async () => {
  203. // 전시장 리스트
  204. const { data: showroomData } = await get('/staff/showrooms')
  205. if (showroomData) showrooms.value = showroomData
  206. // 지점 리스트
  207. const { data: branchData } = await get('/branch/list', { per_page: 1000 })
  208. if (branchData) branches.value = branchData.items || []
  209. // 팀 리스트
  210. const { data: teamData } = await get('/staff/teams')
  211. if (teamData) teams.value = teamData
  212. }
  213. // 데이터 로드
  214. const loadSales = async () => {
  215. isLoading.value = true
  216. const params = {
  217. page: currentPage.value,
  218. per_page: perPage.value,
  219. ...filters.value
  220. }
  221. const { data, error } = await get('/staff/sales', params)
  222. if (data) {
  223. salesList.value = data.items || []
  224. totalCount.value = data.total || 0
  225. totalPages.value = Math.ceil(totalCount.value / perPage.value)
  226. }
  227. isLoading.value = false
  228. }
  229. // 검색
  230. const handleSearch = () => {
  231. currentPage.value = 1
  232. loadSales()
  233. }
  234. // 초기화
  235. const handleReset = () => {
  236. filters.value = {
  237. showroom: '',
  238. branch: '',
  239. team: '',
  240. keyword: ''
  241. }
  242. currentPage.value = 1
  243. loadSales()
  244. }
  245. // 페이지 변경
  246. const changePage = (page) => {
  247. if (page < 1 || page > totalPages.value) return
  248. currentPage.value = page
  249. loadSales()
  250. }
  251. // 엑셀 다운로드 (전체)
  252. const handleExcelDownload = async () => {
  253. const params = { ...filters.value }
  254. window.open(`/api/staff/sales/excel?${new URLSearchParams(params)}`, '_blank')
  255. }
  256. // A2 출력
  257. const handleA2Print = () => {
  258. const params = { ...filters.value }
  259. window.open(`/api/staff/sales/print-a2?${new URLSearchParams(params)}`, '_blank')
  260. }
  261. // 개별 프린트
  262. const handlePrint = (id) => {
  263. window.open(`/api/staff/sales/${id}/print`, '_blank')
  264. }
  265. // 개별 엑셀 출력
  266. const handleExcelExport = (id) => {
  267. window.open(`/api/staff/sales/${id}/excel`, '_blank')
  268. }
  269. // 등록 페이지로 이동
  270. const goToCreate = () => {
  271. router.push('/admin/staff/sales/create')
  272. }
  273. // 수정 페이지로 이동
  274. const goToEdit = (id) => {
  275. router.push(`/admin/staff/sales/edit/${id}`)
  276. }
  277. // 삭제
  278. const handleDelete = async (id) => {
  279. if (!confirm('정말 삭제하시겠습니까?')) return
  280. const { error } = await del(`/staff/sales/${id}`)
  281. if (error) {
  282. alert('삭제에 실패했습니다.')
  283. } else {
  284. alert('삭제되었습니다.')
  285. loadSales()
  286. }
  287. }
  288. onMounted(() => {
  289. loadFilters()
  290. loadSales()
  291. })
  292. </script>