<template>
  <div
    class="pb_content"
    style="
      background: unset;
      overflow: auto;
      padding: 20px;
      margin: 0;
      box-sizing: border-box;
    "
  >
    <div
      style="
        position: absolute;
        width: 95%;
        top: 0;
        height: 100%;
        overflow: auto;
        left: 50%;
        transform: translateX(-50%);
      "
    >
      <div
        class="pb_content_body"
        style="
          background: #fff;
          padding: 0px 25px;
          box-sizing: border-box;
          margin: 10px auto 0;
        "
      >
        <div class="pb_head">
          <span>评价管理</span>
          <!-- <span>备注：教师可以根据课程、班级条件筛选学生并查看该学生信息</span> -->
          <span
            @click="
              goTo('/courseGM?userid=' + userid + '&oid=' + oid + '&org=' + org)
            "
            >项目管理</span
          >
        </div>
        <div class="student_head">
          <div class="student_search">
            <div>项目筛选</div>
            <el-select v-model="groupA" @change="search">
              <el-option value="0" label="我的课程"></el-option>
              <el-option value="1" label="他人课程"></el-option>
            </el-select>
            <el-input
              v-model="cn"
              placeholder="筛选项目名称"
              @input="search"
            ></el-input>
          </div>
        </div>
      </div>
      <div class="pb_content_body" style="margin:0px auto">
        <div class="student_table">
          <el-table
            ref="table"
            :data="tableData1"
            border
            :height="tableHeight"
            :fit="true"
            v-loading="isLoading"
            style="width: 100%"
            :header-cell-style="{ background: '#f1f1f1', fontSize: '17px' }"
            :row-class-name="tableRowClassName"
          >
            <el-table-column
              prop="title"
              label="项目"
              min-width="30"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="uname"
              label="创建人"
              min-width="30"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="time"
              label="时间"
              min-width="20"
              align="center"
            ></el-table-column>
            <el-table-column label="操作" min-width="30">
              <template slot-scope="scope">
                <!-- <el-button
                type="primary"
                size="small"
                @click="
                  goTo(
                    '/worksDetail?cid=' +
                      scope.row.courseId +
                      '&userid=' +
                      userid +
                      '&oid=' +
                      oid
                  )
                "
                >查看学生</el-button>-->
                <!-- <el-button type="primary" size="small" @click="getWorkData(scope.row)">生成报告</el-button> -->
                <el-button
                  type="primary"
                  size="small"
                  class="btnClass"
                  @click="getWorkData(scope.row)"
                  >查看课程</el-button
                >
                <el-button
                  type="primary"
                  size="small"
                  class="btnClass"
                  @click="getStudnet(scope.row)"
                  >查看报告</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="student_page">
          <el-pagination
            background
            layout="prev, pager, next"
            :page-size="10"
            :total="total"
            v-if="page"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!-- <el-dialog
      title="查看报告"
      :visible.sync="dialogVisible"
      :append-to-body="true"
      width="750px"
      :before-close="handleClose"
      class="dialog_diy"
    >
      <div>
        <div class="a_addBox">
          <WorkDate :dataJson="dataJson"></WorkDate>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>-->
    <WorkDate
      :dataJson="dataJson"
      :uid="userid"
      :cid="dataJson.courseId"
      :ooid="oid"
      v-if="dialogVisible"
      class="workdates"
    ></WorkDate>
    <div class="cancelbox" v-if="dialogVisible">
      <el-button @click="dialogVisibleBao = true" type="primary" size="small" class="btnClass"
        >自定义导出</el-button
      >
      <el-button @click="cancel" type="primary" size="small" class="btnClass">返回</el-button>
      <!-- <el-button
        type="primary"
        size="small"
        @click="
          goTo(
            '/worksDetail?cid=' +
              dataJson.courseId +
              '&userid=' +
              userid +
              '&oid=' +
              oid
          )
        "
        >查看作业</el-button
      >-->
    </div>
    <el-dialog
      title="自定义导出报告"
      :visible.sync="dialogVisibleBao"
      :append-to-body="true"
      width="550px"
      :before-close="handleClose"
      class="dialog_diy r_diy"
    >
      <div>
        <div>
          <Report :cid="dataJson.courseId"></Report>
        </div>
      </div>
      <span slot="footer" class="dialog-footer"> </span>
    </el-dialog>
    <el-dialog
      title="选择学生"
      :visible.sync="signDialog"
      width="500px"
      :before-close="handleClose"
      class="dialog_diy check_diy"
    >
      <div>
        <div class="student_search" style="margin-bottom: 10px">
          <div>筛选</div>
          <div style="display: flex; width: 90%">
            <el-select
              class="r_select"
              v-model="uname"
              placeholder="请选择学生"
              filterable
              @change="searchWork2"
            >
              <el-option label="所有学生" value></el-option>
              <el-option
                v-for="item in userAarray"
                :key="item.userid"
                :label="item.username"
                :value="item.userid"
              ></el-option>
            </el-select>
          </div>
        </div>
        <div>
          <el-table
            v-loading="isLoading2"
            ref="table"
            :data="res2"
            border
            :height="400"
            :fit="true"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            :header-cell-style="{ background: 'rgb(238,238,238)' }"
          >
            <el-table-column
              prop="sName"
              label="姓名"
              min-width="20"
            ></el-table-column>
            <el-table-column label="操作" min-width="20">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="small"
                  class="btnClass"
                  @click="getReport(scope.row)"
                  >查看报告</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div style="margin-top: 10px" class="student_page">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-size="10"
              :total="total2"
              @current-change="handleCurrentChange2"
            ></el-pagination>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="signDialog = false" class="cancel_button"
          >关闭</el-button
        >
      </span>
    </el-dialog>
    <div class="report_box" v-if="reportVisible">
      <studentReport
        :checkCourse="checkCourse"
        :checkStudent="checkStudent"
        :oid="oid"
      ></studentReport>
    </div>
    <div class="cancelbox" v-if="reportVisible">
      <el-button @click="cancelR" type="primary" size="small" class="btnClass">返回</el-button>
    </div>
  </div>
