<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 { unqualifiedProduct } 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 unqualifiedProduct(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>`,
      stage: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>工序类型</span>`,
      total: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>数量</span>`,
      updated: `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px'>时间</span>`,
    };
    let bigData: any[] = [];
    res.data.forEach((item: any) => {
      const rowStyle = `
          ${item.state === "0" ? "color: yellow;" : ""} `;
      let row = [
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px;'>${item.workOrderCode}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px;'>${item.materialModel}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px;'>${item.stage}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px;'>${item.total}</span>`,
        `<span style='font-size:${bigScreenData.value.fontSize * 1.5}px;'>${item.updated}</span>`,
      ];
      bigData.push(row);
    });

    config.value = {
      header: Object.values(dicts),
      data: bigData,
      index: true,
      rowNum: 10,
      // columnWidth: [50, 130, 160, 160, 120, 160, 120],
      columnWidth: [50],
      align: ["center"],
      carousel: "single",
    };
  }
};

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