print-template-bs-car.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <ele-modal
  3. title="送货单"
  4. :visible.sync="QRvisible"
  5. v-if="QRvisible"
  6. width="90%"
  7. destroy-on-close
  8. >
  9. <div
  10. id="printSection"
  11. ref="printRef"
  12. style="
  13. display: flex;
  14. align-items: center;
  15. justify-content: center;
  16. flex-direction: column;
  17. "
  18. >
  19. <div
  20. style="
  21. position: relative;
  22. width: 100%;
  23. display: flex;
  24. flex-direction: column;
  25. align-items: center;
  26. margin-bottom: 20px;
  27. "
  28. >
  29. <!-- <img
  30. v-if="groupName.includes('宝盛')"
  31. style="width: 80px; height: 80px; position: absolute; left: 20px"
  32. src="@/assets/bslogo.png"
  33. alt=""
  34. /> -->
  35. <div
  36. style="
  37. font-size: 18px;
  38. font-weight: 800;
  39. text-align: center;
  40. width: 100%;
  41. "
  42. >{{ groupName || '长沙宝盛汽车配件有限公司' }}送货单</div
  43. >
  44. </div>
  45. <div
  46. style="
  47. width: 100%;
  48. display: flex;
  49. justify-content: space-between;
  50. margin-bottom: 10px;
  51. "
  52. >
  53. <span style="width: 40%">客户名称:{{ infoData.customerNames }}</span>
  54. <span style="width: 40%"
  55. >发货单号:{{ infoData.allotCode }}</span
  56. >
  57. </div>
  58. <div
  59. style="
  60. width: 100%;
  61. display: flex;
  62. justify-content: space-between;
  63. margin-bottom: 10px;
  64. "
  65. >
  66. <span style="width: 40%">发货日期:{{ infoData.createTime }}</span>
  67. <span style="width: 40%"
  68. >收货联系人:{{ infoData.receiveContacts }} {{ infoData.receiveTels }}</span
  69. >
  70. </div>
  71. <table
  72. cellspacing="0"
  73. class="print-table"
  74. border
  75. style="
  76. width: 100%;
  77. table-layout: fixed;
  78. word-break: break-all;
  79. word-wrap: break-word;
  80. font-size: 12px;
  81. "
  82. >
  83. <tbody>
  84. <tr align="center">
  85. <td style="padding: 5px; width: 35px"> 序号 </td>
  86. <td style="padding: 5px; width: 10%;"> 车型 </td>
  87. <td style="padding: 5px; width: 12%;"> 料号 </td>
  88. <td style="padding: 5px; width: 14%;"> 零件名 </td>
  89. <td style="padding: 5px; width: 8%;"> 单位</td>
  90. <td style="padding: 5px; width: 8%;"> 交货数</td>
  91. <td style="padding: 5px; width: 8%;"> 实收数量</td>
  92. <td style="padding: 5px; width: 11%"> 客户订单号</td>
  93. <td style="padding: 5px; width: 8%;"> 重量</td>
  94. <td style="padding: 5px; width: 14%;"> 工艺</td>
  95. <td style="padding: 5px; width: 12%;"> 备注</td>
  96. </tr>
  97. <tr align="center" v-for="(item, index) in detailList">
  98. <td style="padding: 5px"> {{ index + 1 }} </td>
  99. <td style="padding: 5px">
  100. <span v-if="isPrint">{{ item.car }}</span>
  101. <el-input
  102. v-else
  103. type="textarea"
  104. style="width: 100%; border: none;"
  105. placeholder=""
  106. v-model="item.car"
  107. class="input-with-select"
  108. autosize
  109. ></el-input>
  110. </td>
  111. <td style="padding: 5px"> {{ item.categoryCode }} </td>
  112. <td style="padding: 5px">
  113. {{ item.categoryName }}
  114. </td>
  115. <td style="padding: 5px"> {{ item.measureUnit }} </td>
  116. <td style="padding: 5px"> {{ item.quantity }}</td>
  117. <td style="padding: 5px"> </td>
  118. <td style="padding: 5px"> {{ item.saleOrderNo }}</td>
  119. <td style="padding: 5px"> {{ item.weight }}</td>
  120. <td style="padding: 5px">
  121. <span v-if="isPrint">{{ item.produceRoutingName }}</span>
  122. <el-input
  123. v-else
  124. type="textarea"
  125. style="width: 100%; border: none;"
  126. placeholder=""
  127. v-model="item.produceRoutingName"
  128. class="input-with-select"
  129. autosize
  130. ></el-input>
  131. </td>
  132. <td style="padding: 5px"> {{ item.remark }} </td>
  133. </tr>
  134. <tr style="height: 40px;">
  135. <td style="border: 1px solid #000; padding: 8px; text-align: center;"></td>
  136. <td colspan="2" style="border: 1px solid #000; padding: 8px; text-align: center;">合计</td>
  137. <!-- <td style="border: 1px solid #000; padding: 8px; text-align: center;"></td> -->
  138. <td style="border: 1px solid #000; padding: 8px; text-align: center;"></td>
  139. <td style="border: 1px solid #000; padding: 8px; text-align: center;"></td>
  140. <td style="border: 1px solid #000; padding: 8px; text-align: center;">{{ detailList.reduce((total, item) => total + Number(item.quantity || 0), 0) || ''}}</td>
  141. <td style="border: 1px solid #000; padding: 8px; text-align: center;"></td>
  142. <td style="border: 1px solid #000; padding: 8px; text-align: center;" colspan="4">
  143. <div style="display: flex; align-items: center;" class="foot">
  144. <div style="flex: 1; width: 25%; display: flex; align-items: center;">
  145. <span style="width: 50px;">铁框:</span>
  146. <span v-if="isPrint">{{ query.tk }}</span>
  147. <el-input
  148. v-else
  149. style="width: calc(100% - 50px); border: none;"
  150. placeholder=""
  151. v-model="query.tk"
  152. class="input-with-select"
  153. >
  154. </el-input>
  155. </div>
  156. <div style="flex: 1; width: 25%; display: flex; align-items: center;">
  157. <span style="width: 50px;">托盘:</span>
  158. <span v-if="isPrint">{{ query.tp }}</span>
  159. <el-input
  160. v-else
  161. style="width: 100%; border: none;"
  162. placeholder=""
  163. v-model="query.tp"
  164. class="input-with-select"
  165. ></el-input>
  166. </div>
  167. <div style="flex: 1; width: 25%; display: flex; align-items: center;">
  168. <span style="width: 50px;">工装:</span>
  169. <span v-if="isPrint">{{ query.gz }}</span>
  170. <el-input
  171. v-else
  172. style="width: calc(100% - 50px); border: none;"
  173. placeholder=""
  174. v-model="query.gz"
  175. class="input-with-select"
  176. ></el-input>
  177. </div>
  178. <div style="flex: 1; width: 25%; display: flex; align-items: center;">
  179. <span style="width: 50px;">胶框:</span>
  180. <span v-if="isPrint">{{ query.jk }}</span>
  181. <el-input
  182. v-else
  183. style="width: calc(100% - 50px); border: none;"
  184. placeholder=""
  185. v-model="query.jk"
  186. class="input-with-select"
  187. ></el-input>
  188. </div>
  189. </div>
  190. </td>
  191. </tr>
  192. </tbody>
  193. </table>
  194. <div
  195. style="
  196. width: 100%;
  197. display: flex;
  198. justify-content: space-between;
  199. margin-top: 10px;
  200. "
  201. >
  202. <div style="flex: 1">
  203. <div>发货人:{{ infoData.allotName }}</div>
  204. </div>
  205. <div style="flex: 1">
  206. <div>承运人:{{ infoData.carNo }}</div>
  207. </div>
  208. <div style="flex: 1"> 收货人: </div>
  209. <!-- <div style="flex: 1"> 托盘:{{ infoData.trayNum }} </div> -->
  210. </div>
  211. </div>
  212. <div slot="footer">
  213. <el-button @click="print">打印预览</el-button>
  214. <el-button @click="close">关闭</el-button>
  215. </div>
  216. </ele-modal>
  217. </template>
  218. <script>
  219. import storageApi from '@/api/warehouseManagement/index.js';
  220. import { mapGetters } from 'vuex';
  221. import { printElement } from 'ele-admin';
  222. export default {
  223. name: 'print',
  224. computed: {
  225. ...mapGetters(['user'])
  226. },
  227. props: {
  228. groupName: {
  229. type: String,
  230. default: ''
  231. }
  232. },
  233. data() {
  234. return {
  235. isPrint: false,
  236. checked: '',
  237. QRvisible: false,
  238. isPrintPrice: false,
  239. infoData: {},
  240. outBound: {},
  241. detailList: [],
  242. query: {
  243. tp: '',
  244. gz: '',
  245. jk: '',
  246. tk: '',
  247. }
  248. };
  249. },
  250. methods: {
  251. print() {
  252. this.isPrint = true;
  253. // 等待 DOM 更新完成后再打印,确保输入框变成不可编辑的 span
  254. this.$nextTick(() => {
  255. // 如果 ref 是组件可以用 this.$refs.printRef.$el
  256. // printElement(this.$refs.printRef);
  257. //printElement(this.$refs.printRef, { }); // 参数二加更多参数同 printThis 方法
  258. this.print1();
  259. });
  260. },
  261. async open(row) {
  262. this.row = row;
  263. this.getData();
  264. this.QRvisible = true;
  265. },
  266. async getData() {
  267. const res = await storageApi.getAllotDetailList({
  268. applyId: this.row.id
  269. });
  270. const data = await storageApi.getAllotDetail(this.row.id);
  271. this.infoData = data;
  272. if (this.infoData.type == 1) {
  273. // 库内调拨
  274. /* this.infoData.auditStatus = 2; */
  275. this.infoData.auditStatus = data.status;
  276. } else {
  277. // 库外调拨
  278. this.infoData.auditStatus = data.status;
  279. }
  280. this.detailList = res.map((item) => {
  281. return {
  282. ...item,
  283. // categoryCode: this.infoData.categoryCode,
  284. // categoryName: this.infoData.categoryName,
  285. // brandNum: this.infoData.brandNum,
  286. // categoryModel: this.infoData.model,
  287. // specification: this.infoData.specification
  288. };
  289. });
  290. console.log('infoData', this.infoData)
  291. console.log('detailList', this.detailList)
  292. },
  293. close() {
  294. this.QRvisible = false;
  295. },
  296. print1() {
  297. const printSection = document.getElementById('printSection');
  298. const self = this;
  299. // 创建打印任务
  300. const printWindow = window.open('', '_blank');
  301. printWindow.document.open();
  302. printWindow.document.write('<html><head><title>打印预览</title>');
  303. printWindow.document.write(
  304. '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  305. );
  306. printWindow.document.write('</head><body>');
  307. printWindow.document.write(printSection.innerHTML);
  308. printWindow.document.write('</body></html>');
  309. printWindow.document.close();
  310. // 监听打印窗口关闭事件,恢复输入框
  311. printWindow.onbeforeunload = function() {
  312. self.isPrint = false;
  313. };
  314. printWindow.onunload = function() {
  315. self.isPrint = false;
  316. };
  317. printWindow.onafterprint = function() {
  318. self.isPrint = false;
  319. };
  320. printWindow.onload = function () {
  321. printWindow.print();
  322. };
  323. }
  324. }
  325. };
  326. </script>
  327. <style lang="scss" scoped>
  328. :deep(.print-table) {
  329. .el-input--medium {
  330. font-size: 12px !important;
  331. .el-textarea__inner {
  332. border: none;
  333. padding-left: 0;
  334. padding-right: 0;
  335. }
  336. }
  337. }
  338. :deep(.foot) {
  339. .el-input--medium {
  340. font-size: 12px !important;
  341. .el-input__inner {
  342. border: none;
  343. padding-left: 0;
  344. padding-right: 0;
  345. }
  346. }
  347. }
  348. </style>