| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <template>
- <ele-modal
- title="朔源码"
- :visible.sync="QRvisible"
- v-if="QRvisible"
- width="800px"
- :maxable="true"
- >
- <div id="printSection">
- <div
- style="
- position: relative;
- width: 98mm;
- height: 70mm;
- box-sizing: border-box;
- font-size: 10px;
- color: green;
- margin: 0 auto;
- font-weight: 700;
- "
- >
- <div
- style="
- display: flex;
- flex-direction: row;
- width: 260px;
- height: 260px;
- "
- >
- <img style="width: 100%; height: 100%" :src="url" />
- </div>
- </div>
- </div>
- <div slot="footer">
- <el-button @click="print">打印预览</el-button>
- <el-button @click="close">关闭</el-button>
- </div>
- </ele-modal>
- </template>
- <script>
- import { parameterGetByCode } from '@/api/system/dictionary-data';
- import QRCode from 'qrcode';
- export default {
- data() {
- return {
- batchNo: '',
- createDate: '',
- enforceStandards: '',
- layBy: '',
- level: '',
- netWeight: '',
- notice: '',
- productName: '',
- purchaseOrigins: '',
- specification: '',
- warrantyPeriod: '',
- warrantyPeriodUnit: '',
- weightUnit: '',
- url: '',
- workOrderId: '',
- qrCodeUrl: '',
- QRvisible: false,
- industryAttribute: ''
- };
- },
- created() {
- // 行业属性 0:通用行业;1:生物医药行业;2:电线电缆行业;
- parameterGetByCode({
- code: 'industry_attribute'
- }).then((res) => {
- console.log(res.value, '77777');
- if (res.value) {
- console.log(res, '33333333');
- this.industryAttribute = res.value
- }
- });
- },
- computed: {
- clientEnvironmentId() {
- return this.$store.state.user.info.clientEnvironmentId;
- },
- },
- mounted() {},
- methods: {
- open(workOrderId) {
- this.QRvisible = true;
- this.workOrderId = workOrderId;
- this.qrCodeUrl =
- window.location.origin + `/traceability?id=${this.workOrderId}&industry=${this.industryAttribute}&clientEnvironmentId=${this.clientEnvironmentId}`;
- // this.qrCodeUrl = `http://192.168.1.22:9999/traceability?id=${this.workOrderId}`;
- this.$nextTick(() => {
- this.generateQRCodes();
- });
- },
- generateQRCodes() {
- if (this.workOrderId) {
- QRCode.toDataURL(this.qrCodeUrl)
- .then((url) => {
- // item.qrcode = url;
- this.url = url;
- this.$forceUpdate();
- })
- .catch((err) => {
- console.error(err);
- });
- }
- },
- close() {
- this.QRvisible = false;
- },
- print() {
- const printSection = document.getElementById('printSection');
- // 创建打印任务
- const printWindow = window.open('', '_blank');
- printWindow.document.open();
- printWindow.document.write('<html><head><title>打印预览</title>');
- printWindow.document.write(
- '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
- );
- printWindow.document.write('</head><body>');
- printWindow.document.write(printSection.innerHTML);
- printWindow.document.write('</body></html>');
- printWindow.document.close();
- printWindow.onload = function () {
- printWindow.print();
- };
- }
- // print() {
- // const printSection = document.getElementById('printSection');
- // // 创建打印任务
- // const printWindow = window.open('', '_blank');
- // printWindow.document.open();
- // printWindow.document.write('<html><head><title>打印预览</title>');
- // printWindow.document.write(
- // '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
- // );
- // printWindow.document.write('</head><body>');
- // printWindow.document.write(printSection.innerHTML);
- // printWindow.document.write('</body></html>');
- // printWindow.document.close();
- // // printWindow.onload = function () {
- // // printWindow.print();
- // // };
- // }
- }
- };
- </script>
- <style scoped lang="scss"></style>
|