<template>
  <div class="main-content">
  <div class="bgColor" v-if="modelValue" @click.stop="close">
    <div class="body">
      <div class="header">
        <div class="text">报告预览</div>
        <div class="delete">
          <el-button
            style="margin-right: 10px"
            type="primary"
            size="small"
            class="btn"
            v-print="'#print'"
            >打印</el-button
          >
          <span style="padding: 20px" @click="close">X</span>
        </div>
      </div>
      <div class="box">
        <el-scrollbar>
          <div id="print">
            <div class="tableInfo">
              <div style="page-break-after: always">
                <div class="title" style="text-align: center" v-if="props.detail.reportType==1">质量日报({{props.detail.generationDate}})</div>
                <div class="title" style="text-align: center" v-if="props.detail.reportType==2">质量月报({{props.detail.generationDate}})</div>

                <div class="tableTitle">模块筛选情况</div>
                <table>
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th id="lineId" colspan="2">
                        <span style="float: left; margin-top: 10px"
                          >产品型号<br />检验批号</span
                        >
                        <span style="float: right; margin-top: 10px"
                          >筛选项目</span
                        >
                      </th>
                      <th>封前 目检</th>
                      <th>高温 贮存</th>
                      <th>温度 循环</th>
                      <th>随机 振动</th>
                      <th>电测 试</th>
                      <th>老炼</th>
                      <th>最终电测试</th>
                      <th>外部 目检</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr
                      v-for="(item, index) in moduleScreeningData"
                      :key="index"
                    >
                      <td>{{ item.id }}</td>
                      <td>{{ item.model }} {{ item.batch }}</td>
                      <td>
                        <div>数量</div>
                        <div>剔除数</div>
                      </td>
                      <td>
                        <div>{{ item.preInspection.quantity }}</div>
                        <div>{{ item.preInspection.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.highTempStorage.quantity }}</div>
                        <div>{{ item.highTempStorage.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.tempCycle.quantity }}</div>
                        <div>{{ item.tempCycle.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.randomVibration.quantity }}</div>
                        <div>{{ item.randomVibration.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.electricalTest.quantity }}</div>
                        <div>{{ item.electricalTest.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.aging.quantity }}</div>
                        <div>{{ item.aging.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.finalElectricalTest.quantity }}</div>
                        <div>{{ item.finalElectricalTest.rejects }}</div>
                      </td>
                      <td>
                        <div>{{ item.externalInspection.quantity }}</div>
                        <div>{{ item.externalInspection.rejects }}</div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <div style="page-break-after: always">
                <div class="tableTitle" style="margin-top: 100px">
                  质量一致性检验
                </div>
                <div class="info">
                  <div class="text">产品型号：</div>
                  <div class="text">产品批次：</div>
                  <div class="text">报告日期：2025年03月23日</div>
                </div>
                <table>
                  <thead>
                    <tr>
                      <th>序号</th>
                      <th>产品型号</th>
                      <th>批号</th>
                      <th>质量一致性检验情况</th>
                      <th>留样数量</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr
                      v-for="(item, index) in consistencyTestData"
                      :key="index"
                    >
                      <td>{{ item.id }}</td>
                      <td>{{ item.model }}</td>
                      <td>{{ item.batch }}</td>
                      <td>{{ item.inspectionStatus }}</td>
                      <td>{{ item.sampleQuantity }}</td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <div class="tableTitle" style="margin-top: 100px">
                产品代验收情况
              </div>
              <div class="info">
                <div class="text">产品型号：</div>
                <div class="text">产品批次：</div>
                <div class="text">报告日期：2025年03月23日</div>
              </div>
              <table>
                <thead>
                  <tr>
                    <th>序号</th>
                    <th>产品型号</th>
                    <th>批号</th>
                    <th>数量</th>
                  </tr>
                </thead>
                <tbody>
                  <tr
                    v-for="(item, index) in productAcceptanceData"
                    :key="index"
                  >
                    <td>{{ item.id }}</td>
                    <td>{{ item.model }}</td>
                    <td>{{ item.batch }}</td>
                    <td>{{ item.sampleQuantity }}</td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
  </div>
  </div>
</template>

<script setup>
import {
  moduleScreeningData,
  consistencyTestData,
  productAcceptanceData,
} from "@/api/statistic/reportMockData.ts";
onMounted(async () => {
  await getQualityTableData(props.detail.value);

});
const getQualityTableData=(data)=>{

}
const props = defineProps({
  modelValue: {
    type: [Boolean],
  },
  detail: {
    type: [Object],
   },
});
const emits = defineEmits(["update:modelValue"]);
const close = () => {
  emits("update:modelValue", false);
};
// import html2canvas from "html2canvas";

// const downloadPNG = async () => {
//   try {
//     const canvas = await html2canvas(document.getElementById("print"));
//     const imgData = canvas.toDataURL("image/png");
//     const downloadLink = document.createElement("a");
//     downloadLink.href = imgData;
//     downloadLink.download = "download.png";
//     downloadLink.click();
//   } catch (error) {
//     console.error("Error generating PNG:", error);
//   }
// };
</script>

<style lang="scss" scoped>
#lineId {
  background: #f2f2f2
    url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=)
    no-repeat 100% center;
}
@media print {
  #print {
    position: absolute; /* 或 absolute, fixed, 根据需要调整 */
    top: 20px; /* 调整顶部位置 */
    margin: 0; /* 重置边距 */
    width: 700px;
  }
}
table {
  width: 100%;
  border-collapse: collapse; /* 合并表格边框 */
}
th,
td {
  border: 1px solid rgba(0, 0, 0, 0.3); /* 设置所有单元格的边框 */
  padding: 8px;
  text-align: left;
}
th {
  background-color: #f2f2f2; /* 设置表头的背景颜色 */
}

.bgColor {
  position: fixed;
  width: 100vw;
  height: 100vh;
  z-index: 99999;
  background-color: rgba(0, 0, 0, 0.3);
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  left: 0;
  .body {
    width: 80%;
    height: 85vh;
    background-color: white;
    display: flex;
    flex-direction: column;
    padding: 20px;
    .header {
      width: 100%;
      height: 40px;
      display: flex;
      padding-bottom: 10px;
      justify-content: space-between;
      border-bottom: 1px solid rgba(0, 0, 0, 0.3);
    }
    .box {
      height: calc(100% - 40px);
    }
  }
}
.tableInfo {
  width: 100%;
  height: 60px;

  .tableTitle {
    margin: 10px 0;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 20px;
    text-align: center;
  }

  .title {
    margin: 10px 0;
    font-size: 20px;
    font-weight: 600;
  }
  .info {
    display: flex;
    padding: 0 20px;
    justify-content: space-between;
  }
}
</style>
