<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="学生姓名" prop="stuName">
        <el-input
          v-model="queryParams.stuName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生性别" prop="stuGender">
        <el-select
          v-model="queryParams.stuGender"
          placeholder="内容类型"
          clearable
          style="width: 125px">
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生专业" prop="stuMajor">
        <el-input
          v-model="queryParams.stuMajor"
          placeholder="请输入学生专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生手机号" prop="stuNumber">
        <el-input
          v-model="queryParams.stuNumber"
          placeholder="请输入学生手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校及院系名称" prop="schoolName">
        <el-input
          v-model="queryParams.schoolName"
          placeholder="请输入学校及院系名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大赛类型" prop="">
        <el-select
          v-model="queryParams.competitionType"
          placeholder="大赛类型"
          clearable
          style="width: 125px">
          <el-option
            v-for="dict in dict.type.competition_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="所属赛区" prop="division">
        <el-input
          v-model="queryParams.division"
          placeholder="请输入所属赛区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="团队名称" prop="teamName">
        <el-input
          v-model="queryParams.teamName"
          placeholder="请输入团队名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教师名称" prop="teachName">
        <el-input
          v-model="queryParams.teachName"
          placeholder="请输入团队名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大赛名称" prop="competitionName">
        <el-input
          v-model="queryParams.competitionName"
          placeholder="请输入团队名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置刷新</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hit:hitRegistrationStudentInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hit:hitRegistrationStudentInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table @expand-change="getTeachInfo" style="width: 100%; table-layout: auto" v-loading="loading" :data="HitRegistrationStudentInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-descriptions title="学生信息" style="margin-left: 100px">
            <el-descriptions-item label="比赛名称">{{props.row.competitionName}}</el-descriptions-item>
            <el-descriptions-item label="学生姓名">{{props.row.stuName}}</el-descriptions-item>
            <el-descriptions-item label="学生性别">
              <dict-tag :options="dict.type.sys_user_sex" :value="props.row.stuGender"/>
            </el-descriptions-item>
            <el-descriptions-item label="学生专业">{{props.row.stuMajor}}</el-descriptions-item>
            <el-descriptions-item label="学生手机号">{{props.row.stuNumber}}</el-descriptions-item>
            <el-descriptions-item label="学校及院系名称">{{props.row.schoolName}}</el-descriptions-item>
            <el-descriptions-item label="所属赛区">{{props.row.division}}</el-descriptions-item>
            <el-descriptions-item label="团队名称">{{props.row.teamName}}</el-descriptions-item>
          </el-descriptions>
          <el-descriptions :title="'领队教师' + (index + 1)"  v-for="(item, index) in leaderTeachList" style="margin-left: 100px" v-show="leaderTeachList !== null && leaderTeachList.length !== 0">
            <el-descriptions-item label="教师姓名">{{item.teacherName}}</el-descriptions-item>
            <el-descriptions-item label="教师职务">{{item.teacherJob}}</el-descriptions-item>
            <el-descriptions-item label="教师手机号">{{item.teacherNumber}}</el-descriptions-item>
            <el-descriptions-item label="教师邮箱">{{item.teacherEmail}}</el-descriptions-item>
            <el-descriptions-item label="教师所在系及专业">{{item.teacherSchool}}</el-descriptions-item>
          </el-descriptions>
          <el-descriptions :title="'指导教师' + (index + 1)"  v-for="(item, index) in guideTeachList" style="margin-left: 100px" v-show="guideTeachList !== null && guideTeachList.length !== 0">
            <el-descriptions-item label="教师姓名">{{item.teacherName}}</el-descriptions-item>
            <el-descriptions-item label="教师职务">{{item.teacherJob}}</el-descriptions-item>
            <el-descriptions-item label="教师手机号">{{item.teacherNumber}}</el-descriptions-item>
            <el-descriptions-item label="教师邮箱">{{item.teacherEmail}}</el-descriptions-item>
            <el-descriptions-item label="教师所在系及专业">{{item.teacherSchool}}</el-descriptions-item>
          </el-descriptions>
        </template>
      </el-table-column>
      <el-table-column label="比赛名称" align="center" prop="competitionName" />
      <el-table-column label="学生姓名" align="center" prop="stuName" />
      <el-table-column label="学生性别" align="center" prop="stuGender" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.stuGender"/>
        </template>
      </el-table-column>
      <el-table-column label="学生专业" align="center" prop="stuMajor" />
      <el-table-column label="学生手机号" align="center" prop="stuNumber" />
      <el-table-column label="学校及院系名称" align="center" prop="schoolName" width="120px"/>
      <el-table-column label="所属赛区" align="center" prop="division" />
      <el-table-column label="团队名称" align="center" prop="teamName" />
      <el-table-column label="领队教师" align="center" prop="leaderNames" />
      <el-table-column label="指导教师" align="center" prop="guideNames" width="120px" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hit:hitRegistrationStudentInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listHitRegistrationStudentInfo,
  getHitRegistrationStudentInfo,
  delHitRegistrationStudentInfo,
  addHitRegistrationStudentInfo,
  updateHitRegistrationStudentInfo,
  getTeachInfoByIds
} from "@/api/hit/registrationStudentInfo";

