<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="80px">
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable />
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select v-model="queryParams.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 label="已选课目" prop="selectedSubject">
        <el-select v-model="queryParams.selectedSubject" placeholder="请选择已选课目" clearable>
          <el-option v-for="(item, index) in dict.type.art_subject" :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-upload2" size="mini" @click="exportRecord">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="courseSelectionData" stripe>
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="学生姓名" align="center" prop="studentName" />
      <el-table-column label="学号" align="center" prop="studentNumber" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="课程类型" align="center" prop="courseType">
        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.course_type, row.courseType) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="选课时间" align="center" prop="curriculaTime" />
      <el-table-column label="选课状态" align="center" prop="curriculaState">
        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.curricula_state, row.curriculaState) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="已选科目" align="center" prop="selectedSubject">
        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.art_subject, row.selectedSubject) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="已选课程" align="center" prop="selectedCourse">

        <template slot-scope="{ row }">
          <div>{{ selectDictLabel(dict.type.section_type, row.selectedCourse) }}</div>
        </template>
      </el-table-column>
    </el-table>
    <pagination ref="pageBlock" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { classList } from "../../../../../api/smartSchool/gradeWork/courseSelection/taskPublishing";
import { courseSelectionArtList } from "../../../../../api/smartSchool/gradeWork/courseSelection/courseSelection";
export default {
  dicts: ['art_subject', 'curricula_state', 'course_type', 'section_type'],
  data() {
    return {
      queryParams: {
        studentName: '',
        classId: '',
        selectedSubject: '',
        curriculaId: '',
        pageNum: 1,
        pageSize: 10,
      },
      classList: [], // 班级
      courseSelectionData: [],
      loading: false,
      total: 0,
    }
  },
  created() {
    this.getList();
    this.getClassList();
  },
  methods: {
    // 获取列表
    getList() {
      this.queryParams.curriculaId = this.$route.query.id;
      courseSelectionArtList(this.queryParams).then(res => {
        if (res.code == 200) {
          this.courseSelectionData = res.rows;
          this.total = res.total;
          this.loading = false;
        }
      })
    },


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

    //重置
    resetQuery() {
      this.queryParams = {
        studentName: '',
        classId: '',
        selectedSubject: '',
        curriculaId: '',
        pageNum: 1,
        pageSize: 10,
      }
      this.getList();
    },

    //导出
    exportRecord() {
      this.download('/curricula/student/exportYt', {
        ...this.queryParams
      }, `学生艺体选课信息_${new Date().getTime()}.xlsx`)
    }

  }
}

</script>

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