printDialog.vue 3.34 KB
<template>
  <el-dialog
    title="打印"
    :visible.sync="visible"
    width="1000px"
    append-to-body
    @close="$emit('update:showP', false)"
  >
    <el-button
      size="mini"
      type="primary"
      icon="el-icon-printer"
      @click="print"
      class="pull-right"
    >打印
    </el-button>

    <div ref="print">
      <div v-for="(item, index) in tableData" :key="index">
        <div class="table-container">
          <table
            border="0"
            cellspacing="0"
            cellpadding="0"
            class="table-bordered"
          >
            <caption>
              {{
              item.companyName
              }}
            </caption>
            <tbody>
            <tr>
              <td width="23%" scope="col">物料编码</td>
              <td colspan="2" scope="col" class="center">
                <span>{{ item.code }}</span>
              </td>
            </tr>

            <tr>
              <td>物料类别</td>
              <td class="center">
                <span>{{ item.type }}</span>
              </td>
              <td rowspan="3" width="15%">
                <qrcode-vue
                  :value="'物料编码:'+item.code+', 物料类别:'+item.type+', 物料名称:'+item.name+', 物料规格:'+item.spec"
                  size="60"
                  level="H"
                  renderAs="svg"
                  style="padding-top: 4px"
                ></qrcode-vue>
              </td>
            </tr>
            <tr>
              <td>物料名称</td>
              <td class="center">
                <span>{{ item.name }}</span>
              </td>
            </tr>
            <tr>
              <td>物料规格</td>
              <td class="center">
                <span>{{ item.materialSpec }}</span>
              </td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import html2canvas from 'html2canvas'
  import QrcodeVue from 'qrcode.vue'

  export default {
    name: 'printDialog',
    components: {
      QrcodeVue,
    },
    props: {
      tableData: {
        type: Array,
        defaults: () => []
      },
      showP: {
        type: Boolean,
        defaults: false
      }
    },
    watch: {
      showP() {
        this.visible = this.showP
      }
    },
    data() {
      return {
        visible: this.showP,
        gqrcode: ''
      }
    },
    methods: {
      print() {
        this.$print(this.$refs.print)
      }
    },

  }
</script>

<style lang="scss" scoped>
  .no-print {
    margin-bottom: 20px;
  }

  .table-container {
    width: 320px;
    margin-right: auto;
    margin-left: auto;

    table {
      white-space: wrap;
      border-collapse: collapse;
    }

    .table-bordered {
      width: 100%;
      margin-bottom: 30px;
      border: 1px solid #ebebeb;

      caption {
        font-size: 17px;
        text-align: center;
        color: #333;
        padding-bottom: 5px;
      }

      tbody {
        tr {
          .center {
            text-align: center;
          }

          td {
            padding: 3px;
            text-align: center;
            box-sizing: border-box;
            vertical-align: middle;
            border: 1px solid #000;
            color: #333;

            span {
              color: #333;
            }
          }
        }
      }
    }
  }
</style>