<template>
  <div class="context">
    <div class="panel">
      <div class="panel-body">
        <el-page-header @back="goBack" content="评分结果"/>
        <span class="classNames">{{ title }} {{ ClassStateText }}</span>
        <div class="likeTab">
          <el-button @click="goType('courseEdit')" size="mini" v-if="FinishClass == 2 || FinishClass == 3">人员管理</el-button>
          <el-button @click="goType('actionScore')" size="mini">动作评分</el-button>
          <el-button type="primary" @click="goType('scoreResult')" size="mini">评分结果</el-button>
        </div>
      </div>
    </div>
    <div class="table">
      <el-table
          :data="tableData"
          border
          is-horizontal-resize
          :default-sort="{ prop: 'data', order: 'descending' }"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          class
          ref="multipleTable"
      >
        >
        <el-table-column
            type="index"
            label="排名"
            align="center"
            width="50"
        ></el-table-column>
        <el-table-column
            prop="head"
            label="头像"
            width="75"
            align="center"
            sortable
        >
          <template slot-scope="scope">
            <div class="demo-image__preview" v-if="scope.row.Head">
              <el-image
                  style="width: 25px; height: 25px"
                  :src="scope.row.Head"
                  :preview-src-list="[scope.row.Head]"
              ></el-image>
            </div>
            <img
                src="../assets/img/nav/head.png"
                alt
                v-else
                width="25px"
                height="25px"
            />
          </template>
        </el-table-column>
        <el-table-column
            prop="Name"
            label="会员名"
            width="90"
            sortable
        />
        <el-table-column
            prop="TotalScore"
            label="总分"
            width="90"
            sortable
        >
          <template slot-scope="scope">
            {{scope.row.TotalScore.toFixed(0)}}
          </template>
        </el-table-column>
        <el-table-column
            v-for="item in actionList" :key="item.HAgdId" :label="item.EaName"
            :value="item.HAgdId" :prop="item.HAgdId+''"
        >
          <template slot-scope="scope">
            {{scope.row.DetailScore[item.HAgdId].toFixed(0)}}
          </template>
        </el-table-column>
      </el-table>
      <br/>
      <el-pagination
          background
          :total="pagination.total"
          :page-size="pagination.pageItem"
          @current-change="pageChange"
      />
    </div>
  </div>
</template>

<script>
import Global from "../Global.js";
import {
  AGDetailCurrStdQuery,
  ScoreClassQuery,
} from "../api/getApiRes";

let qs = require("qs");
export default {
  data() {
    return {
      AgId: 0,
      ScoreIsFinish: true,
      tableData: [],
      title: "",
      ClassType: 0,
      PkNum: 0,
      ClassStateText: "",
      FinishClass: 0, //当前上课状态 1已下课 2已上课 3准备上课 FinishClass
      current: getNowDate(),
      ClassName: "",
      cur_page: 1,
      actionList: [],
      pagination: {
        pageItem: 1000,
        pageOptions: pageOptions(),
        total: 1000,
        pageIndex: 1,
      },
      isCollapse: document.body.clientWidth < 1366,
    };
  },
  mounted() {
    this.getActionQuery();
    this.AgId = this.$route.query.AgId;
    this.ClassType = this.$route.query.ClassType;
    this.PkNum = this.$route.query.PkNum;
    this.FinishClass = this.$route.query.FinishClass;
    this.title =
        this.$route.query.ClassName +
        " " +
        this.$route.query.BeginStr +
        "-" +
        this.$route.query.EndStr;
  },
  methods: {
    goBack() {
      this.$router.push({
        path: "/courses",
        query: {},
      });
    },
    //查询动作
    getActionQuery() {
      let that = this;
      let param = {
        token: localStorage.token,
        stdId: this.$route.query.StdId
      };
      let postData = qs.stringify(param);
      AGDetailCurrStdQuery(postData).then((res) => {
        let json = res;
        if (json.Code == 0) {
          if (json.Rs) {
            that.actionList = json.Rs;
            that.getTableQuery();
          } else {
            that.actionList = [];
          }
        } else {
          that.$message.error(json.Memo + " 错误码：" + json.Code);
        }
      });
    },
    // 页面数据查询
    getTableQuery() {
      let that = this;
      let param = {
        token: localStorage.token,
        stdId: this.$route.query.StdId
      };
      that.allTableData = [];
      that.tableData = [];
      that.recordsTotal = 0;
      let postData = qs.stringify(param);
      ScoreClassQuery(postData).then((res) => {
        let json = res;
        if (json.Code == 0) {
          if (json.Rs) {
            that.allTableData = json.Rs;
            that.recordsTotal = json.Rs.length;
          } else {
            that.allTableData = [];
            that.recordsTotal = 0;
          }
          console.log(that.allTableData);
          // 设置分页数据
          that.setPagination();
        } else {
          that.$message.error(json.Memo + " 错误码：" + json.Code);
        }
      });
    },
    // 设置分页数据
    setPagination() {
      // 分页属性
      let that = this;
      that.pagination.total = that.recordsTotal;
      // 默认分页
      that.tableData = that.allTableData.filter((item, index) => {
        return index < that.pagination.pageItem;
      });
    },
    // 每页显示数量
    handleSizeChange() {
      let that = this;
      that.tableData = that.allTableData.filter((item, index) => {
        return index < that.pagination.pageItem;
      });
      that.draw = that.pagination.pageItem;
    },
    // 翻页
    pageChange(pageIndex) {
      let that = this;
      // 获取当前页
      let index = that.pagination.pageItem * (pageIndex - 1);
      // 数据总数
      let nums = that.pagination.pageItem * pageIndex;
      // 容器
      let tables = [];
      for (var i = index; i < nums; i++) {
        if (that.allTableData[i]) {
          tables.push(that.allTableData[i]);
        }
        this.tableData = tables;
      }
      that.start = index * that.draw;
    },
    goType(url) {
      this.$router.push({
        path: '/' + url, query: {
          AgId: this.$route.query.AgId,
          ScoreIsFinish: this.$route.query.ScoreIsFinish,
          StdId: this.$route.query.StdId,
          ClassName: this.$route.query.ClassName,
          BeginStr: this.$route.query.BeginStr,
          EndStr: this.$route.query.EndStr,
          FinishClass: this.$route.query.FinishClass,
          ClassType: this.$route.query.ClassType,
          PkNum: this.$route.query.PkNum,
        }
      });
    },
  },
  watch: {
    $route(to) {
      if (to.name == "scoreResult") {
        this.getActionQuery();
        this.AgId = this.$route.query.AgId;
        this.FinishClass = this.$route.query.FinishClass;
        this.ScoreIsFinish = this.$route.query.ScoreIsFinish,
            this.ClassType = this.$route.query.ClassType;
        this.PkNum = this.$route.query.PkNum;
        this.title =
            this.$route.query.ClassName +
            " " +
            this.$route.query.BeginStr +
            "-" +
            this.$route.query.EndStr;
      }
    },
  },
};
</script>

