<template>
  <el-scrollbar class="collapseStyle" :height="tableHeight + 100">
    <el-scrollbar style="border: 1px solid #ebeef5" :height="tableHeight">
      <el-collapse accordion v-model="activeNames">
        <el-collapse-item
          v-for="(item, index) in materialsData"
          :key="index"
          :title="item.opName"
          :name="index"
        >
          <el-table :data="item.children" border>
            <el-table-column prop="checkName" label="点检项名称" />
            <el-table-column prop="checkCode" label="点检项编码" />
            <el-table-column prop="content" label="内容" />
            <el-table-column prop="result" label="结果">
              <template #default="scope">
                {{ scope.row.result == "1" ? "合格" : "不合格" }}
              </template>
            </el-table-column>
            <el-table-column prop="standard" label="标准值" />
            <el-table-column prop="upper" label="上限值" />
            <el-table-column prop="lower" label="下限值" />
            <el-table-column prop="created" label="录入时间" />
          </el-table>
        </el-collapse-item>
      </el-collapse>
      <Empty v-if="materialsData.length < 1" />
    </el-scrollbar>
    <Pagination
      position="right"
      :page="page"
      :limit="limit"
      :total="total"
      @pagination="getPagination"
    />
  </el-scrollbar>
</template>

<script lang="ts" setup>
import { useProcessStore } from "@/store";
import { checkRecordInfo } from "@/api/process/traceability";
import { useDictionaryStore } from "@/store";
const dictS = useDictionaryStore();
const activeNames = ref([0]);
const store = useProcessStore();
const page = ref(1);
const limit = ref(10);
const total = ref(10);
const materialsData = ref([]);
const tableHeight = ref(null);
const getPagination = async () => {
  const { data } = await checkRecordInfo({
    pageNo: page.value,
    pageSize: limit.value,
    seqNo: store.useSeqNo,
    workOrderCode: store.odersData.workOrderCode,
  });
  total.value = data.totalCount;
  materialsData.value = data.records;
};
//动态控制高度
const setTableHeight = () => {
  tableHeight.value =
    Number(document.getElementById("tabBox").offsetHeight) - 110;
};
onMounted(() => {
  getPagination();
  setTableHeight();
  window.addEventListener("resize", setTableHeight);
});
onUnmounted(() => {
  window.removeEventListener("resize", setTableHeight);
});
</script>

<style lang="scss" scoped></style>
