<template>
  <div class="screen-common-component">
    <ScreenComHeader :module-id="moduleId" title="检验任务" />
    <dv-scroll-board
      :config="config"
      style="width: 100%; height: calc(100% - 32px)"
    />
  </div>
</template>

<script lang="ts" setup>
import ScreenComHeader from "@/views/screens/configs/screenComHeader.vue";
import { todayInspectionDetail } from "@/api/screens";
const bigScreenData: any = inject("bigScreenData");

const config = ref({});

const props = defineProps({
  moduleId: {
    type: String,
    required: true,
  },
});

const loadData = async () => {
  let res = await todayInspectionDetail(4);
  if (res.data.length > 0) {
    let dicts = {
      workOrderCode: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>生产批号</span>`,
      materialModel: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>物料型号</span>`,
      isDestruction: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>破坏性检验</span>`,
      checkType: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>检验类型</span>`,
      total: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>数量</span>`,
    };
    let bigData: any[] = [];
    res.data.forEach((item: any) => {
      const rowStyle = `
          ${item.isDestruction ? "color: #99f6cc;" : ""} `;
      let row = [
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px; ${rowStyle};display: inline-block;width: 70%;text-align: left;'>${item.workOrderCode}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px; ${rowStyle}'>${item.materialModel}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px; ${rowStyle};display: inline-block;width: 70%;text-align: center;'>${item.isDestruction === 0 ? "否" : "是"}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px; ${rowStyle}'>${item.checkType === "1" ? "首件检验" : "过程检验"}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px; ${rowStyle}'>${item.total}</span>`,
      ];
      bigData.push(row);
    });

    config.value = {
      headerBGC: "rgba(134,158,218,0.5)",
      oddRowBGC: "rgba(134,158,218,0.0)",
      evenRowBGC: "rgba(134,158,218,0.0)",
      header: Object.values(dicts),
      data: bigData,
      rowNum: 10,
      // columnWidth: [50, 130, 160, 160, 120, 160, 120],
      // columnWidth: [120, 160, 120, 120, 120],
      align: ["center"],
      carousel: "single",
    };
  }
};

onMounted(async () => {
  loadData();
  const timer = setInterval(loadData, 60 * 5 * 1000);
  // 组件卸载时清除定时器
  onUnmounted(() => clearInterval(timer));
});
</script>
