<script setup lang="ts">
import { ElMessageBox } from "element-plus";
import {
  consistencyTestData,
  moduleScreeningData,
  productAcceptanceData,
} from "@/api/statistic/reportMockData";
import { getQualityTableData } from "@/api/statistic/reportData";

const detail = ref<any>({});

const dialogVisible = ref(false);
const tableData = ref([]);
const openPrintDialog = (row) => {
  dialogVisible.value = true;
  console.info("openPrintDialog", row);
  getQualityTableData(row).then((data) => {
    tableData.value = data.data;
  });
  //   在这里调接口
  detail.value = row;
};

const handleClose = (done: () => void) => {};
defineExpose({
  openPrintDialog: openPrintDialog,
});
</script>

<template>
  <el-dialog
    v-model="dialogVisible"
    width="1000"
    append-to-body
    align-center
    :close-on-click-modal="false"
  >
    <div>
      <el-scrollbar class="scroll-container">
        <div id="print">
          <div class="tableInfo">
            <div style="page-break-after: always">
              <div
                class="title"
                style="text-align: center"
                v-if="detail.reportType == 1"
              >
                质量日报({{ detail.generationDate }})
              </div>
              <div
                class="title"
                style="text-align: center"
                v-if="detail.reportType == 2"
              >
                质量月报({{ detail.generationDate }})
              </div>
              <div v-for="(item, index) in tableData.filterList" :key="index">
              <div class="tableTitle">{{item.materialCategory}}筛选情况</div>
              <table  style="margin-top:10px">
                <thead>
                  <tr>
                    <th style="width: 60px">序号</th>

                    <th id="lineId" colspan="2">
                      <span class="left-text">产品型号/检验批号</span>
                      <span class="right-text">筛选项目</span>
                      <svg xmlns="http://www.w3.org/2000/svg" class="xiexian">
                        <path
                          d="M 0 80 L 250 80 L 0 0 Z"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                        <path
                          d="M 0 80 L 250 80"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                        <!-- 左边 -->
                        <path
                          d="M 250 80 L 0 0"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                      </svg>
                    </th>
                    <th  v-for="(operationName) in item.operationNames">{{operationName}}</th>
                  </tr>
