printModal.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose title="装运单打印" :height="400" :width="800" ok-text="打印" @ok="onPrint">
  3. <section ref="print" style="padding: 10px 10px 0; position: relative; border: 1px solid #c5c5c5; background: beige; width: 98%" id="printContent">
  4. <span style="position: absolute; right: 20px; top: 10px; font-size: 16px; font-weight: bold"
  5. >{{ info.ccmNo }}#机 / {{ info.btype == 1 ? '冷' : '热' }}</span
  6. >
  7. <div class="ticket next-ticket">
  8. <div style="text-align: center">
  9. <p style="font-size: 24px; font-weight: 800; display: inline-block; border-bottom: 2px solid #000; margin-bottom: 16px; line-height: 30px">
  10. 龙钢公司钢坯装运单
  11. </p>
  12. </div>
  13. <div class="flex" style="line-height: 24px">
  14. <div class="flex-1">库名:{{ info.destination }}</div>
  15. <div class="flex-1" style="text-align: center; font-size: 13px">{{
  16. dayjs(info.arrivalTime).format('YYYY 年 MM 月 DD 日 HH 时 mm 分')
  17. }}</div>
  18. <div class="flex-1" style="text-align: right; font-size: 12px">
  19. {{ dayjs(info.arrivalTime).format('YYYYMMDDHHmmss') }}/{{ info.carNum }}/{{ info.carAllNum }}/{{ info.shift_dictText }}/{{
  20. info.shiftGroup_dictText
  21. }}
  22. </div>
  23. </div>
  24. <a-descriptions style="margin-top: 6px; margin-bottom: 4px" layout="vertical" bordered :column="8" size="small">
  25. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="序号">
  26. <div style="min-height: 80px; display: flex; align-items: center; justify-content: center"
  27. ><span>{{ info.carAllNum }}</span></div
  28. >
  29. </a-descriptions-item>
  30. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="车号">
  31. {{ info.licensePlate }}
  32. </a-descriptions-item>
  33. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="牌号">
  34. <component :is="renderDictTag(info.brandNum, 'billet_spec')" />
  35. </a-descriptions-item>
  36. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="炉号">
  37. <div v-for="item in headDtl" :key="item.id">{{ item.heatNo }} - {{ item.billetNos.length }}</div>
  38. </a-descriptions-item>
  39. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="规格">
  40. 170 / {{ info.size }}
  41. </a-descriptions-item>
  42. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="名称">
  43. 方坯
  44. </a-descriptions-item>
  45. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="支数">
  46. {{ info.amountTotal }}
  47. </a-descriptions-item>
  48. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 12px; padding: 4px; text-align: center; height: 36px" label="重量">
  49. {{ weight > 0 ? weight.toFixed(4) : 0 }}
  50. </a-descriptions-item>
  51. </a-descriptions>
  52. <a-descriptions style="padding: 0 30px" size="small">
  53. <a-descriptions-item label="储运中心"> </a-descriptions-item>
  54. <a-descriptions-item label="轧钢厂"> </a-descriptions-item>
  55. <a-descriptions-item label="炼钢厂"> </a-descriptions-item>
  56. </a-descriptions>
  57. </div>
  58. </section>
  59. </BasicModal>
  60. </template>
  61. <script lang="ts" setup>
  62. import { ref } from 'vue';
  63. import { BasicModal, useModalInner } from '/@/components/Modal';
  64. import dayjs from 'dayjs';
  65. import { render } from '/@/utils/common/renderUtils';
  66. import { printJS } from '/@/hooks/web/usePrintJS';
  67. import { listShippingBill } from '../shippingBill.api';
  68. const props = defineProps({
  69. api: {
  70. type: Function as PropType<(params: any) => Promise<any>>,
  71. default: listShippingBill,
  72. },
  73. });
  74. const info = ref<any>({});
  75. const headDtl = ref<any[]>([]);
  76. const weight = ref<number>(0);
  77. //表单赋值
  78. const [registerModal, { changeLoading, changeOkLoading }] = useModalInner(async (data) => {
  79. const { record } = data;
  80. console.log(record);
  81. if (record) {
  82. info.value = record;
  83. getTableList();
  84. } else {
  85. info.value = {};
  86. }
  87. });
  88. // 渲染字典标签
  89. const renderDictTag = (value: string, dictCode: string) => {
  90. return render.renderDict(value, dictCode);
  91. };
  92. const getTableList = async () => {
  93. try {
  94. changeLoading(true);
  95. changeOkLoading(true);
  96. const { id, ccmNo, heatNo, typeConfigId } = info.value;
  97. const data = await props.api({
  98. id,
  99. ccmNo,
  100. heatNo,
  101. typeConfigId,
  102. });
  103. let newArr: any[] = [];
  104. if (Array.isArray(data)) {
  105. newArr = data;
  106. } else {
  107. for (let item in data) {
  108. if (data[item] && data[item].length > 0) {
  109. newArr = newArr.concat(data[item]);
  110. }
  111. }
  112. }
  113. let allWeight = 0;
  114. // 数据结果按组批号分组
  115. newArr = newArr.reduce((acc, cur) => {
  116. const index = acc.findIndex((item) => cur.heatNo && item.heatNo === cur.heatNo);
  117. if (index === -1) {
  118. acc.push({
  119. ...cur,
  120. billetNos: [...cur.billetNo.split(',')],
  121. });
  122. } else {
  123. acc[index].billetNos = acc[index].billetNos.concat(cur.billetNo.split(','));
  124. }
  125. if (cur.blankOutput) {
  126. allWeight += Number(cur.blankOutput);
  127. }
  128. return acc;
  129. }, []);
  130. headDtl.value = newArr;
  131. weight.value = allWeight;
  132. } catch (error) {
  133. console.log(error);
  134. } finally {
  135. changeLoading(false);
  136. changeOkLoading(false);
  137. }
  138. };
  139. function onPrint() {
  140. changeOkLoading(true);
  141. printJS({
  142. printable: '#printContent',
  143. type: 'html',
  144. });
  145. setTimeout(() => {
  146. changeOkLoading(false);
  147. }, 1000);
  148. }
  149. </script>
  150. <style lang="less">
  151. @media print {
  152. header,
  153. footer,
  154. .noprint {
  155. display: none;
  156. }
  157. @page :first {
  158. margin-top: 10px; /* 第一页的页眉距离顶部为0 */
  159. margin-bottom: 0; /* 第一页的页脚距离底部为0 */
  160. }
  161. }
  162. </style>