<template>
  <div class="app-container">
    <el-form :model="queryForm" size="small" :inline="true" label-width="80px">
      <el-form-item prop="studentsName" label="学生姓名">
        <el-input clearable v-model="queryForm.studentName" placeholder="学生姓名"></el-input>
      </el-form-item>
      <el-form-item prop="classId" label="班级">
        <el-select v-model="queryForm.classId" placeholder="请选择学生班级" clearable>
          <el-option v-for="(item, index) in classList" :key="index" :label="item.className"
            :value="item.classId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="selectedMajor" label="已选专业">
        <el-select v-model="queryForm.selectedMajor" placeholder="请选择学生已选专业" clearable>
          <el-option v-for="(item, index) in dict.type.specialty" :key="index" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <!-- 表单信息 -->
    <el-table v-loading="loading" :data="studentsList" stripe>
      <el-table-column label="班级" prop="className" align="center" width="150px" />
      <el-table-column label="学生姓名" prop="studentName" align="center" width="150px" />
      <el-table-column label="学号" prop="studentNumber" align="center" />
      <el-table-column label="身份证号" prop="idCard" width="300px" align="center" />
      <el-table-column label="课程类型" prop="courseType" align="center">
        <!-- 1春季选课 2夏季选课 3艺体 -->
        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.course_type, row.courseType) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="选课时间" prop="curriculaTime" align="center" />
      <el-table-column label="已选专业" prop="selectedMajor" align="center">
        <template slot-scope="{ row }">
          <div>{{ selectDictLabels(dict.type.specialty, row.selectedMajor) }}</div>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryForm.pageNum" :limit.sync="queryForm.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>

import { classList } from "../../../../../api/smartSchool/gradeWork/courseSelection/taskPublishing";
import { courseSelectionSpringList } from "../../../../../api/smartSchool/gradeWork/courseSelection/courseSelection";

export default {
  name: "springView",
  dicts: ['specialty', 'course_type'],
  data() {
    return {
      majorList: [],
      classList: [],
      queryForm: { // 查询表单
        curriculaId: '',
        studentName: '',
        classId: '',
        selectedMajor: '',
        pageNum: 1,
        pageSize: 10
      },
      loading: false, // 遮罩层
      total: 0,
      studentsList: [], // 信息列表

    }
  },
  mounted() {
    this.getClassList()
    this.getList();
  },
  methods: {
    //获取班级下拉框数据
    getClassList() {
      let grade = this.$route.query.grade
      classList(grade).then(res => {
        if (res.code == 200) {
          this.classList = res.data
        }
      })
    },

    // 获取列表
    getList() {
      this.loading = true
      this.queryForm.curriculaId = this.$route.query.id
      courseSelectionSpringList({ ...this.queryForm }).then(res => {
        if (res.code == 200) {
          this.studentsList = res.rows
          this.total = res.total
          this.loading = false
        }
      })
    },

    // 重置按钮
    resetQuery() {
      this.queryForm = {
        curriculaId: '',
        studentName: '',
        classId: '',
        selectedMajor: '',
        pageNum: 1,
        pageSize: 10
      };
      this.getList()
    },

    // 导出
    handleExport() {
      this.download('/curricula/student/exportCj', {
        ...this.queryForm
      }, `学生春季选课信息_${new Date().getTime()}.xlsx`)
    }

  }
}
</script>

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