<template>
  <div style="background: #ffffff">
    <div class="button-container">
      <el-button  @click="yulandayin" style="width: 200px;height: 50px" type="primary">打印中大物标签预览</el-button>
    </div>
    <div id="printMe" v-for="(kw3,groupIndex) in kwfenzu" :key="groupIndex"  class="group-container">
      <div
        v-for="k2 in kw3"
        class="label-item" >
        <table class="label-table">
          <tr>
            <td  class="td-item" style="width:25mm">纳所/品番</td>
            <td  class="td-item-value" colspan="5"  style="width:125mm ;background: #fcd700">{{ k2.ns }}</td>
            <td  class="td-item" style="width:15mm">箱种</td>
            <td  class="td-item-value2" style="width:25mm">{{ k2.xz }}</td>
          </tr>
          <tr>
            <td class="td-item">品名</td>
            <td  class="td-item-value" colspan="5">{{ k2.pm }}</td>
            <td  class="td-item">收容数</td>
            <td  class="td-item-value" >{{ k2.srs }}</td>
          </tr>
          <tr style="height: 13mm">
            <td class="td-item">货位</td>
            <td  class="td-item-value" colspan="5" style="background: #fcd700">{{ k2.hw }}</td>
            <td  class="td-item" >税别</td>
            <td  class="td-item-value2">{{ k2.bonded }}</td>
          </tr>
          <tr>
            <td class="td-item">供应商</td>
            <td  class="td-item-value2" colspan="7">{{ k2.supplier }}</td>

          </tr>
          <tr style="height: 13mm">
            <td class="td-item">适用机型</td>

            <td  class="td-item-value3" style="width:45mm">{{ k2.jxs[0] }}</td>
            <td  class="td-item-value3" style="width:45mm" >{{ k2.jxs[1] }}</td>
            <td  class="td-item-value3" style="width:45mm" >{{ k2.jxs[2] }}</td>
            <td  class="td-item-value3" style="width:45mm" >{{ k2.jxs[3] }}</td>
            <td  class="td-item-value3" style="width:45mm" >{{ k2.jxs[4] }}</td>
            <td  class="td-item" colspan="2" rowspan="2" style="width: 40mm;height: 20mm;">
              <vue-qrcode
                :value="getQrContent(k2)"
                :options="qrOptions"
                tag="img"
                class="qr-code"
              />
            </td>
          </tr>
          <tr style="height: 13mm">
            <td class="td-item">使用数量</td>
            <td  class="td-item-value" >{{ k2.tyls[0] }}</td>
            <td  class="td-item-value" >{{ k2.tyls[1] }}</td>
            <td  class="td-item-value" >{{ k2.tyls[2] }}</td>
            <td  class="td-item-value" >{{ k2.tyls[3] }}</td>
            <td  class="td-item-value" >{{ k2.tyls[4] }}</td>

          </tr>
        </table>

      </div>
    </div>

  </div>
</template>

<script>
import { vPrint } from 'vue-print-next';
import { VuePrintNext } from 'vue-print-next';
import {bomPrintBiaoQianList} from "@/api/bomAccount";

import VueQrcode from '@chenfengyuan/vue-qrcode';

export default {
  name: 'PointPrint',
  components: {
    VueQrcode
  },
  directives: {
    print: vPrint
  },
  computed: {

  },

  data() {
    return {
      kkkk2: [],
      kwfenzu: [],
      qrOptions: {
        width: 60,          // 二维码宽度
        margin: 0,          // 边距
        errorCorrectionLevel: 'H' // 容错级别（高）
      },
      qrSize: 120, // 二维码尺寸
      // 示例数据 - 实际应用中可从API获取


    }
  },
  mounted() {
    this.getPrintList();
  },
  methods: {
    getQrContent(location) {
      // 自定义二维码内容，这里用箱种和品番组合
      return `${location.ewm}`;

      // 如果只需要箱种，可以直接用：
      // return location.boxType;
    },
    //获取点位表的数据
    yulandayin(){
      new VuePrintNext({
        el: '#printMe', /* 其他参数 */
        popTitle: '打印拣货单',
        preview: false,// 启用打印预览
        paperSize: 'A4',
        orientation: 'portrait'
      });
    },
     getPrintList(){
      console.log('打印标签')
      bomPrintBiaoQianList('_ZDWBQ').then(res => {
        console.log(res)
        this.kkkk2=res;

        this.kwfenzu=[]
        for (let i = 0; i < this.kkkk2.length; i += 3) {
          this.kwfenzu.push(this.kkkk2.slice(i, i + 3));
        }

      });
    }

  }
}


</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Microsoft YaHei', sans-serif;
}
body {
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
  padding: 20px;
  min-height: 100vh;
}
.button-container {
  padding-top: 20px;
  display: flex;
  justify-content: center; /* 水平居中 */
}
.group-container{
  padding-top: 10mm;
  box-shadow: none;margin-bottom:0;padding: 0;border-radius: 0;
  page-break-after: always;
  break-after: page;
}
.label-item {
  display: flex;
  flex-wrap: wrap;
  font-size: 12pt;
  background: #ffffff;
  justify-content: center;
}
.td-item{
  text-align: center;
  border: #000000 2px solid;
  word-wrap: break-word;
  font-size: 12pt;

}

.td-item-value{
  font-size: 25pt;
  font-weight: bold;
  text-align: center;
  border: #000000 2px solid;
}
.td-item-value2{
  font-size: 18pt;
  font-weight: bold;
  text-align: center;
  border: #000000 2px solid;
}

.td-item-value3{
  font-weight: bold;
  text-align: center;
  border: #000000 2px solid;
  font-size: 10pt;
  overflow: hidden;
  word-wrap: break-word;
  overflow: hidden;
}


.qr-code {
  padding: 1mm;
  width: 22mm;   /* 控制显示大小 */
  height: 22mm;
  image-rendering: crisp-edges; /* 保持清晰度 */
  display: block;
  margin: 0 auto;
}

.label-table {
  margin-top: 5mm;
  margin-bottom: 5mm;

  width: 200mm;
  height: 80mm;
  background: #ffffff;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.shrink-content {
  /* 备选方案：使用scale变换 */
  transform-origin: left;
  display: inline-block;
  max-width: 100%;
  margin: 5px;
}
</style>
