<template>
  <div class="conetentBox">
    <div class="flex-row jcsb aic userBox">
      <div>
        <el-form :inline="true" class="demo-form-inline" size="small">
          <el-form-item label="考核人员" class="form-item">
            <el-select
              v-model="examineId"
              placeholder="请选择"
              @change="userChange"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :label="item.userName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="考核任务" class="form-item">
            <el-select
              v-model="examineTaskId"
              placeholder="请选择"
              @change="getUserList"
            >
              <el-option
                v-for="item in taskList"
                :key="item.id"
                :label="item.taskName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div>考核评分：{{ score }}</div>
    </div>
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane label="组长评估" name="first">
        <div
          v-for="(table, index) in tableData1"
          :key="index"
          style="margin-bottom: 20px"
        >
          <div class="userBox">{{ table[0].reviewCategory }}</div>
          <el-table :data="table" style="width: 100%">
            <el-table-column
              v-for="(header, hIndex) in headers"
              :key="hIndex"
              :label="header.label"
              :prop="header.prop"
              :width="header.width"
            >
            </el-table-column>
            <el-table-column label="评分" prop="score" width="300">
              <template slot-scope="scope">
                <div style="width: 80%; position: relative">
                  <div>
                    <el-slider
                      v-model="scope.row.score"
                      :min="0"
                      :max="10"
                      disabled
                    ></el-slider>
                  </div>
                  <div class="statusText" v-show="scope.row.score == 0">
                    未打分
                  </div>

                  <div class="flex-row jcsb" style="margin-left: 10px">
                    <div>0</div>
                    <div class="scoreText">{{ scope.row.score }}分</div>
                    <div>10</div>
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div>
          <div>
            <div class="userBox">总体评价</div>
            <div>
              <el-input
                type="textarea"
                :autosize="{ minRows: 4 }"
                placeholder="0/300"
                v-model="judgeContent"
                readonly
              >
              </el-input>
            </div>
          </div></div
      ></el-tab-pane>
      <el-tab-pane label="个人自评" name="second">
        <div
          v-for="(table, index) in tableData2"
          :key="index"
          style="margin-bottom: 20px"
        >
          <div class="userBox">表格 {{ table[0].reviewCategory }}</div>
          <el-table :data="table" style="width: 100%">
            <el-table-column
              v-for="(header, hIndex) in headers"
              :key="hIndex"
              :label="header.label"
              :prop="header.prop"
              :width="header.width"
            >
            </el-table-column>
            <el-table-column label="评分" prop="score" width="300">
              <template slot-scope="scope">
                <div style="width: 80%; position: relative">
                  <div>
                    <el-slider
                      v-model="scope.row.score"
                      :min="0"
                      :max="10"
                      disabled
                    ></el-slider>
                  </div>
                  <div class="statusText" v-show="scope.row.score == 0">
                    未打分
                  </div>

                  <div class="flex-row jcsb" style="margin-left: 10px">
                    <div>0</div>
                    <div class="scoreText">{{ scope.row.score }}分</div>
                    <div>10</div>
                  </div>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="自评总结" prop="score" width="300">
              <template slot-scope="scope">
                <div>
                  <el-button
                    v-if="scope.row.remark"
                    @click="handleEdit(scope.row)"
                    type="text"
                    size="mini"
                    icon="el-icon-view"
                    :class="{ hasEdit: !scope.row.remark }"
                    >查看</el-button
                  >
                  <el-button
                    v-if="!scope.row.remark"
                    type="text"
                    size="mini"
                    :class="{ hasEdit: !scope.row.remark }"
                    >未填写</el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div></div
      ></el-tab-pane>
    </el-tabs>
    <el-dialog title="自评总结" :visible.sync="dialogVisible" width="30%">
      <div>
        <el-input
          type="textarea"
          :autosize="{ minRows: 4 }"
          placeholder="0/200"
          v-model="remark"
          readonly
        >
        </el-input>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { taskApi } from "@/utils/api";
export default {
  data() {
    return {
      examineTaskId: "",
      examineId: "",
      userList: [],
      dialogVisible: false,
      remark: "",
      headers: [
        { label: "考核项", prop: "reviewItem", width: 300 },
        { label: "评分标准", prop: "remarks" },
      ],
      // 二维数组，每个子数组代表一个表格的数据
      tableData1: [],
      tableData2: [],
      taskList: [],
      judgeContent: "",
      score: "",
      activeName: "first",
    };
  },
  methods: {
    handleEdit(row) {
      this.dialogVisible = true;
      this.remark = row.remark;
    },

    getTaskList() {
      taskApi
        .getTaskList({
          pageNum: 1,
          pageSize: 100000,
        })
        .then((res) => {
          this.taskList = res.rows;
          this.$nextTick(() => {
            this.examineTaskId = Number(this.$route.query.taskId);
            this.getUserList();
          });
        });
    },
    getUserList() {
      if (!this.examineTaskId) return;
      taskApi
        .getTaskUserList({
          taskId: this.examineTaskId,
          pageNum: 1,
          pageSize: 100000,
        })
        .then((res) => {
          this.userList = res.rows;
          this.$nextTick(() => {
            this.examineId = Number(this.$route.query.examineId);
            this.getSocreDetail(0);
            this.getSocreDetail(1);
          });
        });
    },
    userChange() {
      this.getSocreDetail(0);
      this.getSocreDetail(1);
    },
    // 获取评分详情
    getSocreDetail(type) {
      let param = {
        examineTaskId: this.examineTaskId,
        reviewType: type,
        examineId: this.examineId,
      };
      taskApi.getTaskScoreDetail(param).then((res) => {
        let objData = {};
        res.data.examineConfigDetailVoList.forEach((ele) => {
          if (!objData[ele.reviewCategory]) objData[ele.reviewCategory] = [];
          objData[ele.reviewCategory].push(ele);
        });
        if (type == 0) this.tableData1 = Object.values(objData);
        else this.tableData2 = Object.values(objData);
        this.judgeContent = res.data.examineUser.judgeContent;
        this.score = res.data.examineUser.score;
      });
    },
  },
  created() {
    this.getTaskList();
  },
};
</script>

<style scoped>
.conetentBox {
  padding: 30px;
  background-color: #fff;
  height: 90vh; /* 设置整体高度 */
  overflow: auto;
}
.el-table {
  margin-top: 20px;
}
.userBox {
  margin: 0 0 20px;
  font-size: 16px;
  font-weight: bold;
}
::v-deep .el-slider__runway {
  height: 20px;
  border-radius: 20px;
  margin: 10px !important;
  /* width: 95%; */
}
::v-deep .el-slider__bar {
  height: 20px;
  border-radius: 20px;
  background-color: #ff5722;
}
::v-deep .el-slider__runway.disabled .el-slider__bar {
  background-color: #ff5722;
}
::v-deep .el-slider__bar {
  height: 20px;
  border-radius: 20px;
  background-color: #ff5722;
}
::v-deep .el-slider__button {
  display: none;
}
.scoreText {
  color: #1686d8;
}
::v-deep .el-table th {
  text-align: center;
}

::v-deep .el-table .cell {
  text-align: center;
}
.statusText {
  color: #ff5722;
  position: absolute;
  right: -58px;
  top: 10px;
}
.hasEdit {
  color: #ff5722;
}
::v-deep .el-dialog {
  margin-top: 15% !important;
}

::v-deep .el-tab-pane {
  height: 600px;
  overflow: auto;
}
</style>
