<template>
  <div class="collapseStyle">
    <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.operationName"
          :name="index"
        >
          <el-table :data="item.children" border>
            <el-table-column prop="fileName" label="文件名" />
            <el-table-column prop="created" label="录入时间" />
            <el-table-column label="操作" fixed="right" width="200">
              <template #default="scope">
                <el-button
                  link
                  v-if="scope.row.writeData !== ''"
                  class="btnText"
                  type="primary"
                  @click="downLoad(scope.row.filePath, scope.row.fileName)"
                >
                  下载
                </el-button>
              </template>
            </el-table-column>
          </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"
    />
  </div>
</template>

<script setup>
import { useProcessStore } from "@/store";
import { file } from "@/api/process/traceability";
import { useDictionaryStore } from "@/store";
import { downloadFile } from "@/utils/downLoad";
const dictS = useDictionaryStore();
const activeNames = ref([0]);
const store = useProcessStore();
const downLoad = async (url, name) => {
  let names = name.split(".")[0];
  let resUrl = url;
  await downloadFile(resUrl, names);
};
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 file({
    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) - 70;
};
onMounted(() => {
  getPagination();
  setTableHeight();
});
</script>

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