<template>
  <ele-modal
    title="出库单"
    :visible.sync="QRvisible"
    v-if="QRvisible"
    width="90%"
  >
    <div
      id="printSection"
      style="
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
      "
    >
      <div
        style="
          position: relative;
          width: 100%;
          height: 100px;
          display: flex;
          flex-direction: column;
          align-items: center;
        "
      >
        <!-- <img
          v-if="groupName.includes('宝盛')"
          style="width: 80px; height: 80px; position: absolute; left: 20px"
          src="@/assets/bslogo.png"
          alt=""
        /> -->
        <div
          style="
            font-size: 20px;
            font-weight: 800;
            text-align: center;
            width: 100%;
          "
          >{{ groupName || '长沙宝盛汽车配件有限公司' }}送货单</div
        >
        <!-- <div
          style="
            font-size: 18px;
            font-weight: 800;
            text-align: center;
            width: 100%;
          "
          >送货单</div
        > -->
      </div>
      <div
        style="
          width: 100%;
          font-size: 12px;
          display: flex;
          justify-content: space-between;
          margin-bottom: 10px;
        "
      >
        <span style="width: 40%">客户名称：{{ formData.contactName }}</span>
        <span style="width: 40%"
          >发货单号：{{ formData.printNo || formData.docNo }}</span
        >
      </div>
      <div
        style="
          width: 100%;
          font-size: 12px;
          display: flex;
          justify-content: space-between;
          margin-bottom: 10px;
        "
      >
        <span style="width: 40%">发货日期：{{ formData.createTime }}</span>
        <span style="width: 40%"
          >收货联系人：{{ formData.linkName }}

          <!-- 联系电话：{{ formData.linkPhone }} -->
        </span>
        <!-- <span> 车牌号：{{ formData.carNo }} </span> -->
      </div>
      <table
        cellspacing="0"
        border
        style="
          width: 100%;
          table-layout: fixed;
          word-break: break-all;
          word-wrap: break-word;
          font-size: 12px;
        "
      >
        <tbody>
          <tr align="center">
            <td style="padding: 5px; width: 35px"> 序号 </td>
            <td style="padding: 5px;"> 车型 </td>
            <td style="padding: 5px;"> 料号 </td>
            <td style="padding: 5px; width: 50px"> 单位</td>
            <td style="padding: 5px"> 交货数</td>
            <td style="padding: 5px"> 实收数量</td>
            <td style="padding: 5px"> 客户订单号</td>
            <td style="padding: 5px"> 重量</td>
            <td style="padding: 5px"> 工艺</td>
            <td style="padding: 5px"> 备注</td>
          </tr>

          <tr align="center" v-for="(item, index) in formData.productList">
            <td style="padding: 5px"> {{ index + 1 }} </td>
            <td style="padding: 5px"> </td>
            <td style="padding: 5px"> {{ item.productName }} </td>
            <td style="padding: 5px">
              {{ item.productCode }}
            </td>
            <td style="padding: 5px"> {{ item.productName }} </td>
            <td style="padding: 5px"> {{ item.measuringUnit }}</td>
            <td style="padding: 5px"> {{ item.totalCount }}</td>
            <td style="padding: 5px"> {{ item.totalCount }}</td>
            <td style="padding: 5px"> </td>
            <td style="padding: 5px">{{ item.orderNo }} </td>
            <td style="padding: 5px"> </td>
          </tr>
        </tbody>
      </table>
      <div
        style="
          width: 100%;
          font-size: 12px;
          display: flex;
          justify-content: space-between;
          margin-top: 10px;
        "
      >
        <div style="flex: 1">
          <div>发货人：</div>
        </div>
        <div style="flex: 1">
          <div>送货人：</div>
        </div>
        <div style="flex: 1"> 收货人: </div>
        <div style="flex: 1"> 托盘:{{   formData.trayNum }} </div>
      
      </div>
    </div>

    <div slot="footer">
      <el-button @click="print">打印预览</el-button>
      <el-button @click="close">关闭</el-button>
    </div>
  </ele-modal>
</template>

<script>
  // import { getSendSaleOrderrecordDetailSplit } from '@/api/saleManage/saleordersendrecord';
  import { mapGetters } from 'vuex';
  export default {
    name: 'print',
    computed: {
      ...mapGetters(['user'])
    },
    props: {
      groupName: ''
    },
    data() {
      return {
        checked: '',
        QRvisible: false,
        isPrintPrice: false,
        formData: {},
        outBound: {}
      };
    },

    methods: {
      async open(id) {
        // this.formData = await getSendSaleOrderrecordDetailSplit(id);
        this.QRvisible = true;
        // let dataArray = await getInfoBySourceBizNoAll(this.formData.docNo);
        // this.outBound = JSON.parse(JSON.stringify(dataArray[0]));
        // this.outBound['outInDetailRecordRequestList'] = [];

        // dataArray.forEach((item) => {
        //   item.outInDetailList.forEach((val) => {
        //     val['orderNo'] = item.orderNo;
        //     if (val.outInDetailRecordRequestList.length) {
        //       val.outInDetailRecordRequestList.forEach((j) => {
        //         j['categoryName'] = val.categoryName;
        //         j['categoryModel'] = val.categoryModel;
        //         j['specification'] = val.specification;
        //         j['categoryCode'] = val.categoryCode;
        //         j['orderNo'] = item.orderNo;

        //       });
        //       this.outBound['outInDetailRecordRequestList'].push(
        //         ...val.outInDetailRecordRequestList
        //       );
        //     } else {
        //       this.outBound['outInDetailRecordRequestList'].push(val);
        //     }
        //   });
        // });
        //包装维度
      },
      close() {
        this.QRvisible = false;
      },

      print() {
        const printSection = document.getElementById('printSection');
        // 创建打印任务
        const printWindow = window.open('', '_blank');
        printWindow.document.open();
        printWindow.document.write('<html><head><title>打印预览</title>');
        printWindow.document.write(
          '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
        );
        printWindow.document.write('</head><body>');
        printWindow.document.write(printSection.innerHTML);
        printWindow.document.write('</body></html>');
        printWindow.document.close();
        printWindow.onload = function () {
          printWindow.print();
        };
      }
    }
  };
</script>

<style lang="scss"></style>