</template>

<script>
import WorkDate from "./components/workDataGM";
import Report from "./components/reportGM";
import studentReport from "./components/studentReportGM";
export default {
  components: {
    WorkDate,
    Report,
    studentReport,
  },
  data() {
    return {
      tableHeight: "500px",
      isLoading: false,
      formLabelWidth: "100px",
      tableData1: [],
      subject: "",
      sClass: "",
      subjectJuri: [],
      projectJuri: [],
      grade: [],
      projectchoose: "",
      page: 1,
      total: 0,
      groupA: "0",
      cn: "",
      userid: this.$route.query.userid,
      org: this.$route.query.org,
      oid: this.$route.query.oid,
      dialogVisible: false,
      dialogVisibleBao: false,
      dataJson: {},
      signDialog: false,
      isLoading2: false,
      page2: 1,
      total2: 0,
      res2: [],
      checkCourse: "",
      reportVisible: false,
      checkStudent: "",
      userAarray: [],
      uname: "",
    };
  },
  mounted() {
    this.$nextTick(function () {
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 200;
      if (this.tableHeight <= 530) {
        this.tableHeight = 530;
      }
      // 监听窗口大小变化
      let self = this;
      window.onresize = function () {
        self.tableHeight =
          window.innerHeight - self.$refs.table.$el.offsetTop - 200;
        if (self.tableHeight <= 530) {
          self.tableHeight = 530;
        }
      };
    });
  },
  methods: {
    goTo(path) {
      this.$router.push(path);
    },
    tableRowClassName({ row, rowIndex }) {
      if ((rowIndex + 1) % 2 === 0) {
        return "even_row";
      } else {
        return "";
      }
    },
    handleClose(done) {
      done();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getProject();
    },
    handleCurrentChange2(val) {
      this.page2 = val;
      this.getStudnet();
    },
    //获取班级列表
    getClass() {
      this.isLoading = true;
      let params = {
        cu: "",
        cn: this.sClass,
        page: this.page,
      };
      this.ajax
        .get(this.$store.state.api + "selectClass", params)
        .then((res) => {
          this.isLoading = false;
          this.grade = res.data[0];
        })
        .catch((err) => {
          this.isLoading = false;
          console.error(err);
        });
    },
    getProject() {
      this.isLoading = true;
      let params = {
        type: this.groupA,
        uid: this.userid,
        oid: this.oid,
        cn: this.cn,
        page: this.page,
      };
      this.ajax
        .get(this.$store.state.api + "getProject", params)
        .then((res) => {
          this.isLoading = false;
          this.total = res.data[0].length > 0 ? res.data[0][0].num : 0;
          this.tableData1 = res.data[0];
        })
        .catch((err) => {
          this.isLoading = false;
          console.error(err);
        });
    },
    search() {
      this.page = 1;
      this.getProject();
    },
    getWorkData(res) {
      this.dataJson = res;
      this.dialogVisible = true;
    },
    cancel() {
      this.dataJson = "";
      this.dialogVisible = false;
    },
    cancelR() {
      this.checkStudent = "";
      this.reportVisible = false;
      this.signDialog = true;
    },
    searchWork2() {
      (this.page2 = 1), this.getStudnet();
    },
    getStudnet(row) {
      //获取作业
      this.signDialog = true;
      this.isLoading2 = true;
      this.checkCourse = row ? row.courseId : this.checkCourse;
      let params = {
        cid: this.checkCourse,
        uname: this.uname,
        stage: "",
        task: "",
        page: this.page2,
      };
      this.ajax
        .get(this.$store.state.api + "getCourseWorks3", params)
        .then((res) => {
          this.isLoading2 = false;
          this.total2 = res.data[0].length > 0 ? res.data[0][0].num : 0;
          this.res2 = res.data[0];
          this.getCourseDetail();
        })
        .catch((err) => {
          this.isLoading2 = false;
          console.error(err);
        });
    },
    getCourseDetail() {
      let params = {
        cid: this.checkCourse,
      };
      this.ajax
        .get(this.$store.state.api + "getCourseWorksReport", params)
        .then((res) => {
          this.userAarray = res.data[1];
        })
        .catch((err) => {
          console.error(err);
        });
    },
    getReport(row) {
      this.checkStudent = row.userid;
      this.reportVisible = true;
      this.signDialog = false;
    },
  },
  created() {
    this.page = 1;
    // this.getClass();
    // this.getGroup();
    this.getProject();
  },
};
</script>

