index.vue 9.3 KB

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