originCode.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <ele-modal
  3. title="朔源码"
  4. :visible.sync="QRvisible"
  5. v-if="QRvisible"
  6. width="800px"
  7. :maxable="true"
  8. >
  9. <div id="printSection">
  10. <div
  11. style="
  12. position: relative;
  13. width: 98mm;
  14. height: 70mm;
  15. box-sizing: border-box;
  16. font-size: 10px;
  17. color: green;
  18. margin: 0 auto;
  19. font-weight: 700;
  20. "
  21. >
  22. <div
  23. style="
  24. display: flex;
  25. flex-direction: row;
  26. width: 260px;
  27. height: 260px;
  28. "
  29. >
  30. <img style="width: 100%; height: 100%" :src="url" />
  31. </div>
  32. </div>
  33. </div>
  34. <div slot="footer">
  35. <el-button @click="print">打印预览</el-button>
  36. <el-button @click="close">关闭</el-button>
  37. </div>
  38. </ele-modal>
  39. </template>
  40. <script>
  41. import { parameterGetByCode } from '@/api/system/dictionary-data';
  42. import QRCode from 'qrcode';
  43. export default {
  44. data() {
  45. return {
  46. batchNo: '',
  47. createDate: '',
  48. enforceStandards: '',
  49. layBy: '',
  50. level: '',
  51. netWeight: '',
  52. notice: '',
  53. productName: '',
  54. purchaseOrigins: '',
  55. specification: '',
  56. warrantyPeriod: '',
  57. warrantyPeriodUnit: '',
  58. weightUnit: '',
  59. url: '',
  60. workOrderId: '',
  61. qrCodeUrl: '',
  62. QRvisible: false,
  63. industryAttribute: ''
  64. };
  65. },
  66. created() {
  67. // 行业属性 0:通用行业;1:生物医药行业;2:电线电缆行业;
  68. parameterGetByCode({
  69. code: 'industry_attribute'
  70. }).then((res) => {
  71. console.log(res.value, '77777');
  72. if (res.value) {
  73. console.log(res, '33333333');
  74. this.industryAttribute = res.value
  75. }
  76. });
  77. },
  78. computed: {
  79. clientEnvironmentId() {
  80. return this.$store.state.user.info.clientEnvironmentId;
  81. },
  82. },
  83. mounted() {},
  84. methods: {
  85. open(workOrderId) {
  86. this.QRvisible = true;
  87. this.workOrderId = workOrderId;
  88. this.qrCodeUrl =
  89. window.location.origin + `/traceability?id=${this.workOrderId}&industry=${this.industryAttribute}&clientEnvironmentId=${this.clientEnvironmentId}`;
  90. // this.qrCodeUrl = `http://192.168.1.22:9999/traceability?id=${this.workOrderId}`;
  91. this.$nextTick(() => {
  92. this.generateQRCodes();
  93. });
  94. },
  95. generateQRCodes() {
  96. if (this.workOrderId) {
  97. QRCode.toDataURL(this.qrCodeUrl)
  98. .then((url) => {
  99. // item.qrcode = url;
  100. this.url = url;
  101. this.$forceUpdate();
  102. })
  103. .catch((err) => {
  104. console.error(err);
  105. });
  106. }
  107. },
  108. close() {
  109. this.QRvisible = false;
  110. },
  111. print() {
  112. const printSection = document.getElementById('printSection');
  113. // 创建打印任务
  114. const printWindow = window.open('', '_blank');
  115. printWindow.document.open();
  116. printWindow.document.write('<html><head><title>打印预览</title>');
  117. printWindow.document.write(
  118. '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  119. );
  120. printWindow.document.write('</head><body>');
  121. printWindow.document.write(printSection.innerHTML);
  122. printWindow.document.write('</body></html>');
  123. printWindow.document.close();
  124. printWindow.onload = function () {
  125. printWindow.print();
  126. };
  127. }
  128. // print() {
  129. // const printSection = document.getElementById('printSection');
  130. // // 创建打印任务
  131. // const printWindow = window.open('', '_blank');
  132. // printWindow.document.open();
  133. // printWindow.document.write('<html><head><title>打印预览</title>');
  134. // printWindow.document.write(
  135. // '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  136. // );
  137. // printWindow.document.write('</head><body>');
  138. // printWindow.document.write(printSection.innerHTML);
  139. // printWindow.document.write('</body></html>');
  140. // printWindow.document.close();
  141. // // printWindow.onload = function () {
  142. // // printWindow.print();
  143. // // };
  144. // }
  145. }
  146. };
  147. </script>
  148. <style scoped lang="scss"></style>