<style scoped>
@import "../assets/css/panel.css";

.context {
  /* height: 770px; */
  overflow-y: scroll;
  display: block;
  margin: 0 auto;
  background-color: #fff !important;
  padding: 30px;
}

.classNames {
  height: 25px;
  background: #f0f2f5;
  font-family: "Source Han Sans CN";
  font-weight: normal;
  font-size: 16px;
  color: #3799ff;
  border-radius: 250px;
  text-align: center;
  margin-top: 15px;
  margin-bottom: 3px;
  float: left;
  padding-left: 10px;
  padding-right: 10px;
}

.head {
  overflow: hidden;
  display: block;
  margin: 0 auto;
  border-radius: 250px;
}

.panel_control {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
}

.likeTab {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
  padding-top: 10px;
  padding-bottom: 0;
  border-bottom: 1px solid #ccc;
  margin-bottom: 10px;
}

.likeTab button {
  float: left;
  border-radius: 0;
}

.likeTab button.pull-right {
  float: right;
}

/*.panel-body {*/
.panel_control {
  padding: 20px;
  background: #f0f2f5;
}

.change {
  width: 100%;
  overflow: hidden;
  display: block;
  margin: 0 auto;
  padding-top: 10px;
  padding-bottom: 10px;
}

.change button {
  float: left;
}

.change button.pull-right {
  float: right;
}

.lessons {
  padding: 1px 7px;
  border-radius: 250px;
  float: left;
  color: #000;
}

/deep/ .el-transfer-panel__item .el-checkbox__input {
  /*float: left;*/
  left: 10%;
}

/*/deep/ .el-checkbox  .el-checkbox {*/
/*margin-right: 1px;*/
/*}*/
/deep/ .el-checkbox__label span {
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  float: left;
}

.cell em {
  margin-left: 5px;
  margin-right: 5px;
}

/deep/
.el-transfer-panel
.el-transfer-panel__header
.el-checkbox
.el-checkbox__label
span {
  width: 50px;
  float: right;
  right: 0;
}

/*/deep/ .el-table .red-row {*/
/*background: #fb88c1;*/
/*}*/

/*/deep/ .el-table .blue-row {*/
/*background: #7099d0;*/
/*}*/
/*/deep/ .el-table .yellow-row {*/
/*background: #fbe56e;*/
/*}*/

/deep/ .el-table__header .el-table-column--selection .cell .el-checkbox:after {
  content: " 是否网课";
}

/deep/
.el-table__body-wrapper
.el-table-column--selection
.cell
.el-checkbox:after {
  content: " 网课";
}
</style>
