PurchaseInPrint.vue 3.25 KB
<template>
  <div class="container" style=" width:320px;/*height:228px;*/color: #333">
    <div class="noprint container" style="text-align:right; padding: 20px;float: right">
      <a-button v-print="'#printContent'" ghost type="primary">打印</a-button>
    </div>


    <div class="row" id="printContent" >

      <table width="100%" border="0" cellspacing="0" cellpadding="0"
             v-for="source in  dataSource">
        <caption style="font-size:22px;text-align:center; color:#333; padding-bottom: 3px;"></caption>
        <tbody>
        <tr >
          <td  scope="col" style="font-size:12px;font-weight:bold" >物料图号:{{source.drawingNo}}</td>
        </tr>
        <tr >
          <td  scope="col"  width="100%" style="font-size:12px;font-weight:bold" >物料名称:{{source.name}}  </td>
          <td   rowspan="4" style="padding: 1px">
            <!--<img class="" align="center" valign="middle" style="vertical-align:middle; padding:2px;"/>-->
            <!--<span class="qrcode"></span>-->
            <!--            <div id="qrcode" ></div>-->
            <vue-qr  :text="source.userDef3" :size="70" :margin="0"></vue-qr>
          </td>
        </tr>
        <tr >
          <td scope="col" style="font-size:12px;font-weight:bold" >物料规格:</td>
        </tr>
        <tr >
          <td scope="col" style="font-size:12px;font-weight:bold" >生产数量:{{source.qty}}</td>
        </tr>
        <tr >
          <td scope="col" style="font-size:12px;font-weight:bold">部件工作令:{{source.userDef1}}</td>
        </tr>
        <tr >
          <td scope="col" style="font-size:12px;font-weight:bold">项目名称:{{source.userDef2}}</td>
        </tr>
        <tr >
          <td scope="col" style="font-size:12px;font-weight:bold">工序:{{source.technology}}</td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
import QRCode from 'qrcodejs2'
import VueQr from 'vue-qr'
import { getSchedulerPrint } from '../../api/api'

export default {
  name: 'PurchaseInPrint',
  components: {
    QRCode,
    VueQr,
  },
  data() {
    return {
      dataSource:[],
      downloadData: {
        url: '扫码访问的链接地址',
        icon: '随便一张图片的地址也行'
      },
      value: 'https://example.com',
      size: 300,
    }
  },
  methods:{
    print(){
      var print= document.getElementById('printContent');
      var newContent = print.innerHTML;
      var oldContent = document.body.innerHTML;
      // this.$nextTick (function () {
      //   this.qrcode();
      // });
      document.body.innerHTML = newContent;
      // 获取要打印的dom内容
      // let  newDomHtml =  this.$refs.printContent.innerHTML;
      // // 将要打印的内容赋值给本页
      // window.document.body.innerHTML= newDomHtml ;
      // 调用window的打印
      window.print();
      // 解决打印之后按钮失效的问题,刷新页面
      window.location.reload();
      return false;
    },

    loadData(id){
      getSchedulerPrint(id).then((res) => {
        console.log(res);
        this.dataSource = res;
      })
    },

    created() {
      this.getDate();
    },


  },

  mounted:function() {
    let id = this.$route.query.id;
    this.loadData(id);
  },
}
</script>

<style scoped>

</style>