print-a2.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class="a2-print-page">
  3. <div v-for="branch in groupedData" :key="branch.id" class="branch-section">
  4. <h2 class="branch-name">{{ branch.name }}</h2>
  5. <div v-for="team in branch.teams" :key="team.id" class="team-section">
  6. <h3 class="team-name">{{ team.name }}</h3>
  7. <div class="staff-grid">
  8. <div v-for="staff in team.staff" :key="staff.id" class="staff-card">
  9. <div class="staff-photo">
  10. <img
  11. v-if="staff.photo_url"
  12. :src="getImageUrl(staff.photo_url)"
  13. :alt="staff.name"
  14. />
  15. <img
  16. v-else
  17. :src="getMediaUrl('/img/FORDKOREA_logo.png')"
  18. alt="FORDKOREA Logo"
  19. class="logo-placeholder"
  20. />
  21. </div>
  22. <div class="staff-info">
  23. <div class="staff-position">
  24. {{ getPositionName(staff.position) }} {{ staff.name }}
  25. </div>
  26. <div class="staff-phone">{{ staff.direct_phone || staff.main_phone }}</div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup>
  35. import { ref, onMounted, computed } from "vue";
  36. definePageMeta({
  37. layout: false,
  38. });
  39. const config = useRuntimeConfig();
  40. const { get } = useApi();
  41. const { getMediaUrl } = useImage();
  42. const { getImageUrl } = useImage();
  43. const { getTeamName, getPositionName } = useSalesData();
  44. const salesList = ref([]);
  45. const showrooms = ref([]);
  46. // 지점별, 팀별로 그룹화
  47. const groupedData = computed(() => {
  48. const branches = {};
  49. salesList.value.forEach((staff) => {
  50. const branchId = staff.showroom || 0;
  51. const teamId = staff.team ?? 0;
  52. // 지점 정보 찾기
  53. const showroom = showrooms.value.find((s) => s.id === branchId);
  54. // 지점이 없으면 건너뛰기 (미지정 제외)
  55. if (!showroom) {
  56. return;
  57. }
  58. // 지점 초기화
  59. if (!branches[branchId]) {
  60. branches[branchId] = {
  61. id: branchId,
  62. name: showroom.name,
  63. teams: {},
  64. };
  65. }
  66. // 팀 초기화
  67. if (!branches[branchId].teams[teamId]) {
  68. branches[branchId].teams[teamId] = {
  69. id: teamId,
  70. name: getTeamName(teamId),
  71. staff: [],
  72. };
  73. }
  74. // 직원 추가
  75. branches[branchId].teams[teamId].staff.push(staff);
  76. });
  77. // 배열로 변환 및 정렬
  78. return Object.values(branches)
  79. .map((branch) => ({
  80. ...branch,
  81. teams: Object.values(branch.teams)
  82. .map((team) => ({
  83. ...team,
  84. staff: team.staff.sort((a, b) => {
  85. // company가 'w'인 경우: position 내림차순
  86. // 그 외: position 오름차순
  87. if (a.position !== b.position) {
  88. if (config.public.company === "w") {
  89. return b.position - a.position; // 내림차순
  90. } else {
  91. return a.position - b.position; // 오름차순
  92. }
  93. }
  94. // 2. 같은 직급이면 display_order 오름차순
  95. return a.display_order - b.display_order;
  96. }),
  97. }))
  98. .sort((a, b) => a.id - b.id),
  99. }))
  100. .sort((a, b) => a.id - b.id);
  101. });
  102. // 데이터 로드
  103. const loadData = async () => {
  104. // 전시장 목록 로드 (is_active=1인 활성화된 지점만)
  105. const { data: branchData } = await get("/branch/list", {
  106. params: { per_page: 1000, is_active: 1 },
  107. });
  108. console.log("[PrintA2] 지점 데이터:", branchData);
  109. if (branchData?.success && branchData?.data) {
  110. showrooms.value = branchData.data.items || [];
  111. }
  112. // 전체 영업사원 목록 로드 (is_act=1인 활성화된 영업사원만)
  113. const { data: salesData } = await get("/staff/sales", {
  114. params: { per_page: 1000, is_act: 1 },
  115. });
  116. console.log("[PrintA2] 영업사원 데이터:", salesData);
  117. if (salesData?.success && salesData?.data) {
  118. salesList.value = salesData.data.items || [];
  119. }
  120. console.log("[PrintA2] 최종 salesList (활성화만):", salesList.value);
  121. };
  122. onMounted(async () => {
  123. await loadData();
  124. // 데이터 로드 후 자동 출력
  125. setTimeout(() => {
  126. window.print();
  127. }, 500);
  128. });
  129. </script>
  130. <style scoped>
  131. .a2-print-page {
  132. padding: 20px;
  133. background: white;
  134. }
  135. .a2-header {
  136. text-align: center;
  137. margin-bottom: 30px;
  138. padding-bottom: 20px;
  139. border-bottom: 3px solid #000;
  140. }
  141. .a2-header h1 {
  142. font-size: 28px;
  143. font-weight: bold;
  144. margin: 0;
  145. }
  146. .branch-section {
  147. margin-bottom: 40px;
  148. page-break-inside: avoid;
  149. }
  150. .branch-name {
  151. font-size: 24px;
  152. font-weight: bold;
  153. color: #333;
  154. margin-bottom: 20px;
  155. padding: 10px;
  156. background: #f0f0f0;
  157. border-left: 5px solid #000;
  158. }
  159. .team-section {
  160. margin-bottom: 30px;
  161. page-break-inside: avoid;
  162. }
  163. .team-name {
  164. font-size: 20px;
  165. font-weight: bold;
  166. color: #555;
  167. margin-bottom: 15px;
  168. padding: 8px;
  169. background: #f8f8f8;
  170. border-left: 3px solid #666;
  171. }
  172. .staff-grid {
  173. display: grid;
  174. grid-template-columns: repeat(8, 1fr);
  175. gap: 20px;
  176. margin-bottom: 20px;
  177. }
  178. .staff-card {
  179. border: 1px solid #ddd;
  180. padding: 15px;
  181. text-align: center;
  182. background: white;
  183. page-break-inside: avoid;
  184. }
  185. .staff-photo {
  186. width: 100%;
  187. height: 150px;
  188. margin-bottom: 10px;
  189. overflow: hidden;
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. border: 1px solid #ddd;
  194. }
  195. .staff-photo img {
  196. max-width: 100%;
  197. max-height: 100%;
  198. object-fit: cover;
  199. }
  200. .staff-photo .logo-placeholder {
  201. max-width: 80%;
  202. max-height: 80%;
  203. object-fit: contain;
  204. }
  205. .staff-info {
  206. margin-top: 10px;
  207. }
  208. .staff-position {
  209. font-size: 16px;
  210. font-weight: bold;
  211. color: #333;
  212. margin-bottom: 5px;
  213. }
  214. .staff-phone {
  215. font-size: 13px;
  216. color: #888;
  217. }
  218. /* 인쇄 스타일 */
  219. @media print {
  220. * {
  221. margin: 0;
  222. padding: 0;
  223. }
  224. body {
  225. margin: 0 !important;
  226. padding: 0 !important;
  227. }
  228. .a2-print-page {
  229. padding: 5mm;
  230. margin: 0;
  231. }
  232. .a2-header {
  233. margin-top: 0;
  234. padding-top: 0;
  235. margin-bottom: 20px;
  236. }
  237. .staff-grid {
  238. grid-template-columns: repeat(8, 1fr);
  239. gap: 10px;
  240. }
  241. .staff-card {
  242. padding: 10px;
  243. }
  244. .staff-photo {
  245. height: 120px;
  246. }
  247. .staff-position {
  248. font-size: 14px;
  249. }
  250. .staff-phone {
  251. font-size: 11px;
  252. }
  253. @page {
  254. size: A2;
  255. margin: 5mm;
  256. }
  257. }
  258. </style>