<template>
  <div class="student-management">
    <div class="part-box-head">
      <div class="part-box-head-left"><h1>成绩查询</h1></div>
    </div>
    <div class="part-filter">
      <div class="part-filter-form">
        <el-form ref="form" :model="form" :rules="rules" inline>
          <el-form-item label="批次名称" prop="examId">
            <ExamSelect v-model="form.examId" />
          </el-form-item>
          <el-form-item label="场次代码">
            <ActivitySelect
              :examId="form.examId"
              v-model="form.examActivityId"
            />
          </el-form-item>
          <el-form-item label="科目">
            <CourseSelect :examId="form.examId" v-model="form.courseCode" />
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model.trim="form.name"></el-input>
          </el-form-item>
          <el-form-item label="证件号">
            <el-input v-model.trim="form.identity"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleCurrentChange(0)"
              >查询</el-button
            >

            <el-dropdown
              class="mx-2"
              split-button
              type="primary"
              @command="exportMarkResult"
            >
              导出
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="simple">简化版</el-dropdown-item>
                <el-dropdown-item command="standard">标准版</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <el-table :data="tableData">
      <el-table-column type="selection" width="42" />
      <el-table-column width="100" label="场次代码">
        <span slot-scope="scope">{{ scope.row.examActivityCode }}</span>
      </el-table-column>
      <el-table-column width="100" label="姓名">
        <span slot-scope="scope">{{ scope.row.name }}</span>
      </el-table-column>
      <el-table-column width="200" label="证件号">
        <span slot-scope="scope">{{ scope.row.identity }}</span>
      </el-table-column>
      <el-table-column width="100" label="科目代码">
        <span slot-scope="scope">{{ scope.row.courseCode }}</span>
      </el-table-column>
      <el-table-column width="100" label="科目名称">
        <span slot-scope="scope">{{ scope.row.courseName }}</span>
      </el-table-column>
      <el-table-column width="100" label="考场代码">
        <span slot-scope="scope">{{ scope.row.roomCode }}</span>
      </el-table-column>
      <el-table-column width="100" label="考场名称">
        <span slot-scope="scope">{{ scope.row.roomName }}</span>
      </el-table-column>
      <el-table-column width="100" label="年级">
        <span slot-scope="scope">{{ scope.row.grade }}</span>
      </el-table-column>
      <el-table-column width="100" label="教学班级">
        <span slot-scope="scope">{{ scope.row.classNo }}</span>
      </el-table-column>
      <el-table-column width="100" label="缺考">
        <span slot-scope="scope">{{ scope.row.examAbsent }}</span>
      </el-table-column>
      <el-table-column width="100" label="违纪次数">
        <span slot-scope="scope">{{ scope.row.breachCount }}</span>
      </el-table-column>
      <el-table-column width="100" label="考试次数">
        <span slot-scope="scope">{{ scope.row.examCount }}</span>
      </el-table-column>
      <el-table-column width="100" label="客观分">
        <span slot-scope="scope">{{ scope.row.objectiveScore }}</span>
      </el-table-column>
      <el-table-column width="100" label="主观分">
        <span slot-scope="scope">{{ scope.row.subjectiveScore }}</span>
      </el-table-column>
      <el-table-column width="100" label="总分">
        <span slot-scope="scope">{{ scope.row.sumScore }}</span>
      </el-table-column>
    </el-table>
    <div class="part-page">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :page-sizes="[10, 20, 50, 100, 200, 300]"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </div>
  </div>
</template>

<script>
import { searchMarkResult, exportMarkResult } from "@/api/examwork-markresult";
export default {
  name: "MarkResultManagement",
  data() {
    return {
      form: {
        examId: "",
        examActivityId: "",
        courseCode: "",
        name: "",
        identity: "",
      },
      rules: {
        examId: [{ required: true, message: "批次必选" }],
      },
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
    };
  },
  async created() {},
  methods: {
    async searchForm() {
      try {
        const valid = await this.$refs.form.validate();
        if (!valid) return;
      } catch (error) {
        console.log(error);
        return;
      }
      const res = await searchMarkResult({
        examId: this.form.examId,
        examActivityId: this.form.examActivityId,
        identity: this.form.identity,
        courseCode: this.form.courseCode,
        name: this.form.name,
        pageNumber: this.currentPage,
        pageSize: this.pageSize,
      });
      this.tableData = res.data.data.records;
      this.total = res.data.data.total;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.searchForm();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.searchForm();
    },
    async exportMarkResult(type) {
      try {
        const valid = await this.$refs.form.validate();
        if (!valid) return;
      } catch (error) {
        console.log(error);
        return;
      }
      await exportMarkResult({
        examId: this.form.examId,
        examActivityId: this.form.examActivityId,
        identity: this.form.identity,
        courseCode: this.form.courseCode,
        name: this.form.name,
        type,
      });
      this.$notify({ title: "导入任务已成功启动", type: "success" });
    },
  },
};
</script>

<style></style>
