detailprintDialog0.vue 5.18 KB
<template>
  <el-dialog
    title="出库单铭牌打印"
    :visible.sync="visible"
    :showdetailprint="showdetailprint"
    width="800px"
    append-to-body
    @close="$emit('update:showdetailprint', false)">
    <div ref="print">
      <el-header>
        <el-button size="mini"
                   type="info"
                   plain icon="el-icon-printer"
                   @click="print()"
                   :class="{hide: isHide}"
                   style="float: right;">打印</el-button>
      </el-header>
      <el-main>
        <div style="padding: 0 29%" v-for="item in DetailList">
          <el-header><!--{{item.companyName}}-->{{item.companyCode}}</el-header>
          <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-bordered">
            <tbody>
            <tr>
              <td width="20%">物料编码</td>
              <td colspan="2" style="text-align:center">
                <span>{{item.materialCode}}</span>
              </td>
            </tr>
            <tr>
              <td scope="col">存货代码</td>
              <td colspan="2" style="text-align:center">
                <span></span>
              </td>
            </tr>
            <tr style="vertical-align:middle">
              <td>存货名称</td>
              <td style="text-align:center">
                <span>{{item.materialName}}</span>
              </td>
              <td rowspan="3" width="20%" style="padding: 2px">
                <div class="qrcode">
                  <!--<barcode :value="item.materialCode" width="1" height="70" fontSize="10"/>-->
                </div>
              </td>
            </tr>
            <tr>
              <td>规格型号</td>
              <td style="text-align:center">
                <span>{{item.materialSpec}}</span>
              </td>
            </tr>
            <tr>
              <td>数<span style="padding-left:27px">量</span></td>
              <td style="text-align:center; padding: 0">
                <!--<input name="" type="text" style="line-height:18px;  border:0; text-align:center;" th:text="${receiptDetail.qty}"/>-->
                <input v-model="item.shipQty" id="qty" name="qty" class="form-control" style="text-align:center;height:30px;border: none">
              </td>
            </tr>
            <tr>
              <td colspan="4" scope="col" style="text-align:center;height: 30px;">
                <span></span>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
      </el-main>

    </div>
  </el-dialog>
</template>

<script>

  import html2canvas from "html2canvas";
  import VueBarcode from 'vue-barcode';
  export default {
    name: 'detailprint-dialog',
    props: {
      showdetailprint: {
        type: Boolean,
        default: false
      },
      DetailList: {
        type: Array,
        defaults: []
      }

    },
    data() {
      return {
        companies: [],
        isHide:false,
        visible: this.showdetailprint,
      }
    },
    watch: {
      showdetailprint() {
        this.visible = this.showdetailprint
      }
    },
    created() {
      this.getCompany();
    },
    methods: {
      getCompany() {
        this.getDicts("companyCode").then(response => {
          this.companies = response.data;
        })

      },
      // 货主字典翻译
      companyName(row, column) {
        return this.selectDictLabel(this.companies, row.companyCode);
      },

      print() {
        this.isHide = true;
        // 转图片打印
        const timer = setTimeout(()=> {
          this.isHide = false;
          html2canvas(this.$refs.print, {
            allowTaint: false,
            taintTest: true,
            useCORS: true,
            windowHeight: document.body.scrollHeight,
            background: "#fff",
          }).then((canvas) => {
            const url = canvas.toDataURL("image/jpeg", 1.0);
            const myimg = document.createElement("img");
            myimg.src = url;
            this.$print(myimg);
          });
        })
        this.$once('hook:beforeDestroy',()=>{
          clearInterval(timer);
          timer = null;
        })
      },


    }
  }
</script>

<style lang="scss" scoped>
  .el-header {
    color: #333;
    text-align: center;
    font-size: 18px;
    line-height: 21px;
    padding-top: 30px;
  }
  .el-main{
    padding: 0;
    width: 100%;
    font-family: "Microsoft YaHei";
  }
  aside{background: none;margin-bottom: 0px;}
  .el-table--border, .el-table--group {
     border-top: 1px solid #d7dae2;
  }
  .table-bordered{
    border-right:1px solid #333;
    border-bottom:1px solid #333;
  }
  caption {
    font-size:18px;
    text-align:center;
    color:#333;
    padding-bottom: 5px;
  }
  .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
    border-top: 1px solid #333;
    line-height: 1.42857;
    padding: 8px;
    vertical-align: middle;
  }
  .table {
    width: 100%;
    max-width: 100%;
    margin-bottom: 20px;
  }
  .table tbody tr td {
    padding: 3px;
    border-left:1px solid #333;
    text-align: center;
  }
  .no-print {
    margin-top: 15px;
  }
  .ad-sheet {
    font-size: 22px;
  }
  .hide {
    display: none;
  }
</style>