<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 class="grid-container">
      <div
        v-for="k2 in kw3"
        class="label-item" >
        <table class="label-table">
          <tr style="height: 6mm">
            <td  class="td-item-value" style="width:25mm">台车名</td>
            <td  class="td-item-value" colspan="1" style="width: 46mm;background:#fcd700">{{ k2.hw }}</td>
            <td  class="td-item" rowspan="1" style="width: 23mm;height: 20mm;">
              <vue-qrcode
                  :value="getQrContent(k2)"
                  :options="qrOptions"
                  tag="img"
                  class="qr-code"
              />
            </td>
          </tr>
          <tr style="height: 6mm">
            <td  class="td-item-value"  rowspan="3" style="width:25mm">机型</td>
            <td  class="td-item-value3" >{{ k2.jxs[0] }}</td>
            <td  class="td-item-value3" >{{ k2.jxs[2] }}</td>
          </tr>
          <tr style="height: 6mm">
            <td  class="td-item-value3" >{{ k2.jxs[3] }}</td>
            <td  class="td-item-value3" >{{ k2.jxs[4] }}</td>
          </tr>
          <tr style="height: 6mm">
            <td  class="td-item-value3" >{{ k2.jxs[5] }}</td>
            <td  class="td-item-value3" >{{ k2.jxs[6] }}</td>
          </tr>
        </table>

      </div>
    </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: [],
      kwfenzuAll: [],
      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'//landscape,portrait
      });
    },
     getPrintList(){
      console.log('打印台车标签')
      bomPrintBiaoQianList('_TCBQ').then(res => {
        console.log(res)
        this.kkkk2=res;

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

  }
}


</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Microsoft YaHei', sans-serif;
}
body {
  background: linear-gradient(35deg, #f5f7fa 0%, #e4edf5 100%);
  padding: 20px;
  min-height: 100vh;
}
.button-container {
  padding-top: 20px;
  display: flex;
  justify-content: center; /* 水平居中 */
}
.group-container{
  padding-top: 1mm;
  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;

  background: #ffffff;
  justify-content: center;
}
.td-item{
  text-align: center;
  border: #000000 2px solid;
  font-size: 6pt;
  font-weight: bold;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

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

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

.td-item-value3{
  font-size: 9pt;
  font-weight: bold;
  text-align: center;
  border: #000000 2px solid;
  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 {
  background: #00a0e9;

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

.grid-container {
  display: grid;
  grid-template-columns: repeat(1, 1fr); /* 4列 */
  grid-template-rows: repeat(4, 1fr);   /* 5行 */
  width: 100%;
  height: 100%;
  background: #ffffff;
  gap: 1mm 1mm; /* 标签之间的间隙 */
}

</style>
