<script setup lang="ts">
import ahTable from "@/components/hTable/index.vue";
import { ConditionalType, TableConfig } from "@/components/hTable/hTable";
import { onMounted, ref } 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 { getClassInfo, getSchoolInfo } from "@/api/userCenter";
const ControllerName = "ExamUserInfo";

defineOptions({
  name: ControllerName,
});

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

function searchCallback(data) {}
const table = ref<{ initTable: (config: TableConfig) => void }>();
const tableData: TableConfig = {
  apiUrl: ControllerName,
  selectColumn: false, // 列表选择
  border: false, // 是否显示表格边框
  searchCallback: searchCallback,
  search: {
    // 查询条件
    show: true,
    PageIndex: 0,
    PageSize: 60,
    OrderBy: "Id", // 排序
    OrderByType: 1,
    defaultConditions: [
      {
        FieldName: "UserId",
        FieldValue: props.data[0].userId + "",
      },
    ], // 默认查询条件
    Conditions: [],
  },
  operationColumn: true, // 显示操作按钮
  operationColumnData: [],
  column: {
    // 行数据
    examName: {
      label: "考试名称",
      search: true,
      searchType: ConditionalType.Like, // 搜索类型
      width: "180px",
    },
    // 行数据
    type: {
      label: "考试类型",
      search: true,
      type: "dropdown",
      setting: {},
      width: "150px",
    },
    // 行数据
    grade: {
      label: "考试阶段",
      search: true,
      searchType: ConditionalType.Like, // 搜索类型
      width: "120px",
    }, // 行数据
    testPaperType: {
      label: "试卷类型",
      search: true,
      type: "dropdown",
      setting: {},
      width: "150px",
    },
    语文: {
      label: "语文",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.语文 ?? "--",
    },
    数学: {
      label: "数学",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.数学 ?? "--",
    },
    英语: {
      label: "英语",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.英语 ?? "--",
    },
    物理: {
      label: "物理",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.物理 ?? "--",
    },
    化学: {
      label: "化学",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.化学 ?? "--",
    },
    生物: {
      label: "生物",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.生物 ?? "--",
    },
    政治: {
      label: "政治",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.政治 ?? "--",
    },
    历史: {
      label: "历史",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.历史 ?? "--",
    },
    地理: {
      label: "地理",
      search: false,
      width: "80px",
      custom: (row) => row.subjectDic.地理 ?? "--",
    },
    assignScore: {
      label: "赋分总分",
      search: false,
      width: "80px",
    },
    assignRanking: {
      label: "赋分后的排名",
      search: false,
      width: "120px",
    },
  },
  data: [],
  pageData: {
    total: 0,
  },
  selectRows: [],
};

const showTable = ref(false);
const exam = props.data[0];
onMounted(async () => {
  //初始化数据原
  getClassInfo(exam.classId).then((res) => {
    exam.className = res.data.name;
  });
  getSchoolInfo(exam.schoolId).then((res) => {
    exam.schoolName = res.data.name;
  });
  tableData.column.testPaperType.setting.datasource = (
    await getenum("TestPaperTypeEnum")
  ).data;
  tableData.column.type.setting.datasource = (await getenum("ExamTypeEnum")).data;
  showTable.value = true;
});
</script>

<template>
  <div>
    <div class="p-[10px] text-[1.3rem]">
      <strong>学生{{ exam.userName }}</strong
      >&nbsp; &nbsp; {{ exam.schoolName }} {{ exam.grade }}
      {{ exam.className }}
    </div>
    <ahTable v-if="showTable" ref="table" :tableConfig="tableData" />
  </div>
</template>
