<template>
  <div>
    <div class="evaBox" v-for="(item, index) in mrEvaList" :key="index">
      <div class="sub_title">
        <div class="yuan">
          <img src="../../../../assets/icon/myReport/gang.png" alt="" />
        </div>
        <div>{{ item.title }}</div>
      </div>
      <el-table :data="item.course" border style="width: 100%" stripe>
        <el-table-column
          prop="title"
          label="项目"
          align="center"
          min-width="15%"
        >
        </el-table-column>
        <el-table-column label="分类" align="center" min-width="20%">
          <template slot-scope="scope">
            {{ scope.row.typename ? scope.row.typename : "-" }}
          </template>
        </el-table-column>
        <el-table-column label="班级" align="center" min-width="20%">
          <template slot-scope="scope">
            {{ scope.row.cName ? scope.row.cName : "-" }}
          </template>
        </el-table-column>
        <el-table-column label="选择合成报告" align="center" min-width="25%">
          <template slot-scope="scope">
            <input
              type="checkbox"
              :id="scope.row.courseId"
              :value="scope.row.title"
              @change="isChooseStudent(scope.row.courseId, index)"
            />
          </template>
        </el-table-column>
      </el-table>
      <el-button
        class="lookReport"
        type="primary"
        size="small"
        @click="getReport(index)"
        >报告查看</el-button
      >
    </div>
  </div>
</template>

<script>
export default {
  props: ["mrEvaList"],
  data() {
    return {
      checkboxList: [],
    };
  },
  watch: {
    mrEvaList: {
      immediate: true,
      deep: true,
      handler(newValue, oldValue) {
        this.checkboxList = newValue;
        this.$forceUpdate();
      },
    },
  },
  methods: {
    getReport(i) {
      if (this.checkboxList[i].isChoose.length > 0) {
        this.$emit("getEvaCid", this.checkboxList[i]);
      }else{
        this.$message.error("请选择至少一项课程！");
      }
    },
    isChooseStudent(id, i) {
      if (this.checkboxList[i].isChoose.indexOf(id) != -1) {
        this.checkboxList[i].isChoose.splice(
          this.checkboxList[i].isChoose.indexOf(id),
          1
        );
      } else {
        this.checkboxList[i].isChoose.push(id);
      }
      this.$forceUpdate();
    },
  },
};
</script>

<style scoped>
.evaBox {
  width: 100%;
  padding: 20px 0 0 0;
}
.el-table >>> .has-gutter > tr th {
  background: #fafafa;
}
.sub_title {
  display: flex;
  color: #3050c2;
  font-weight: bold;
  align-items: center;
  height: 40px;
  width: 200px;
  flex-direction: row;
  flex-wrap: nowrap;
  margin: 0;
  justify-content: flex-start;
  width: 100%;
}
.yuan {
  width: 40px;
  height: 20px;
}
.yuan > img {
  width: 100%;
  height: 100%;
}
.lookReport {
  margin: 10px 0 0 0;
  float: right;
}
</style>