<template>
  <div>
    <div class="personPage">
      <div
        style="width: 100%;display: flex;justify-content: flex-end;align-items: center;"
      >
        <!-- <el-select v-model="teas" multiple placeholder="请选择">
          <el-option
            v-for="item in TeaList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select> -->
        <!-- <div style="margin-left: 10px;">
          <el-button type="primary" @click="remindExamine" size="mini"
            >提醒</el-button
          >
        </div> -->
      </div>
      <el-table
        :data="tableData"
        class="scoTab"
        v-loading="tabLoading"
        style="width: 100%"
      >
        <el-table-column type="index" align="center" label="序号" width="180">
        </el-table-column>
        <el-table-column prop="username" align="center" label="教师姓名">
        </el-table-column>
        <el-table-column
          prop="tea"
          show-overflow-tooltip
          :filters="TeachingOptions"
          :filter-method="filterTea"
          align="center"
          label="教研室"
          width="180"
        >
        </el-table-column>
        <el-table-column
          :filters="[
            { text: '已完成', value: '已完成' },
            { text: '未完成', value: '未完成' }
          ]"
          :filter-method="filterExa"
          :filter-multiple="false"
          prop="state"
          align="center"
          label="考核进度"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.step == scope.row.allStep">√</div>
            <div v-else>{{ scope.row.step }}/{{ scope.row.allStep }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="evaSca"
          :sortable="true"
          :sort-method="sortEvaMethod"
          align="center"
          label="自评总分"
        >
        </el-table-column>
        <el-table-column align="center" label="一级指标评分" >
          <template slot-scope="scope">
            <div class= "scoreBox" v-for="item, index in scope.row.json" :key="index">
              <el-tooltip :content="item.name" placement="top" effect="dark">
                <span>{{ item.name }}</span>
              </el-tooltip>
               :<span>{{ scoreChildren(item.children) }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="cogSco"
          :sortable="true"
          :sort-method="sortCogMethod"
          align="center"
          label="考核总分"
        >
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <div style="display: flex;justify-content: center;">
              <div class="TabBtn" @click="lookScore(scope.row)">评分</div>
              <div class="TabBtn" @click="withdraw(scope.row.id)">退回</div>
              <div class="TabBtn" @click="recordBtn(scope.row.id)">记录</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 点击评分 -->
    <el-dialog
      title=""
      :visible.sync="diaSco"
      :append-to-body="true"
      width="95%"
      :before-close="handleClose"
      class="dialog_diy"
    >
      <div v-loading="digLoading" class="testPersonExamine">
        <div class="testTit">
          <div class="teaLis">
            <div
              class="teal"
              @click="cutPage(2)"
              :class="[digType == 2 ? 'Tbor' : '']"
            >
              专任教师
            </div>
            <div
              class="teal"
              @click="cutPage(1)"
              :class="[digType == 1 ? 'Tbor' : '']"
            >
              班主任考核
            </div>
          </div>
        </div>
        <div class="digTop">
          <div
            style="width: 230px;display: flex;justify-content: space-between;align-items: center;margin-left: 15px;"
          >
            <div class="digUsernameCss">{{ digUsername }}</div>
            <div
              v-if="tableData.length > 0"
              style="display: flex;justify-content: space-between;width: 150px;"
            >
              <div>
                <el-button type="primary" size="mini" @click="upTea"
                  >上一个</el-button
                >
              </div>
              <div>
                <el-button type="primary" size="mini" @click="nextTea"
                  >下一个</el-button
                >
              </div>
            </div>
          </div>
          <div
            style="width: 650px;display: flex;justify-content: space-between;margin-left: 6px;"
          >
            <div style="display: flex;">
              <span>教研室:</span
              ><el-tooltip
                class="item"
                effect="dark"
                :content="disTeaClass"
                placement="top"
              >
                <div
                  style="width: 100px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"
                >
                  {{ disTeaClass }}
                </div>
              </el-tooltip>
            </div>
            <div>审核进度:{{ computedStep }}/{{ twoTarget }}</div>
            <div>自评分数:{{ DigSelfSco }}</div>
            <div>考核分数:{{ computedSco }}</div>
          </div>
        </div>
        <div style="height:100%;overflow: auto;padding-bottom: 80px;">
          <div class="sBox_table">
            <div class="table_title">
              <div style="width: 150px;">一级指标</div>
              <div style="width: 160px;">二级指标</div>
              <div style="width: 160px;">评价方法</div>
              <div style="width: 110px;">分值</div>
              <div style="width: 110px;">自评</div>
              <div style="flex: 1;">自评概述</div>
              <div style="width: 250px;">数据来源</div>
              <div style="width: 110px;">认定</div>
              <div style="flex: 1;">认定概述</div>
            </div>
            <div
              style="height: 100%;overflow: auto;overflow-x: hidden;border-left: 1px #ccc solid;"
            >
              <div
                class="table_Content"
                v-for="item in PageBaseData"
                :key="item.id"
              >
                <div class="twoCol">
                  <div class="ColTit">{{ item.name }}</div>
                  <div class="ColCon">
                    <div class="twoCon" v-for="k in item.children" :key="k.id">
                      <div>{{ k.name }}</div>
                      <div style="padding: 10px;box-sizing: border-box;">
                        {{ k.evaMethod }}
                      </div>
                      <div>{{ k.score }}</div>
                      <div>
                        {{ k.sco1 }}
                      </div>
                      <div>
                        <div class="tArea">
                          {{ k.selfSummary }}
                        </div>
                      </div>
                      <div>
                        <div v-if="!k.testid.test.length">/</div>
                        <div v-else style="padding-top: 10px;">
                          <!-- {{ reverseString(k.testid.test) }} -->
                          <div
                            v-for="(item2, index) in k.testid.test"
                            :key="item2.courseId"
                            class="orgData"
                          >
                            <div @click="lookUserPrize(item2.courseId)">
                              {{ item2.title }}:{{ item2.num }}份
                            </div>
                          </div>
                        </div>
                      </div>
                      <div style="display: flex;justify-content: center;">
                        <div v-if="tableData.length > 0" class="ScoreStep">
                          <el-input
                            :style="{
                              color: k.sco1 == k.sco2 ? '#000' : 'red'
                            }"
                            @blur="
                              saveTab(
                                k.id,
                                k.sco2 > k.score
                                  ? (k.sco2 = k.score)
                                  : '' || k.sco2 < 0
                                  ? (k.sco2 = '')
                                  : ''
                              )
                            "
                            v-model.number="k.sco2"
                            v-stopMousewheel
                          ></el-input>
                        </div>
                      </div>
                      <div style="display: flex;justify-content: center;">
                        <textarea
                          v-if="tableData.length > 0"
                          @blur="saveTab(k.id)"
                          v-model.trim="k.cogSum"
                        />
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 查看数据来源 -->
    <el-dialog
      title=""
      :visible.sync="diaIframe"
      :append-to-body="true"
      width="95%"
      :before-close="handleClose2"
      class="dialog_diy"
    >
      <div style="height: 100%;">
        <iframe
          ref="viframe"
          style="width: 100%; height: 99%; border: none"
          :src="ifmUrl"
        ></iframe>
      </div>
    </el-dialog>

    <!-- 提醒弹框 -->
    <shareBox
      :remDig.sync="remDig"
      :pType="pType"
      :TeaList="TeaList"
    ></shareBox>

    <el-dialog
      title="评分记录"
      :visible.sync="recordVisible"
      class="recordDig"
      :before-close="recordHandleClose"
    >
      <div>
        <el-table border height="500px" :data="RecordList" style="width: 100%">
          <el-table-column align="center" type="index" label="序号" width="80">
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            prop="username"
            label="教师姓名"
          >
          </el-table-column>
          <el-table-column align="center" prop="dateTime" label="评分时间">
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>

    <!-- <el-dialog
      title="提醒"
      :visible.sync="remDig"
      :append-to-body="true"
      width="600"
      :before-close="handleClose3"
      class="dialog_remDig"
    >
      <div v-loading="digLoading" style="height: 100%;padding: 15px;">
        <div class="remFlex" style="align-items: center;">
          <div class="remFlexTit">填写范围:</div>
          <el-select v-model="teas" multiple placeholder="请选择">
            <el-option
              v-for="item in TeaList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              @change="remindExamine"
            >
            </el-option>
          </el-select>
        </div>
        <div class="remFlex">
          <div class="remFlexTit">需提交人数:</div>
          <div>{{ remindNum }}</div>
        </div>
        <div class="remFlex">
          <div class="remFlexTit">未完成人数:</div>
          <div>{{ remindList.length }}</div>
        </div>
        <div class="remFlex">
          <div class="remFlexTit">需提交人数:</div>
          <div class="remFlex" style="flex-wrap: wrap;">
            <div
              v-for="(item, index) in remindList"
              :key="index"
              style="margin-right: 2px;"
            >
              {{ item }},
            </div>
          </div>
        </div>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import shareBox from "./shareBox/index";
export default {
  directives: {
    stopMousewheel: {
      inserted: function(el) {
        const ele = el.tagName === 'INPUT' ? el : el.querySelector('input');
        ele.addEventListener("mousewheel", () => {
          ele.blur();
        });
      }
    }
  },
  props: {
    pType: {
      //2专任教师 1班主任
      type: Number,
      default: 0
    },
    teacherName: {
      type: String,
      default: ""
    }
  },
  components: {
    shareBox
  },
  data() {
    return {
      digType: 2,
      diaSco: false,
      diaIframe: false,
      recordVisible: false,
      RecordList: [],
      ifmUrl: false,
      PageBaseData: [],
      digUserid: "", //用户id
      digTid: "", //表单id
      cutTeaNum: 0, //第几位教师
      disTeaClass: "", //教研室
      digLoading: false,
      DigSelfSco: 0,
      digUsername: "",
      twoTarget: 0,
      computedScoData: 0,
      computedStepData: 0,
      computedCogSCoData: 0,
      TeaList: [],
      tabLoading: false,
      userid: this.$route.query.userid, //用户id
      oid: this.$route.query.oid, //学校id
      org: this.$route.query.org, //组织id
      tableData: [],
      TeachingOptions: [],
      PageBaseDataTwo: [],
      remDig: false
    };
  },
  watch: {
    pType(newVal, oldVal) {
      this.getData();
    },
    digType(newVal, oldVal) {
      this.getDataDig();
    }
  },
  computed: {
    computedSco() {
      this.computedScoData = 0; // 初始化一个局部变量来存储累加结果

      // 定义一个函数来执行累加操作
      const accumulateSco = () => {
        if (this.PageBaseData) {
          // 确保 this.PageBaseData 存在
          this.PageBaseData.forEach(e => {
            // 假设 e.children 是一个可以迭代的数组或类似结构
            e.children.forEach(i => {
              if (!!i.sco2) {
                this.computedScoData += i.sco2 * 1;
              }
            });
          });
          this.computedScoData = this.computedScoData.toFixed(2);
        }
        return this.computedScoData; // 返回累加结果
      };

      // 立即调用函数并返回结果
      return accumulateSco();
    },

    computedStep() {
      this.computedStepData = 0; // 初始化一个局部变量来存储累加结果

      // 定义一个函数来执行累加操作
      const accumulateSco2 = () => {
        if (this.PageBaseData) {
          this.PageBaseData.forEach(e => {
            e.children.forEach(i => {
              if (!!i.sco2) {
                this.computedStepData++;
              }
            });
          });
        }
        return this.computedStepData; // 返回累加结果
      };

      // 立即调用函数并返回结果
      return accumulateSco2();
    },

    scoreChildren() {
      return function(children){
        let score = 0;
        children.forEach(item => {
          if (item.sco2 && parseFloat(item.sco2) > 0) {
            score += parseFloat(item.sco2);
          }
        });
        return score;
      }
    },
  },
  mounted() {
    this.getData();
    this.getTeaList();
  },
  methods: {
    // 禁用滚轮事件
    handleWheel(event) {
      event.preventDefault();
    },
    // 获取页面数据
    getData() {
      this.tabLoading = true;
      let params = {
        oid: this.oid,
        org: this.org,
        type: this.pType,
        tname: this.teacherName
      };
      // console.log(params);
      this.ajax
        .get(this.$store.state.api + "selectTestExaminePersonData", params)
        .then(res => {
          let data = res.data[0];

          data.forEach(e => {
            e.json = JSON.parse(e.json);
          });

          data.forEach(e => {
            e.evaSca = 0;
            e.cogSco = 0;
            e.step = 0;
            e.allStep = 0;

            e.json.forEach(i => {
              i.children.forEach(k => {
                e.evaSca = e.evaSca + k.sco1 * 1;
                e.cogSco = e.cogSco + k.sco2 * 1;
                e.allStep++;
                if (!!k.sco2 * 1) {
                  e.step++;
                }
              });
            });
          });

          data.forEach(e => {
            if (e.step == e.allStep) {
              e.state = "已完成";
            } else {
              e.state = "未完成";
            }
            if (!e.tea) {
              e.tea = "";
            }
            e.evaSca = e.evaSca.toFixed(2);
            e.cogSco = e.cogSco.toFixed(2);
          });
          this.tableData = data;
          this.tabLoading = false;
        })
        .catch(error => {
          this.tabLoading = false;
          console.log(error);
        });
    },
    // 点击评分
    lookScore(val) {
      this.digLoading = true;
      // console.log("valvalvalval", val);
      // 重置自评分,二级指标个数
      this.DigSelfSco = 0;
      this.twoTarget = 0;

      this.digType = this.pType;

      this.digTid = val.id;
      this.diaSco = true;
      this.digUserid = val.userid;
      this.disTeaClass = val.tea;
      this.cutPerson();
      this.getPageBase();
    },
    // 获取教研室
    getTeaList() {
      let params = {
        oid: this.oid
      };
      this.ajax
        .get(this.$store.state.api + "selectTeacherOfficeBySchool", params)
        .then(res => {
          // return console.log("this.TeachingOptions", res.data[0]);
          let data = res.data[0];
          let dataCopy = [];

          data.forEach(e => {
            if(e.parentid == '6'){
              let a = {};
              a.value = e.name;
              a.text = e.name;
              dataCopy.push(a);
            }
          });
          data.forEach(e => {
            if(e.parentid == '6'){
              let a = {};
              a.id = e.id;
              a.name = e.name;
              this.TeaList.push(a);
            }
          });

          this.TeachingOptions = dataCopy;
          // console.log("this.TeachingOptions", this.TeachingOptions);
        })
        .catch(err => {
          console.error(err);
        });
    },
    // 撤回
    withdraw(id) {
      let params = [
        {
          tid: id
        }
      ];

      this.$confirm("是否确认退回？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: " info"
      })
        .then(() => {
          this.ajax
            .post(this.$store.state.api + "updateExamineState", params)
            .then(res => {
              this.getData();
            })
            .catch(error => {
              console.log(error);
            });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消退回"
          // });
        });
    },
    recordBtn(val) {
      this.RecordList = [];
      this.recordVisible = true;
      this.getRecordData(val);
    },
    // 查看记录
    getRecordData(val) {
      let params = {
        tid: val,
        type: this.pType
      };
      this.ajax
        .get(this.$store.state.api + "selectExamineOperateRecord", params)
        .then(res => {
          // console.log(res.data[0]);
          this.RecordList = res.data[0];
        })
        .catch(err => {
          console.error(err);
        });
    },
    recordHandleClose(done) {
      done();
    },
    // 提醒
    remindExamine() {
      this.remDig = true;
    },
    // 下载excel
    getExcel() {
      var res = this.tableData;
      // console.log('导出数据',res);
      //如果value的json字段的key值和想要的headers值不一致时，可做如下更改
      //将和下面的Object.fromEntries结合，将json字段的key值改变为要求的excel的header值
      var array = [];
      for (var i = 0; i < res.length; i++) {
        var _json = {};
        _json["教师姓名"] = res[i].username;
        _json["教师账号"] = res[i].eName;
        _json["所属教研室"] = res[i].tea;
        _json["考核进度"] = `${res[i].step}/${res[i].allStep}`;
        _json["自评分数"] = res[i].evaSca;
        _json["考核分数"] = res[i].cogSco;
        array.push(_json);
      }

      var XLSX = require("xlsx");
      const workbook = XLSX.utils.book_new(); //创建一个新的工作簿对象
      let ws = XLSX.utils.json_to_sheet(array); //将json对象数组转化成工作表
      ws["!cols"] = [
        //设置每一列的宽度
        { wch: 20 },
        { wch: 30 },
        { wch: 30 },
        { wch: 30 },
        { wch: 30 },
        { wch: 30 }
      ];

      XLSX.utils.book_append_sheet(workbook, ws, "sheet1"); //把sheet添加到workbook里，第三个参数是sheet名
      XLSX.writeFile(workbook, "教师发展.xlsx");
      // const wopts = { bookType: "xlsx", bookSST: false, type: "array" };//写入的样式bookType:输出的文件类型，type：输出的数据类型，bookSST: 是否生成Shared String Table，官方解释是，如果开启生成速度会下降，但在低版本IOS设备上有更好的兼容性
      // const wbout = XLSX.write(workbook, wopts);// 浏览器端和node共有的API,实际上node可以直接使用xlsx.writeFile来写入文件,但是浏览器没有该API
      // FileSaver.saveAs(new Blob([wbout], { type: "application/octet-stream" }), `${title} demo.xlsx`);//保存文件
      this.$message({
        message: "导出成功",
        type: "success"
      });
    },
    // 按照数字大小排序 方法-
    sortCogMethod(before, after) {
      return Number(before.cogSco) - Number(after.cogSco);
    },
    sortEvaMethod(before, after) {
      return Number(before.evaSca) - Number(after.evaSca);
    },
    // 教研室筛选
    filterTea(value, row, column) {
      // console.log(value, row, column);
      const property = column["property"];
      return row[property].includes(value);
    },
    // 是否完成筛选
    filterExa(value, row, column) {
      // console.log(value, row, column);
      const property = column["property"];
      return row[property] == value;
    },
    // ----------------

    // 保存修改
    saveTab(id) {
      let a = { sco2: 0, cogSum: "" };
      let b = { sco2: 0, cogSum: "" };
      this.PageBaseData.forEach(e => {
        e.children.forEach(i => {
          if (i.id == id) {
            a.sco2 = i.sco2;
            a.cogSum = i.cogSum;
          }
        });
      });

      this.PageBaseDataTwo.forEach(e => {
        e.children.forEach(i => {
          if (i.id == id) {
            b.sco2 = i.sco2;
            b.cogSum = i.cogSum;
          }
        });
      });

      console.log(a, b, id);
      if (
        a.sco2 == b.sco2 &&
        JSON.stringify(a.cogSum) === JSON.stringify(b.cogSum)
      )
        return;

      let PageBaseDataCopy = JSON.parse(JSON.stringify(this.PageBaseData));

      for (const e of PageBaseDataCopy) {
        for (const k of e.children) {
          if (k.testid.test.length > 0) {
            k.testid.test = k.testid.test.map(item => item.courseId);
          }
        }
      }

      let params = [
        {
          uid: this.userid,
          tid: this.digTid,
          typ: this.pType,
          // json: JSON.stringify(PageBaseDataCopy)
          json: JSON.stringify(PageBaseDataCopy),
          rjson: JSON.stringify({
            rjson: PageBaseDataCopy,
            text: `按人员,进行修改`
          })
        }
      ];
      // return console.log(params);
      this.ajax
        .post(this.$store.state.api + "updateExamineCogDataCopy", params)
        .then(res => {
          // console.log("updateExamineCogDataCopy", res);
          // this.CopDigSco();
          this.getDigData();
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 查看数据来源
    lookUserPrize(cid) {
      // return console.log(val);
      if (this.tableData.length <= 0)
        return this.$message.error("暂无人员提交");
      // this.ifmUrl = `https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/#/checkToTest?cid=${val}&oid=${this.oid}&org=${this.org}&type=2&role=0&peopleId=${this.userid}`;

      this.ifmUrl = `https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/#/checkToTest?cid=${cid}&oid=${this.oid}&org=${this.org}&type=2&role=0&peopleId=${this.digUserid}`;
      // this.ifmUrl = `https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/#/test?userid=${this.userid}&oid=45facc0a-1211-11ec-80ad-005056b86db5&org=&role=0`;
      this.diaIframe = true;
    },
    // 弹框方法切换专任，班主任
    cutPage(e) {
      this.digType = e;
      this.digLoading = true;

      // this.getDataDig();
    },
    // 弹框内班主任与专任教师切换，刷新tableData数据
    getDataDig() {
      let params = {
        oid: this.oid,
        org: this.org,
        type: this.digType
      };
      // console.log(params);
      this.ajax
        .get(this.$store.state.api + "selectTestExamineSecondData", params)
        .then(res => {
          let data = res.data[0];
          this.tableData = data;

          // 这一步是为了获取弹窗表单第一个人,如果为空的话就清空数据
          if (this.tableData.length > 0) {
            this.DigSelfSco = 0; //弹框自评分
            this.twoTarget = 0; //二级指标个数
            this.digTid = this.tableData[0].id; //表单id
            // this.diaSco = true;
            this.digUserid = this.tableData[0].userid; //弹框tableData数组中第一个数据userid
            this.disTeaClass = this.tableData[0].tea; //弹框tableData数组中第一个数据教研室
            // 判断所处数组第几位，方便后面上下切换
            this.cutPerson();
            // 获取基础模版，重新开始渲染数据
            this.getPageBase();
          } else {
            // 切换后tableData里没有数据的话将，自评分什么的清空
            this.getPageBase2();
          }

          // console.log("this.tableData", this.tableData);
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 弹框切换上一个教师
    upTea() {
      if (this.cutTeaNum <= 0) return this.$message.error("已经是第一个了");
      this.digLoading = true;

      this.cutTeaNum--;
      this.digUsername = this.tableData[this.cutTeaNum].username;
      this.disTeaClass = this.tableData[this.cutTeaNum].tea;
      this.digUserid = this.tableData[this.cutTeaNum].userid;
      this.digTid = this.tableData[this.cutTeaNum].id;

      this.getPageBase();
    },
    // 弹框切换下一个教师
    nextTea() {
      // console.log("this.tableData", this.tableData);
      if (this.cutTeaNum + 1 >= this.tableData.length)
        return this.$message.error("已经是最后一个了");
      this.digLoading = true;

      this.cutTeaNum++;
      this.digUsername = this.tableData[this.cutTeaNum].username;
      this.disTeaClass = this.tableData[this.cutTeaNum].tea;
      this.digUserid = this.tableData[this.cutTeaNum].userid;
      this.digTid = this.tableData[this.cutTeaNum].id;

      this.getPageBase();
    },
    // 弹框专任与班主任切换数据为空时，将表单清空
    getPageBase2() {
      let params = {
        typ: this.digType,
        org: this.org,
        oid: this.oid
      };
      this.ajax
        .get(this.$store.state.api + "selectTestExamineBase", params)
        .then(res => {
          // console.log("selectTestExamineBase", res.data[0][0]);
          this.DigSelfSco = 0;
          this.twoTarget = 0;
          this.digTid = "";
          this.digUserid = "";
          this.disTeaClass = "";
          this.digUsername = "暂无提交";

          this.PageBaseData = JSON.parse(res.data[0][0].json);
          // 处理数据来源
          this.handleData();
          this.digLoading = false;
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 弹框获取页面基础ui信息
    getPageBase() {
      let params = {
        typ: this.digType,
        org: this.org,
        oid: this.oid
      };
      this.ajax
        .get(this.$store.state.api + "selectTestExamineBase", params)
        .then(res => {
          // console.log("selectTestExamineBase", res.data[0][0]);

          this.PageBaseData = JSON.parse(res.data[0][0].json);
          this.PageBaseDataTwo = JSON.parse(res.data[0][0].json);
          // 处理数据来源
          this.handleData();
          // 先获取基础模板，然后再获取用户又没有填写过，填写过就开始循环赋值给基础模板，最后提交基础模板
          this.getDigData();
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 弹框获取页面渲染数据
    getDigData() {
      let params = {
        uid: this.digUserid,
        type: this.digType
      };
      this.ajax
        .get(this.$store.state.api + "getTestExamineByUserId", params)
        .then(res => {
          console.log("getTestExamineByUserId", res);

          if (res.data[0].length > 0) {
            let val = JSON.parse(res.data[0][0].json);

            this.PageBaseData.forEach(e => {
              val.forEach(i => {
                if (e.id == i.id) {
                  e.children.forEach(a => {
                    i.children.forEach(b => {
                      if (a.id == b.id) {
                        a.sco1 = b.sco1;
                        a.sco2 = b.sco2;
                        a.cogSum = b.cogSum;
                        a.selfSummary = b.selfSummary;
                      }
                    });
                  });
                }
              });
            });
            this.PageBaseDataTwo = val;
            // 弹框计算自评分数,与二级指标个数
            this.getTwoRigData();
          } else {
            // 清空自评分数,与二级指标个数
            this.DigSelfSco = 0;
            this.twoTarget = 0;
          }
          this.digLoading = false;
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 弹框计算自评分数,与二级指标个数
    getTwoRigData() {
      this.DigSelfSco = 0;
      this.twoTarget = 0;

      // 计算自评分数,与二级指标个数
      this.PageBaseData.forEach(e => {
        e.children.forEach(i => {
          this.DigSelfSco += i.sco1 * 1;
          this.twoTarget++;
        });
      });
      this.DigSelfSco = this.DigSelfSco.toFixed(2);
    },

    // 获取用户列表位置，以及用户名称
    cutPerson() {
      this.tableData.forEach((e, index) => {
        if (e.userid == this.digUserid) {
          this.cutTeaNum = index;
          this.digUsername = e.username;
        }
      });
    },
    // 评分关闭弹框
    handleClose(done) {
      this.getData();
      done();
    },
    // 数据来源关闭弹框
    handleClose2(done) {
      this.digLoading = true;
      this.getPageBase();
      done();
    },
    // handleClose3(done) {
    //   done();
    // },
    // 处理数据来源
    async handleData() {
      for (const e of this.PageBaseData) {
        for (const k of e.children) {
          if (k.testid.test.length > 0) {
            k.testid.test = await this.computedTest(k.testid.test);
          }
        }
      }
    },
    // 处理数据来源
    computedTest(val) {
      let params = [
        {
          uid: this.digUserid,
          testId: val.join(",")
        }
      ];
      return new Promise(resolve => {
        this.ajax
          .post(this.$store.state.api + "selectExamineTestName", params)
          .then(res => {
            resolve(res.data[0]);
          })
          .catch(error => {
            console.log(error);
          });
      });
    }
  }
};
</script>
<style scoped>
.personPage >>> .el-table tr {
  height: 70px;
}
.digUsernameCss {
  width: 70px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.recordDig >>> .el-dialog {
  height: 600px;
  width: 500px !important;
}
.remFlex {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 20px;
}
.remFlexTit {
  width: 80px;
  flex-shrink: 0;
}
.digTop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 15px 0;
}
.TabBtn {
  cursor: pointer;
  color: #528df6;
  margin: 0 10px;
}
.dialog_remDig >>> .el-dialog {
  height: 700px;
  margin: 0 auto !important;
  margin-top: 20px !important;
  overflow: hidden;
  min-width: 800px !important;
}

.dialog_remDig >>> .el-dialog__header {
  background: #454545 !important;
  padding: 15px 20px;
}
.dialog_diy >>> .el-dialog {
  height: 95%;
  margin: 0 auto !important;
  margin-top: 20px !important;
  overflow: hidden;
  min-width: 800px !important;
}

.dialog_diy >>> .el-dialog__header {
  background: #454545 !important;
  padding: 25px 20px;
}

.dialog_diy >>> .el-dialog__body {
  height: calc(100% - 50px);
  box-sizing: border-box;
  padding: 0px;
}

.dialog_diy >>> .el-dialog__title {
  color: #fff;
}

.dialog_diy >>> .el-dialog__headerbtn {
  top: 19px;
}

.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}

.dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  color: #fff;
}

.dialog_diy >>> .el-dialog__body,
.dialog_diy >>> .el-dialog__footer {
  background: #fafafa;
}
.ScoreStep {
  height: 100%;
  width: 100%;
}
.ScoreStep > input {
  height: 100% !important;
  outline-style: none;
  padding: 5px;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
  border-radius: 4px;
  border: none !important;
  /* border: 1px solid #dcdfe6 !important; */
}

.ScoreStep >>> .el-input-number {
  height: 100% !important;
}
.ScoreStep >>> .el-input {
  height: 100% !important;
}
.ScoreStep >>> .el-input__inner {
  height: 100%;
  padding-left: 15px;
  border: none;
  padding-right: 15px;
}
.testPersonExamine {
  width: 100%;
  min-width: calc(50px * 10);
  height: 100%;
  padding: 10px;
  display: flex;
  flex-direction: column;
  /* overflow: auto; */
  box-sizing: border-box;
  background-color: #fff;
}
.tArea {
  width: 100%;
  height: 100%;
  padding: 5px;
  box-sizing: border-box;
  display: block !important;
  text-align: left;
}
.testPersonExamine > .testTit {
  height: 100px;
  display: flex;
  padding: 15px 0;
  justify-content: space-between;
  align-items: center;
}
.teaLis {
  display: flex;
}
.teal {
  padding: 10px 20px;
  cursor: pointer;
}
.Tbor {
  border-bottom: 2px rgba(54, 129, 252, 1) solid;
  font-weight: 600;
}
.testCon {
  box-sizing: border-box;
  padding: 20px;
}

.orgData {
  cursor: pointer;
  color: #528df6;
  margin-bottom: 10px;
}
.sBox_table {
  width: 100%;
  min-width: 1500px;
  height: 100%;
  margin: 0 auto;
  /* min-width: 1520px; */
  font-size: 14px;
}

.table_title {
  width: calc(100% - 6px);
  /* min-width: calc(100px * 9); */
  height: 50px;
  background: #e0eafb;
  border: 1px solid #d5d8df;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
}
/* 取消[type='number']的input的上下箭头 */
input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}

input::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
}

input[type="number"] {
  -moz-appearance: textfield;
}
.table_title > div {
  /* width: calc(100% / 9); */
  /* min-width: 110px; */
  text-align: center;
  box-sizing: border-box;

  height: 100%;
  line-height: 50px;
  border-right: 1px solid #d5d8df;
}

.table_title > div:last-child {
  border: none;
}

.table_Content {
  width: 100%;
  min-width: calc(100px * 9);
  /* border: 1px solid #d5d8df; */
  border: none;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  text-align: center;
  align-items: center;
}

.twoCol {
  width: 100%;
  display: flex;
}

.ColTit {
  width: 150px !important;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px #ccc solid;
}

.twoCon {
  display: flex;
}

.twoCon > div > input {
  border: none;
  width: 100%;
  height: 100%;
  outline-style: none;
  text-align: center;
}
.twoCon {
  display: flex;
  width: 100%;
}
.twoCon > div > textarea {
  border: none;
  width: 100%;
  height: 100%;
  resize: none;
  box-sizing: border-box;
  padding: 5px;
  outline-style: none;
}
.twoCon > div {
  /* width: 10%; */
  /* min-width: 110px; */
  min-height: 50px;
  /* line-height: 50px; */
  display: flex;
  box-sizing: border-box;

  justify-content: center;
  align-items: center;
  border-left: 1px #ccc solid;
  border-bottom: 1px #ccc solid;
}
.twoCon > div:nth-child(1) {
  width: 160px !important;
}
.twoCon > div:nth-child(2) {
  width: 160px !important;
}
.twoCon > div:nth-child(3) {
  width: 110px !important;
}
.twoCon > div:nth-child(4) {
  width: 110px !important;
}
.twoCon > div:nth-child(5) {
  flex: 1;
}
.twoCon > div:nth-child(6) {
  width: 250px !important;
}
.twoCon > div:nth-child(7) {
  width: 110px !important;
}
.twoCon > div:nth-child(8) {
  flex: 1;
}

.ColCon {
  flex: 1;
}

.scoreBox{
  display: flex;
  align-items: center;
}

.scoreBox > span:nth-child(1){
  max-width: 100px;
  width: 100px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: right;
}

.scoreBox > span:nth-child(2){
  margin-left: 10px;
}

</style>
