<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>
        <div
          style="
            border-bottom: solid 1px #000;
            font-size: 20px;
            font-weight: 800;
            padding-right: 20px;
            width: 400px;
            margin: 0 auto;
          "
          >{{this.groupName||'嘉实（湖南）医院科技有限公司'}}出库单</div
        >
        <div style="text-align: center"
          >（文件编号：JS/SPM-GY-005-01(A/O)）</div
        >
      </div>
      <div
        style="
          width: 100%;
          font-size: 12px;
          display: flex;
          justify-content: space-between;
          margin-bottom: 10px;
        "
      >
        <span style="width: 70%">客户地址：{{ formData.receiveAddress }}</span>
        <span style="width: 30%">NO.：{{ formData.printNo||formData.docNo }}</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"> 编号 </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>
            <td style="padding: 5px"> 序列号</td>
            <td style="padding: 5px"> 备注</td>
          </tr>

          <tr align="center" v-for="(item, index) in outBound.outInDetailRecordRequestList">
            <td style="padding: 5px"> {{ index + 1 }} </td>
            <td style="padding: 5px"> {{ item.categoryName }} </td>
            <td style="padding: 5px">
              {{ item.specification }}/{{ item.categoryModel }}
            </td>
            <td style="padding: 5px"> >{{this.groupName||'嘉实（湖南）医院科技有限公司'}}</td>
            <td style="padding: 5px"> {{ item.measureQuantity }}</td>
            <td style="padding: 5px"> {{ item.measureUnit }}</td>
            <td style="padding: 5px"> {{ item.batchNo }}</td>
            <td style="padding: 5px"> {{item.serialNumber}}</td>
            <td style="padding: 5px"> {{ item.engrave }}</td>
          </tr>
          <tr>
            <td style="padding: 5px" colspan="9">
              备注: &nbsp;白色仓库联&nbsp;&nbsp;&nbsp;
              红色客户联&nbsp;&nbsp;&nbsp; 黄色财务联</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>编单人/日期：{{ formData.makerName }}</div>
          <div>{{ formData.createTime }}</div>
        </div>
        <div style="flex: 1">
          <div>审核人/日期：{{ outBound.createTime }}</div>
          <div>{{ outBound.extInfo?.createUserName  }}</div>
        </div>
        <div style="flex: 1">
          收货人:{{ formData.linkName }} {{ formData.linkPhone }}
        </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 { getInfoBySourceBizNoAll } from '@/api/wms';
  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.outInDetailRecordRequestList.forEach(j=>{
              j['categoryName']=val.categoryName
              j['categoryModel']=val.categoryModel
              j['specification']=val.specification
              j['categoryCode']=val.categoryCode
              
            })
            this.outBound['outInDetailRecordRequestList'].push(...val.outInDetailRecordRequestList)
          });
        });
        //包装维度
      },
      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>