<!--                  <tr>
                    <th class="vertical-text" v-for="(itemCheck, index) in item.checkNameList">{{itemCheck}}</th>
                  </tr>-->
                </thead>
                <tbody v-for="(itemCheck, index) in item.checkList" :key="index">
                  <tr  >
                    <td rowspan="2" style="text-align: center" >{{ index+1}}</td>
                    <td rowspan="2" style="text-align: center;width:180px" >{{ itemCheck.materialModel}}&nbsp;{{ itemCheck.checkCode}}</td>
                    <td  style="text-align: center;width:70px" >数量</td>
                    <td  style="text-align: center;" v-for="(num) in itemCheck.numList" >{{num}}</td>
                  </tr>
                  <tr>
                    <td style="text-align: center">剔除</td>
                    <td  style="text-align: center;" v-for="(remove) in itemCheck.removeList">{{remove}}</td>

                  </tr>
                </tbody>
              </table>
            </div>
            </div>

            <div style="page-break-after: always">
              <div class="tableTitle" style="margin-top: 100px">
                销售信息反馈
              </div>
              <table>
                <thead>
                  <tr>
                    <th rowspan="2">日期</th>
                    <th colspan="3">返回产品</th>
                    <th rowspan="2">用户</th>
                    <th rowspan="2">反馈内容</th>
                    <th rowspan="2">原因</th>
                    <th rowspan="2">纠正措施</th>
                    <th rowspan="2">备注</th>
                  </tr>
                  <tr>
                    <th>型号</th>
                    <th>批次</th>
                    <th>数量</th>
                  </tr>
                </thead>
                <tbody>

                  <tr v-for="(item, index) in tableData.salesReportList" :key="index">
                    <td style="text-align: center">{{ item.created }}</td>
                    <td style="text-align: center">{{ item.materialModel }}</td>
                    <td style="text-align: center">{{ item.checkCode }}</td>
                    <td style="text-align: center">{{ item.num }}</td>
                    <td style="text-align: center">{{ item.customer }}</td>
                    <td style="text-align: center">{{ item.remark1 }}</td>
                    <td style="text-align: center">{{ item.remark3 }}</td>
                    <td style="text-align: center">{{ item.remark4 }}</td>
                    <td style="text-align: center">{{ item.remark }}</td>
                  </tr>
                </tbody>
              </table>
            </div>
            <div style="page-break-after: always; margin-top: 50px">
              <div class="tableTitle">成品率统计</div>
              <div v-for="(item, index) in tableData.finishListList" style="margin-bottom: 30px">
              <div><div class="div-header" style="padding-left: 10px">{{item.productLineName}}</div> <div class="div-header" style="text-align: center">产品类别：{{item.materialCategory}}</div> <div class="div-header" style="text-align: right">统计周期：{{ detail.generationDate }}</div>  </div>
              <table >
                <thead >

                  <tr >
                    <th id="lineId" colspan="2" >
                      <span class="right-text">工序</span>
                      <span class="left-text">产品分类</span>
                      <svg xmlns="http://www.w3.org/2000/svg" class="xiexian">
                        <path
                          d="M 0 80 L 250 80 L 0 0 Z"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                        <path
                          d="M 0 80 L 250 80"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                        <!-- 左边 -->
                        <path
                          d="M 250 80 L 0 0"
                          stroke="rgba(0, 0, 0, 0.3)"
                          stroke-width="1"
                          fill="none"
                        />
                      </svg>
                    </th>
                    <th   v-for="(itemOperation) in item.operationNameList">{{itemOperation}}</th>
                  </tr>

                </thead>
                <tbody v-for="(model,modelIndex) in item.modelList">
                  <tr>
                    <td style="width: 160px;text-align: center" rowspan="3">{{model.materialModel}}</td>
                    <td style="width: 90px;text-align: center">目标%</td>
                    <td v-for="(modelItem) in model.targetList" style="text-align: center">{{modelItem}}</td>
                  </tr>
                  <tr>
                    <td style="width: 90px;text-align: center">实际%</td>
                    <td v-for="(modelItem) in model.actualList" style="text-align: center">{{modelItem}}</td>
                  </tr>
                  <tr>
                    <td style="width: 90px;text-align: center">增量%</td>
                    <td v-for="(modelItem) in model.incrementList" style="text-align: center">{{modelItem}}</td>
                  </tr>
                  <tr v-if="modelIndex===item.num-1">
                    <td colspan="2" style="text-align: center">备注</td>
                    <td :colspan="item.operationNum" v-html="item.remark" style="text-align: center;padding-top: 20px;padding-bottom: 20px"></td>
                  </tr>
                </tbody>
              </table>
              </div>
            </div>
            <div class="tableTitle" style="margin-top: 50px">入库</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 tableData.instockReportList" :key="index">
                  <td style="text-align: center">{{ index+1 }}</td>
                  <td style="text-align: center">{{ item.materialModel }}</td>
                  <td style="text-align: center">{{ item.workOrderCode }}</td>
                  <td style="text-align: center">{{ item.num }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <template #header>
      <div class="dialog-header">
        <div>报告预览</div>
<!--        <el-button
          type="primary"
          size="small"
          @click="dialogVisible = false"
          v-print="'#print'"
        >
          打印
        </el-button>-->
      </div>
    </template>
  </el-dialog>
</template>

<style scoped lang="scss">
.dialog-header {
  display: flex;
  justify-content: start;
  align-items: center;
  gap: 20px;
}

.scroll-container {
  height: calc(100vh - 200px);
}

#lineId {
  width: 250px;
  height: 81px;
  position: relative;
  padding: 0;
  //background: #f2f2f2
  //  url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=)
  //  no-repeat 100% center;

  .xiexian {
    position: absolute;
    left: 0;
    top: 0;
  }

  .left-text {
    position: absolute;
    left: 0;
    bottom: 0;
    line-height: 40px;
    width: 70%;
    text-align: start;
    padding-left: 10px;
  }

  .right-text {
    position: absolute;
    right: 0;
    top: 0;
    line-height: 40px;
    width: 70%;
    text-align: end;
    padding-right: 10px;
  }
}
@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 {
  text-align: center;
  background-color: #f2f2f2; /* 设置表头的背景颜色 */
}
.div-header{
  float: left;
  width: 33%;
  font-size: 15px;
  height: 40px;
  line-height: 40px;

}
.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;
  }
}

.slash {
  position: relative;
}
.slash::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-left: 1px solid #444;
  transform: rotate(45deg);
  transform-origin: 0 0;
}
.split-line {
  border-bottom: 1px solid #444;
  padding: 4px 0;
}

//上下分割成两行的
.top-and-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  border: 0;
  .content {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .middle-line {
    width: 100%;
    height: 1px;
    background-color: rgba(0, 0, 0, 0.3);
  }
}

.vertical-text {
  writing-mode: vertical-rl; /* 竖排从右到左 */
  text-orientation: upright; /* 保持字符直立 */
}
</style>
