<template>
  <div class="collapseStyle" :height="tableHeight + 100">
    <el-scrollbar
      v-loading="loading"
      style="border: 1px solid #ebeef5"
      :height="tableHeight"
    >
      <el-collapse accordion v-model="activeNames">
        <el-collapse-item
          v-for="(item, index) in materialsData"
          :key="item"
          :title="item.operationName"
          :name="index"
        >
          <el-table :data="item.children" border>
            <el-table-column prop="formName" label="表格名称" />
            <el-table-column prop="formType" label="表格类型">
              <template #default="scope">
                {{ dictS.getLableByValue("excel_type", scope.row.formType) }}
              </template>
            </el-table-column>
            <el-table-column label="操作" prop="operation">
              <template #default="{ row }">
                <el-button
                  style="font-size: 18px; color: black"
                  link
                  @click="showExcelDialog(row)"
                  >查看</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"
    />
    <el-dialog
      v-model="excelDialogVisible"
      title="查看表单"
      :append-to-body="true"
      :destroy-on-close="true"
      width="70%"
      height="80%"
      @close="excelDialogVisible = true"
    >
      <TaskExcel v-if="excelDialogVisible" :data="excelData" />
    </el-dialog>
  </div>
</template>

<script setup>
import { useProcessStore } from "@/store";
import { excel } from "@/api/process/traceability";
import { useDictionaryStore } from "@/store";
import TaskExcel from "./taskExcel.vue";
const dictS = useDictionaryStore();
const store = useProcessStore();
const activeNames = ref([0]);
const updataShow = ref(false);
const updateTitle = ref("表格数据");
const page = ref(1);
const limit = ref(10);
const total = ref(10);
const materialsData = ref([]);
const tableHeight = ref(null);
const loading = ref(false);
//  查看excel相关
const excelDialogVisible = ref(false);
const showExcelDialog = async (row) => {
  excelData.value = row;
  excelDialogVisible.value = true;
};
const excelData = ref(null);
const getPagination = async () => {
  loading.value = true;
  try {
    const { data } = await excel({
      pageNo: page.value,
      pageSize: limit.value,
      seqNo: store.useSeqNo,
      workOrderCode: store.odersData.workOrderCode,
    });
    // total.value = data.totalCount;
    materialsData.value = data;
  } catch {
  } finally {
    loading.value = false;
  }
};
//动态控制高度
const setTableHeight = () => {
  tableHeight.value =
    Number(document.getElementById("tabBox").offsetHeight) - 110;
};
onMounted(() => {
  getPagination();
  setTableHeight();
});
</script>

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