<style scoped>
.pb_head > span:nth-child(2) {
  font-size: 16px;
  cursor: pointer;
  margin-left: 10px;
  /* color: #ab582f; */
  color: #5c549f;
}
.pb_head {
  margin: 0 !important;
  width: 100% !important;
}
.student_page {
  margin-top: 10px;
}
.student_head {
  margin-top: 10px;
  padding-bottom: 15px;
  display: flex;
  justify-content: space-between;
}
.student_search {
  display: flex;
}
.student_search > div:nth-child(1) {
  line-height: 35px;
  font-size: 14px;
  min-width: 60px;
}
.student_search >>> .el-input__inner {
  width: 190px;
  height: 35px;
  margin-left: 10px;
}
.student_table >>> .el-table--border td {
  border-right: 0px !important;
}

.student_page {
  margin-top: 10px;
}

.student_table >>> .el-table,
.student_table >>> .el-table__body-wrapper {
  height: auto !important;
}

.el-table >>> .even_row {
  background-color: #f1f1f1 !important;
}

.dialog_diy >>> .el-dialog__header {
  padding: 9px 20px 10px;
  background: #32455b !important;
}
.dialog_diy >>> .el-dialog__title {
  color: #fff;
  font-size: 15px;
}
.dialog_diy >>> .el-dialog__headerbtn {
  top: 14px;
}
.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  color: #fff;
}
.check_diy >>> .el-dialog__body {
  padding-bottom: 0;
}
.dialog_diy >>> .el-dialog__body,
.dialog_diy >>> .el-dialog__footer {
  background: #fafafa;
}
.r_diy >>> .el-dialog__footer {
  padding: 0;
}
.a_addBox {
  height: 570px;
  overflow: auto;
}

.workdates {
  height: 100%;
  position: absolute;
  top: 0;
  background: #fff;
  overflow: auto;
  z-index: 1;
  width: 95%;
  left: 50%;
  transform: translateX(-50%);
  padding: 20px;
  box-sizing: border-box;
}
.cancelbox {
  position: absolute;
  z-index: 2;
  left: 50%;
  width: 95%;
  transform: translateX(-50%);
  display: flex;
  justify-content: flex-end;
  padding: 0 90px 0px 0px;
  box-sizing: border-box;
}

.report_box {
  height: 100%;
  position: absolute;
  top: 0;
  /* background: #fff; */
  background: rgb(231, 242, 252);
  overflow: auto;
  z-index: 1;
  width: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 20px;
  box-sizing: border-box;
}

.student_page
  >>> .el-pagination.is-background
  .el-pager
  li:not(.disabled).active {
  background-color: #5c549f;
}
.student_page
  >>> .el-pagination.is-background
  .el-pager
  li:not(.disabled):hover {
  color: #5c549f;
}

.student_search >>> .el-select .el-input.is-focus .el-input__inner {
  border-color: #5c549f;
}
.student_search >>> .el-select .el-input__inner:focus {
  border-color: #5c549f;
}
.el-select-dropdown__item.selected {
  color: #5c549f;
}

.student_search.is-active >>> .el-input__inner,
.student_search >>> .el-input__inner:focus {
  border-color: #5c549f;
}

.btnClass {
  background: #8681b7;
  border-color: #8681b7;
}

.cancel_button:focus,
.cancel_button:hover {
  color: rgb(92, 84, 159);
  border-color: #5c549f;
  background-color: #dbd7ff;
}
</style>