export default {
  name: "HitRegistrationStudentInfo",
  dicts: ['sys_user_sex', 'competition_type'],
  data() {
    return {
      leaderTeachList:[],
      guideTeachList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报名信息表格数据
      HitRegistrationStudentInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        competitionName: null,
        stuName: null,
        stuGender: null,
        stuMajor: null,
        stuNumber: null,
        schoolName: null,
        division: null,
        teamName: null,
        leaderIds: null,
        guideIds: null,
        teachName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        competitionId: [
          { required: true, message: "大赛ID不能为空", trigger: "blur" }
        ],
        stuName: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" }
        ],
        stuGender: [
          { required: true, message: "学生性别不能为空", trigger: "blur" }
        ],
        stuMajor: [
          { required: true, message: "学生专业不能为空", trigger: "blur" }
        ],
        stuNumber: [
          { required: true, message: "学生手机号不能为空", trigger: "blur" }
        ],
        schoolName: [
          { required: true, message: "学校及院系名称不能为空", trigger: "blur" }
        ],
        division: [
          { required: true, message: "所属赛区不能为空", trigger: "blur" }
        ],
        delFlag: [
          { required: true, message: "逻辑删除0未删除1真删除不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报名信息列表 */
    getList() {
      this.loading = true;
      listHitRegistrationStudentInfo(this.queryParams).then(response => {
        this.HitRegistrationStudentInfoList = response.rows;
        this.HitRegistrationStudentInfoList.forEach(item => {
          if (item.leaderNames !== null) item.leaderNames = item.leaderNames.join(",");
          if (item.guideNames !== null) item.guideNames = item.guideNames.join(",");
        })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        competitionId: null,
        stuName: null,
        stuGender: null,
        stuMajor: null,
        stuNumber: null,
        schoolName: null,
        division: null,
        teamName: null,
        leaderIds: null,
        guideIds: null,
        remark: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报名信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHitRegistrationStudentInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报名信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHitRegistrationStudentInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHitRegistrationStudentInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除报名信息编号为"' + ids + '"的数据项？').then(function() {
        return delHitRegistrationStudentInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hit/hitRegistrationStudentInfo/export', {
        ...this.queryParams
      }, `HitRegistrationStudentInfo_${new Date().getTime()}.xlsx`)
    },
    getTeachInfo(row){
      if (row.leaderIds !== null && row.leaderIds.length !== 0){
        getTeachInfoByIds(row.leaderIds).then(res => {
          this.leaderTeachList = res.data
        })
      }
      if (row.guideIds !== null && row.guideIds.length !== 0){
        getTeachInfoByIds(row.guideIds).then(res => {
          this.guideTeachList = res.data
        })
      }
    },
  }
};
</script>

<style scoped lang="scss">
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
