<script setup lang="ts">
import ahTable from "@/components/hTable/index.vue";
import {
  ConditionalType,
  intTableData,
  TableColumnSearch,
  TableConfig,
} from "@/components/hTable/hTable";
import { onMounted, ref, defineOptions } from "vue";
import { fa } from "element-plus/es/locales.mjs";
import { hTableAPI } from "@/api/hTable";
import { getenum } from "@/api/enum";
import { ruleRequired, ruleRequiredNumber } from "@/utils/rules";
import { DeleteExamInfo, ImportExamInfo } from "@/api/exam";
import { entryExamInfo } from "./examFun";
import { ElMessage, ElMessageBox } from "element-plus";
import { average } from "@pureadmin/utils";
const ControllerName = "ClassExamRecord";

defineOptions({
  name: ControllerName,
});

const props = defineProps<{
  data: any;
}>();

function searchCallback(data) {}
const table = ref<{ initTable: (config: TableConfig) => void }>();
const tableData: TableConfig = intTableData({
  apiUrl: `ExamClassInfo`,
  selectColumn: false, // 列表选择
  border: false, // 是否显示表格边框
  searchCallback: searchCallback,
  search: {
    // 查询条件
    show: true,
    PageIndex: 0,
    PageSize: 999,
    OrderByType: 1, // 排序方式
    OrderBy: "Id", // 排序
    defaultConditions: [
      {
        FieldName: "ClassId",
        FieldValue: props.data[0].classId + "",
        ConditionalType: ConditionalType.Equal,
      },
    ], // 默认查询条件
    Conditions: [],
  },
  operationColumn: true, // 显示操作按钮
  operationColumnData: [
    {
      topBtn: false, // 头部按钮
      show: true,
      label: "学生成绩详情",
      btnType: "custom",
      btnStyle: "primary",
      custom: {
        title: "考试学生班级详情", // 弹出框title
        src: "exam/userDetails", // 组件路径
        width: "1600px", // 弹框宽度
        height: "880px", // 弹框高度
      },
    },
  ],
  column: {
    // 行数据
    examName: {
      label: "考试名称",
      width: "150px",
      search: new TableColumnSearch(true),
    },
    type: {
      label: "考试类型",
      width: "80px",
      type: "dropdown",
      search: new TableColumnSearch(true),
    },
    testPaperType: {
      label: "试卷类型",
      width: "80px",
      type: "dropdown",
      search: new TableColumnSearch(true),
    },
    grade: {
      label: "年级",
      width: "90px",
      custom: (row) => row.gradeLevel + row.gradeYear + "届",
      search: new TableColumnSearch(true),
    },

    // onLineCount: {
    //   label: "重本人数",
    //   width: "80px",
    // },
    // onLineRate: {
    //   label: "重本率",
    //   custom: (row) => `${Math.round(row.onLineRate * 100)}%`,
    //   width: "80px",
    // },
    // onLineRanking: {
    //   label: "重本率排名",
    //   width: "100px",
    // },
    maxScore: {
      label: "最高分[赋分]",
      width: "130px",
    },
    minScore: {
      label: "最低分[赋分]",
      width: "130px",
    },
    average: {
      label: "总平均分[赋分]",
      custom: (row) => `${Math.round(row.average)}`,
      width: "130px",
    },
    average1: {
      label: "资源校平均分[赋分]",
      width: "100px",
    },
    averageRank: {
      label: "总平均分排名",
      width: "110px",
    },
    rank: {
      label: "远端平均/资源校平均",
      custom: (row) =>
        `${
          row.baseSchoolScore == 0
            ? "--"
            : Math.round((row.average / row.baseSchoolScore) * 100)
        }%`,
    },
  },
  data: [],
  pageData: {
    total: 0,
  },
  selectRows: [],
});

const showTable = ref(false);
onMounted(async () => {
  //初始化数据原
  // tableData.column.grade.setting.datasource = (await getenum("GradeEnum")).data.map(
  //   (x) => {
  //     return { text: x.text, value: x.text };
  //   }
  // );

  tableData.column.testPaperType.setting.datasource = (
    await getenum("TestPaperTypeEnum")
  ).data;
  tableData.column.type.setting.datasource = (await getenum("ExamTypeEnum")).data;
  showTable.value = true;
});
</script>

<template>
  <div><ahTable v-if="showTable" ref="table" :tableConfig="tableData" /></div>
</template>
