<script setup lang="ts">
defineOptions({
  name: "evaluateChangeManageObject"
});
import { getState, getStateType, assessmentStatus } from "@/config/tag";
import { ref, reactive, onMounted, watch, computed } from "vue";
import {
  getAssessmentQuotaDetails,
  delAssessmentObject,
  getAssessmentObjectDetails,
  postAddAssessmentObject,
  updateAssessmentQuotaDetails,
  alterFinishValue,
  automaticCollection,
  setTableHeader,
  delBatchDelScoreInfoVO,
  getAssessmentDetails
} from "@/api/assessment";
import editIndex from "./editIndex.vue";
import { getTemplateInfoAllList } from "@/api/templateInfo";
import { useRouter } from "vue-router";
import iconEdit from "@/assets/公式计算.png";
import { ElMessage, ElMessageBox } from "element-plus";
import {
  treeDept,
  postListTreeWithUserApi,
  postListTree
} from "@/api/department";
import { Search } from "@element-plus/icons-vue";
import messagePerson from "./message.vue";
import dayjs from "dayjs";
// 人员,医疗组,负责人
import {
  postUserList,
  postOrganizationUserPage,
  getLeaderList
} from "@/api/userSetting";
// 获取医疗组的数据
import { postPageGroup } from "@/api/userGroup";
import { en } from "element-plus/es/locale/index.mjs";
const $props = defineProps({
  message: {
    type: Object
  }
});
const valSelection = ref(false);
const messageData = ref({});
const initParams = reactive({
  params: {
    pageNumber: 1,
    pageSize: 10,
    userName: "",
    modelName: "",
    quotaName: "",
    assessmentId: "",
    orderField: "",
    orderType: ""
  },
  objParams: {
    pageNumber: 1,
    pageSize: 10,
    userName: "",
    modelName: "",
    quotaName: "",
    assessmentId: "",
    orderField: "",
    orderType: ""
  },
  indexParams: {
    pageNumber: 1,
    pageSize: 10,
    userName: "",
    modelName: "",
    quotaName: "",
    assessmentId: "",
    orderField: "",
    orderType: ""
  },
  tmpParams: {
    page: 1,
    pageSize: 100
  },
  total: 0,
  total1: 0,
  list: [],
  Indexlist: [],
  tmpList: []
});
const state = reactive({
  tableType: 0
});

// 转换函数 --- 人员
const convertDepartmentDataRecursive_Person = data => {
  return data.map(department => {
    const { userNameNew, userCodeNew, children, type } = department;
    // 递归处理子节点
    const processedChildren =
      children.length > 0
        ? convertDepartmentDataRecursive_Person(children)
        : [];
    // 检查子节点是否有 type 为 "user" 的节点
    const hasUserInChildren = processedChildren.some(child => !child.disabled);
    // 当前节点是否为 user 类型
    const isUser = type === "user";
    // 判断当前节点是否需要禁用
    const shouldDisable = !isUser && !hasUserInChildren;

    return {
      value: userCodeNew,
      label: userNameNew,
      children: processedChildren,
      disabled: shouldDisable
    };
  });
};
// 转换函数 --- 部门
const convertDepartmentDataRecursive = data => {
  return data.map(department => {
    const { deptCode, deptName, childrenRes } = department;
    return {
      value: deptCode,
      label: deptName,
      children:
        childrenRes.length > 0
          ? childrenRes.map(child => convertDepartmentDataRecursive([child])[0])
          : []
    };
  });
};
const dpetTree = ref([]);
onMounted(async () => {
  Object.assign(messageData.value, $props.message);
  console.log("传递的值", $props.message);
  switch (messageData.value.assessmentType) {
    case 0:
      initParams.assessmentType = "员工";
      break;
    case 1:
      initParams.assessmentType = "部门";
      break;
    case 2:
      initParams.assessmentType = "医疗组";
      break;
    case 3:
      initParams.assessmentType = "员工";
  }
  assessmentTypeApi(messageData.value.assessmentType);
  initParams.params.assessmentId = $props.message.id;
  initParams.objParams.assessmentId = $props.message.id;
  initParams.indexParams.assessmentId = $props.message.id;
  state.tableType = $props.message.assessmentType;
  await getAssessmentQuotaDetailsApi();
  await getTemplateInfoListApi();
  await getAssessmentObjectDetailsApi();
  // await alterFinishValueApi();
});
const treeDeptList = ref([]);
const assessmentTypeApi = async value => {
  switch (value) {
    case 0:
      postListTreeWithUserApi();
      break;
    case 1:
      const { data, code } = await postListTree();
      dpetTree.value = convertDepartmentDataRecursive(data);
      break;
    case 2:
      const yiliao = await postPageGroup({
        pageNumber: 1,
        pageSize: 1000
      });
      treeDeptList.value = yiliao.data.records;
      break;
    case 3:
      const fuzhere = await getLeaderList({ type: "dept" });
      console.log(fuzhere);
      treeDeptList.value = fuzhere.data;
  }
};
// 查询考核信息详情(考核指标)前先调用此接口,插入类型是自动采集的完成值
const alterFinishValueApi = async () => {
  const { code, msg } = await alterFinishValue(initParams.indexParams);
  if (code != 200) {
    // ElMessage.error(msg);
  }
};
// 指标分页查询
const getAssessmentQuotaDetailsApi = async () => {
  const res = await getAssessmentQuotaDetails(initParams.indexParams);
  if (res.code === 200) {
    initParams.Indexlist = res.data.records;
    initParams.total1 = res.data.totalRow;
    getAssessmentDetailsApi(); // 获取考核指标详情表头信息
  }
};
// 考核模板
const modulesList = ref([]);
const getTemplateInfoListApi = async () => {
  const { data = [], code } = await getTemplateInfoAllList();
  if (code == 200) {
    modulesList.value = data;
  }
};
const handleModulesSelect = val => {
  addPersonParams.assessmentModelId = val;
  modulesList.value.forEach(el => {
    if (el.id === val) {
      addPersonParams.assessmentModelName = el.tpName;
    }
  });
};
// 删除
const delParams = reactive({
  assessmentId: "",
  objectAddVoList: []
});
// 被考核对象
const addPersonParams = reactive({
  assessmentId: "",
  objectAddVoList: [],
  assessmentModelId: "",
  assessmentModelName: "",
  value1: [],
  modulesValue: ""
});
const value1Text = {
  "0": "请选择人员",
  "1": "请选择科室",
  "2": "请选择医疗组",
  "3": "请选择部门负责人"
};
const addPersonParamsRules = reactive({
  value1: [
    {
      required: true,
      message: value1Text[$props.message.assessmentType],
      trigger: "change"
    }
  ],
  modulesValue: [
    {
      required: true,
      message: "请选择考核模板",
      trigger: "change"
    }
  ]
});
// 添加被考核人
const delAssessmentObjectApi = async () => {
  if (valSelection.value) {
    ElMessageBox.confirm(
      "该员工考核删除后不可恢复，请谨慎操作！",
      "确定删除该员工考核吗？",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }
    ).then(async () => {
      const { code, msg } = await delAssessmentObject(delParams);
      if (code === 200) {
        getAssessmentObjectDetailsApi();
        ElMessage.success("删除成功");
      } else {
        ElMessage.error(msg);
      }
    });
  } else {
    ElMessage.warning("请选择要删除的考核对象");
  }
};
// 批量选中
const changeSelection = val => {
  if (val) {
    valSelection.value = true;
    delParams.objectAddVoList = [];
    delParams.assessmentId = messageData.value.id;
    addPersonParams.assessmentId = messageData.value.id;
    let assessmentObjectId;
    let assessmentObjectName;
    val.forEach((item, index) => {
      const obj = {
        assessmentObjectId: item.assessmentObjectId,
        assessmentObjectName: item.assessmentObjectName
      };

      // delParams.objectAddVoList.forEach((item1, index1) => {
      //   if (index == index1) {
      // assessmentObjectId = item.assessmentObjectId;
      // assessmentObjectName = item.assessmentObjectName;
      delParams.objectAddVoList.push(obj);
      //   }
      // });
    });
  }
};
const router = useRouter();
const activeName = ref("first");
// 批量导入
const addsImport = () => {
  router.push({ name: "importIndex", query: { ...messageData.value } });
};
const publishShow = ref(true);
const publish = () => {
  publishShow.value = false;
  ElMessage({
    message: "成功",
    type: "success"
  });
};
// 添加被考核人
const dialogVisibleAdd = ref(false);
const assessmentTypeRef = ref();
const transformArrayFormat = data => {
  return data.assessmentObjectId
    ?.map((item, index) => {
      return {
        assessmentObjectId: item,
        assessmentObjectName: data.assessmentObjectName[index]
      };
    })
    .flat();
};
// 人员 ---- 部门
function flattenTree(data) {
  let result = [];
  for (const item of data) {
    // 添加当前节点到结果数组
    result.push({ value: item.value, label: item.label });
    // 如果有子节点，递归处理子节点
    if (item.children && item.children.length > 0) {
      result = result.concat(flattenTree(item.children));
    }
  }
  return result;
}
// const handleNodeRreeSelect = data => {
//   let dataList;
//   if ($props.message.assessmentType == 1) {
//     if (Array.isArray([data])) {
//       dataList = flattenTree([data]);
//       dataList.map(item => {
//         addPersonParams?.objectAddVoList?.push({
//           assessmentObjectId: item.value,
//           assessmentObjectName: item.label
//         });
//       });
//     }
//   }
// };
const handleRreeSelect = () => {
  addPersonParams.objectAddVoList = [];
  const dataList = assessmentTypeRef.value.getCheckedNodes() || [];
  if ($props.message.assessmentType === 0) {
    dataList.forEach(item => {
      if (item.value.substring(0, 4) === "user") {
        addPersonParams.objectAddVoList.push({
          assessmentObjectId: item.value,
          assessmentObjectName: item.label
        });
      }
    });
  } else {
    dataList.forEach(item => {
      addPersonParams.objectAddVoList.push({
        assessmentObjectId: item.value,
        assessmentObjectName: item.label
      });
    });
  }
};
// 医疗 --- 医疗主任
const handChange = data => {
  let gropList = [];
  treeDeptList.value.map(it => {
    data.map(id => {
      if ($props.message.assessmentType == 2) {
        if (it.groupCode == id) {
          gropList.push({
            assessmentObjectId: it.groupCode,
            assessmentObjectName: it.groupName
          });
        }
      }
      if ($props.message.assessmentType == 3) {
        if (it.userCode == id) {
          gropList.push({
            assessmentObjectId: it.userCode,
            assessmentObjectName: it.realName
          });
        }
      }
    });
  });
  addPersonParams.objectAddVoList = gropList;
  const list = ref({});
  const arr = treeDeptList.value.filter(item => {
    return addPersonParams.value1.includes(item.groupCode);
  });
  list.value.assessmentObjectId = arr.map(item => item.groupCode);
  list.value.assessmentObjectName = arr.map(item => item.groupName);
  // addPersonParams.objectAddVoList = transformArrayFormat(list);
};

const dialogVisibleAddShow = () => {
  dialogVisibleAdd.value = true;
};
// 跳转对应科室
const GoView = row => {
  console.log(row, "路由跳转信息展示", messageData.value);
  const arr = {
    "0": "/draw/children/worker/workerDrak",
    "1": "/draw/children/department/departmentDrank",
    "2": "/draw/children/health/healthDrank",
    "3": "/draw/children/head/headDrank"
  };
  for (let key in arr) {
    if ($props.message.assessmentType == key) {
      router.push({
        path: arr[key],
        query: {
          assessmentId: messageData.value.id,
          assessmentModelId: row.assessmentModelId,
          assessmentObjectId: row.assessmentObjectId,
          assessmentName: row.assessmentModelName,
          assessmentModelName: row.assessmentModelName,
          // assessmentName: messageData.value.name,
          assessmentObjectName: row.assessmentObjectName
        }
      });
      return;
    }
  }
};
// 考核对象
const objList = ref([]);
const getAssessmentObjectDetailsApi = async () => {
  const { data, msg, code } = await getAssessmentObjectDetails(
    initParams.objParams
  );
  const res = await getAssessmentObjectDetails({
    pageNumber: 1,
    pageSize: 1000,
    assessmentId: initParams.objParams.assessmentId
  });
  if (res.code == 200) {
    // initParams.tmpList = res.data.records;
    initParams.tmpList = Array.from(
      new Map(
        res.data.records.map(item => [item.assessmentModelId, item])
      ).values()
    );
  }
  if (code === 200) {
    objList.value = data.records;
    initParams.total = data.totalRow;
  }
};
const handleSizeChange = (val: number) => {
  initParams.objParams.pageSize = val;
  getAssessmentObjectDetailsApi();
};
const handleCurrentChange = (val: number) => {
  initParams.objParams.pageNumber = val;
  getAssessmentObjectDetailsApi();
};
// 指标
const handleSizeIndexChange = (val: number) => {
  initParams.indexParams.pageSize = val;
  getAssessmentQuotaDetailsApi();
};
const handleCurrentIndexChange = (val: number) => {
  initParams.indexParams.pageNumber = val;
  getAssessmentQuotaDetailsApi();
};
// 指标修改
const updateAssessmentQuotaDetailsApi = async row => {
  try {
    const { msg, code } = await updateAssessmentQuotaDetails({ ...row });
    Object.assign(editVxe, {
      relationId: null,
      startValue: null,
      finalValue: null,
      dataSource: null,
      formulaType: null,
      formula: null,
      formulaParamsList: null,
      score: null,
      assessmentObjectId: null,
      assessmentModelId: null,
      id: null,
      dimId: null,
      assessmentId: null
    });
    if (code === 200) {
      ElMessage.success("修改成功");
      getAssessmentQuotaDetailsApi();
    } else {
      getAssessmentQuotaDetailsApi();
    }
  } catch (error) {
    // ElMessage.error(error.response.data.msg);
    getAssessmentQuotaDetailsApi();
  }
};
const tableVxeRef = ref();
const editConfig = ref({
  trigger: "click",
  mode: "cell",
  showStatus: true,
  beforeEditMethod({ row, column }) {
    console.log("编辑123212132", column.title);
    // 完成值 挑战值 门槛值 增幅 降幅 上期完成值 上上期完成值 得分
    if (
      column.title == "目标值" ||
      column.title == "挑战值" ||
      column.title == "门槛值"
    ) {
      return true;
    } else {
      if (row.valueInput == 4 || row.valueInput == "4") {
        return false;
      } else {
        return true;
      }
    }
  }
});
const editVxe = reactive({
  relationId: null,
  startValue: null,
  finalValue: null,
  dataSource: null,
  score: null,
  assessmentObjectId: null,
  assessmentModelId: null,
  id: null,
  dimId: null,
  addValue: null,
  decValue: null,
  challengeValue: null,
  upperValue: null,
  agupperValue: null,
  assessmentId: null,
  remark: null,
  formulaType: null,
  formula: null,
  formulaParamsList: null
});
// 编辑前面
const editOpenEvent = data => {
  console.log("editOpenEvent", data);
};
const hangdleOpenClick = row => {
  Object.assign(editVxe, {
    relationId: null,
    startValue: null,
    finalValue: null,
    dataSource: null,
    score: null,
    assessmentObjectId: null,
    assessmentModelId: null,
    addValue: null,
    decValue: null,
    challengeValue: null,
    upperValue: null,
    agupperValue: null,
    id: null,
    dimId: null,
    assessmentId: null,
    remark: null,
    formulaType: null,
    formula: null,
    formulaParamsList: null
  });
  editVxe.finalValue = row?.finalValue;
  editVxe.score = row?.score;
};
const editClosedEvent = row => {
  // { row, column, newValue, oldValue }
  const $table = tableVxeRef.value;
  if ($table) {
    console.log(1433223, row.row);
    editVxe.relationId = row.row?.relationId;
    editVxe.assessmentModelId = row.row?.assessmentModelId;
    editVxe.assessmentObjectId = row.row?.assessmentObjectId;
    editVxe.id = row.row?.id;
    editVxe.dimId = row.row?.dimId;
    editVxe.assessmentId = messageData.value.id;
    editVxe.formulaType = row.row?.formulaType;
    editVxe.formula = row.row?.formula;
    editVxe.formulaParamsList = row.row?.formulaParamsList;
    // 判断表头
    if (row.column.title == "得分") {
      // 判断是否为空
      if (row.row?.score) {
        // 判断是否id相同
        if (editVxe.score != row.row?.score) {
          // if (row.row?.id != editVxe.id) {
          editVxe.score = convertToNumberIfPercentage(row.row?.score);
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.startValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.agupperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
          // }
        }
      }
    }
    if (row.column.title == "完成值") {
      if (row.row?.finalValue) {
        // if (row.row?.id != editVxe.id) {
        if (editVxe.finalValue != row.row?.finalValue) {
          editVxe.finalValue = convertToNumberIfPercentage(row.row?.finalValue);
          editVxe.score = null;
          editVxe.challengeValue = null;
          editVxe.startValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.agupperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
        // }
      }
    }
    if (row.column.title == "挑战值") {
      if (row.row?.challengeValue) {
        // if (row.row?.id != editVxe.id) {
        if (editVxe.challengeValue != row.row?.challengeValue) {
          editVxe.challengeValue = convertToNumberIfPercentage(
            row.row?.challengeValue
          );
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.startValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.agupperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
        // }
      }
    }
    if (row.column.title == "门槛值") {
      if (row.row?.startValue) {
        // if (row.row?.id != editVxe.id) {
        if (editVxe.startValue != row.row?.startValue) {
          editVxe.startValue = convertToNumberIfPercentage(row.row?.startValue);
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.agupperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
        // }
      }
    }
    if (row.column.title == "增幅") {
      if (row.row?.addValue) {
        if (editVxe.addValue != row.row?.addValue) {
          editVxe.addValue = convertToNumberIfPercentage(row.row?.addValue);
          editVxe.startValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.agupperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
    if (row.column.title == "降幅") {
      if (row.row?.decValue) {
        if (editVxe.decValue != row.row?.decValue) {
          editVxe.decValue = convertToNumberIfPercentage(row.row?.decValue);
          editVxe.startValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.upperValue = null;
          editVxe.agupperValue = null;
          editVxe.targetValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
    if (row.column.title == "上期完成值") {
      if (row.row?.upperValue) {
        if (editVxe.upperValue != row.row?.upperValue) {
          editVxe.upperValue = convertToNumberIfPercentage(row.row?.upperValue);
          editVxe.startValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.agupperValue = null;
          editVxe.targetValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
    if (row.column.title == "上上期完成值") {
      if (row.row?.agupperValue) {
        if (editVxe.agupperValue != row.row?.agupperValue) {
          editVxe.agupperValue = convertToNumberIfPercentage(
            row.row?.agupperValue
          );
          editVxe.startValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
    if (row.column.title == "目标值") {
      if (row.row?.targetValue) {
        if (editVxe.targetValue != row.row?.targetValue) {
          editVxe.targetValue = convertToNumberIfPercentage(
            row.row?.targetValue
          );
          editVxe.startValue = null;
          editVxe.agupperValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.remark = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
    if (row.column.title == "备注") {
      if (row.row?.remark) {
        if (editVxe.remark != row.row?.remark) {
          editVxe.remark = convertToNumberIfPercentage(row.row?.remark);
          editVxe.startValue = null;
          editVxe.agupperValue = null;
          editVxe.score = null;
          editVxe.finalValue = null;
          editVxe.challengeValue = null;
          editVxe.addValue = null;
          editVxe.decValue = null;
          editVxe.upperValue = null;
          editVxe.targetValue = null;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
  }
};

// 关闭弹窗
const closePerson = () => {
  Object.assign(addPersonParams, {
    assessmentId: "",
    objectAddVoList: [],
    assessmentModelId: "",
    assessmentModelName: ""
  });
  addPersonParams.value1 = [];
  addPersonParams.modulesValue = "";
  ruleFormRef.value.resetFields();
  dialogVisibleAdd.value = false;
};

// 添加被考核人
const ruleFormRef = ref(null);
const addPerson = () => {
  ruleFormRef.value.validate(async valid => {
    if (valid) {
      addPersonParams.assessmentId = $props.message.id;
      let arr = [];
      if ($props.message.assessmentType == 0) {
        addPersonParams.objectAddVoList.map(it => {
          if (it.assessmentObjectId.substring(0, 4) == "user") {
            arr.push(it);
          }
          addPersonParams.objectAddVoList = arr;
        });
      }
      const { data, msg, code } = await postAddAssessmentObject({
        assessmentId: addPersonParams.assessmentId,
        assessmentModelId: addPersonParams.assessmentModelId,
        assessmentModelName: addPersonParams.assessmentModelName,
        objectAddVoList: addPersonParams.objectAddVoList
      });
      if (code === 200) {
        ElMessage.success("添加成功");
        dialogVisibleAdd.value = false;
        getAssessmentObjectDetailsApi();
        // 添加成功后，考核指标接口调用
        getAssessmentQuotaDetailsApi();
        closePerson();
      }
    }
  });
};

const changTitle = () => {
  const obj = {
    0: "添加被考核人",
    1: "添加被考核科室",
    2: "添加被考核医疗组",
    3: "添加被考核部门负责人"
  };
  return obj[$props.message.assessmentType];
};
const editDisabledEvent = ({}) => {};
// 同步数据
const automaticCollectionApi = async () => {
  const { code, msg } = await automaticCollection(initParams.indexParams);
  if (code === 200) {
    ElMessage.success("同步数据成功");
    getAssessmentQuotaDetailsApi();
  } else {
    bistatus.value = 1;
  }
};
const assessmentHeader = reactive({
  id: "",
  name: "",
  cycle: "",
  cycleValue: "",
  assessmentType: 0,
  assessmentStatus: 0,
  isDelete: 0,
  showTargetValue: 1,
  showChallengeValue: 0,
  showStartValue: 0,
  showAddValue: 0,
  showDecValue: 0,
  showUpperValue: 0,
  showAgupperValue: 0,
  showRemark: 0
});
const showAssessmentHeader = reactive({
  showTargetValue: 1,
  showChallengeValue: 0,
  showStartValue: 0,
  showAddValue: 0,
  showDecValue: 0,
  showUpperValue: 0,
  showAgupperValue: 0,
  showRemark: 0
});
// 开关状态
// 目标值
const showTargetValueSwitch = computed({
  get: () => assessmentHeader.showTargetValue === 1,
  set: value => {
    assessmentHeader.showTargetValue = value ? 1 : 0;
  }
});
// 挑战值
const showChallengeValueSwitch = computed({
  get: () => assessmentHeader.showChallengeValue === 1,
  set: value => {
    assessmentHeader.showChallengeValue = value ? 1 : 0;
  }
});
// 门槛值
const showStartValueSwitch = computed({
  get: () => assessmentHeader.showStartValue === 1,
  set: value => {
    assessmentHeader.showStartValue = value ? 1 : 0;
  }
});
// 增幅值
const showAddValueSwitch = computed({
  get: () => assessmentHeader.showAddValue === 1,
  set: value => {
    assessmentHeader.showAddValue = value ? 1 : 0;
  }
});
// 降幅值
const showDecValueSwitch = computed({
  get: () => assessmentHeader.showDecValue === 1,
  set: value => {
    assessmentHeader.showDecValue = value ? 1 : 0;
  }
});
// 上期数值
const showUpperValueSwitch = computed({
  get: () => assessmentHeader.showUpperValue === 1,
  set: value => {
    assessmentHeader.showUpperValue = value ? 1 : 0;
  }
});
// 上上期值
const showAgupperValueSwitch = computed({
  get: () => assessmentHeader.showAgupperValue === 1,
  set: value => {
    assessmentHeader.showAgupperValue = value ? 1 : 0;
  }
});
// 备注
const remarkValueValue = computed({
  get: () => assessmentHeader.showRemark === 1,
  set: value => {
    assessmentHeader.showRemark = value ? 1 : 0;
  }
});
const setTableHeaderApi = async () => {
  Object.assign(assessmentHeader, {
    id: $props.message.id,
    name: $props.message.name,
    cycle: $props.message.cycle,
    cycleValue: $props.message.cycleValue,
    assessmentType: $props.message.assessmentType,
    assessmentStatus: $props.message.assessmentStatus
  });
  const { code, msg } = await setTableHeader(assessmentHeader);
  if (code === 200) {
    getAssessmentQuotaDetailsApi();
    let aa = JSON.parse(JSON.stringify(assessmentHeader));
    console.log("表头设置", aa);
    // 目标值
    aa.showTargetValue == 1
      ? showColEvent("targetValue")
      : hideColEvent("targetValue");
    // 挑战值
    aa.showChallengeValue == 1
      ? showColEvent("challengeValue")
      : hideColEvent("challengeValue");
    // 门槛值
    aa.showStartValue == 1
      ? showColEvent("startValue")
      : hideColEvent("startValue");
    // 增幅
    aa.showAddValue == 1 ? showColEvent("addValue") : hideColEvent("addValue");
    // 降幅
    aa.showDecValue == 1 ? showColEvent("decValue") : hideColEvent("decValue");
    // 上期完成值
    aa.showUpperValue == 1
      ? showColEvent("upperValue")
      : hideColEvent("upperValue");
    // 上上期完成值
    aa.showAgupperValue == 1
      ? showColEvent("agupperValue")
      : hideColEvent("agupperValue");
    // 备注
    aa.showRemark == 1 ? showColEvent("remark") : hideColEvent("remark");
    Object.assign(showAssessmentHeader, aa);
    ElMessage.success("表头设置成功");
  } else {
    ElMessage.error(msg);
  }
};
const bistatus = ref(1); //(0同步中，1同步完成)
const getAssessmentDetailsApi = async () => {
  const { code, data } = await getAssessmentDetails({
    id: messageData.value.id
  });
  if (code == 200) {
    assessmentHeader.showTargetValue = data.showTargetValue;
    assessmentHeader.showChallengeValue = data.showChallengeValue;
    assessmentHeader.showStartValue = data.showStartValue;
    assessmentHeader.showAddValue = data.showAddValue;
    assessmentHeader.showDecValue = data.showDecValue;
    assessmentHeader.showUpperValue = data.showUpperValue;
    assessmentHeader.showAgupperValue = data.showAgupperValue;
    assessmentHeader.showRemark = data.showRemark;
    bistatus.value = data.bistatus;
    let aa = JSON.parse(JSON.stringify(assessmentHeader));
    // 目标值
    aa.showTargetValue == 1
      ? showColEvent("targetValue")
      : hideColEvent("targetValue");
    // 挑战值
    aa.showChallengeValue == 1
      ? showColEvent("challengeValue")
      : hideColEvent("challengeValue");
    // 门槛值
    aa.showStartValue == 1
      ? showColEvent("startValue")
      : hideColEvent("startValue");
    // 增幅
    aa.showAddValue == 1 ? showColEvent("addValue") : hideColEvent("addValue");
    // 降幅
    aa.showDecValue == 1 ? showColEvent("decValue") : hideColEvent("decValue");
    // 上期完成值
    aa.showUpperValue == 1
      ? showColEvent("upperValue")
      : hideColEvent("upperValue");
    // 上上期完成值
    aa.showAgupperValue == 1
      ? showColEvent("agupperValue")
      : hideColEvent("agupperValue");
    // 备注
    aa.showRemark == 1 ? showColEvent("remark") : hideColEvent("remark");
    Object.assign(showAssessmentHeader, aa);
  }
};
// 判断是否为百分数
function convertToNumberIfPercentage(value) {
  // 判断是否为字符串，并且是否包含百分号
  if (typeof value === "string" && value.trim().endsWith("%")) {
    // 去掉百分号并将剩余的部分转换为数字
    const numberValue = parseFloat(value.slice(0, -1));

    // 如果转换后的值是有效的数字，返回数字形式
    if (!isNaN(numberValue)) {
      return numberValue / 100; // 转换为小数
    } else {
      return value; // 如果无法转换为有效数字，返回原值
    }
  }
  // 如果不是百分数，直接返回原值
  return value;
}
// 数据校验
const validRules = ref({
  finalValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          cellValue = "";
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  targetValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          cellValue = "";
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  challengeValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  startValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  addValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  decValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  upperValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  agupperValue: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (
          numberPattern.test(cellValue) ||
          decimalPattern.test(cellValue) ||
          percentagePattern.test(cellValue)
        ) {
          return; // 校验通过
        } else {
          return new Error("请输入一个有效的数字、小数或百分数"); // 校验不通过
        }
      }
    }
  ],
  score: [
    {
      validator: ({ cellValue }) => {
        const numberPattern = /^[0-9]+(\.[0-9]+)?$/; // 匹配数字或小数
        const decimalPattern = /^\d+(\.\d+)?$/; // 匹配小数
        const percentagePattern = /^([0-9]{1,2}|100)(\.[0-9]{1,2})?%$/; // 匹配百分数
        if (numberPattern.test(cellValue) || decimalPattern.test(cellValue)) {
          return;
        } else {
          return new Error("请输入一个有效的数字、小数"); // 校验不通过
        }
      }
    }
  ]
});
// 固定表头
// 计算列配置
const showColEvent = field => {
  const $table = tableVxeRef.value;
  if ($table) {
    $table.showColumn(field);
  }
};
const hideColEvent = field => {
  const $table = tableVxeRef.value;
  if ($table) {
    $table.hideColumn(field);
  }
};
const editIndexShow = ref(null);
const editIndexOpen = (row: Object) => {
  if (bistatus.value == 0) {
    ElMessage.error("数据同步中，不允许操作");
    return;
  }
  editIndexShow.value.open({
    ...row,
    assessmentId: initParams.indexParams.assessmentId
  });
};
const deleteParam = ref([]);
// 批量删除指标
const deleteMantList = () => {
  if (deleteParam.value.length === 0) {
    ElMessage.warning("请选择要删除的考核指标");
  } else {
    ElMessageBox.confirm(
      "这些考核项删除后将不可恢复，请谨慎操作",
      "确定删除这些考核项吗？",
      {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }
    ).then(async () => {
      deleteParam.value.map(item => {
        item.assessmentId = initParams.indexParams.assessmentId;
      });
      const { code } = await delBatchDelScoreInfoVO(deleteParam.value);
      if (code === 200) {
        getAssessmentQuotaDetailsApi();
        activeName.value = "second";
        ElMessage({
          type: "success",
          message: "删除成功"
        });
      }
    });
  }
};
// 单选
const selectChangeEvent = row => {
  const $table = tableVxeRef.value;
  deleteParam.value = [];
  if ($table) {
    // deleteParam.value = row.records;
    row.records.map(item => {
      deleteParam.value.push({
        assessmentObjectId: item.assessmentObjectId,
        assessmentModelId: item.assessmentModelId,
        assessmentId: item.assessmentId,
        dimId: item.dimId,
        indId: item.id
      });
    });
  }
};
// 全选
const selectAllChangeEvent = row => {
  const $table = tableVxeRef.value;
  deleteParam.value = [];
  if ($table) {
    // deleteParam.value = row.records;
    console.log(111111, row.records);
    row.records.map(item => {
      deleteParam.value.push({
        assessmentObjectId: item.assessmentObjectId,
        assessmentModelId: item.assessmentModelId,
        assessmentId: item.assessmentId,
        dimId: item.dimId,
        indId: item.id
      });
    });
  }
};
</script>

<template>
  <div class="w-full">
    <!-- 指标编辑 -->
    <editIndex
      ref="editIndexShow"
      @getAssessmentQuotaDetailsApi="getAssessmentQuotaDetailsApi"
    />
    <div class="w-full flex items-center justify-between">
      <div class="flex items-center justify-between mt-2">
        <div class="bg-icon">
          <div>
            <el-icon>
              <Tickets />
            </el-icon>
          </div>
        </div>
        <div>
          <div class="flex items-center justify-between">
            <h5>{{ messageData.name }}</h5>
            <el-tag :type="getStateType(messageData.assessmentStatus)">
              {{ assessmentStatus(messageData.assessmentStatus) }}
            </el-tag>
          </div>
          <el-text type="info" class="text-xs">
            {{ messageData.cycleValue }}
          </el-text>
        </div>
      </div>
      <div class="mr-10">
        <Auth :value="['公布考核结果']">
          <el-button
            v-if="publishShow"
            type="primary"
            :disabled="bistatus == 0"
            @click="publish"
            >公布考核结果</el-button
          >
        </Auth>
      </div>
    </div>
    <el-tabs v-model="activeName" class="demo-tabs">
      <el-tab-pane label="考核对象" name="first">
        <div class="w-full flex items-center justify-between">
          <div class="w-1/2 flex items-center justify-between">
            <el-text class="w-1/5">考核模板</el-text>
            <el-select
              v-model="initParams.objParams.modelName"
              placeholder="请选择"
              filterable
              clearable
              style="width: 250px"
              @change="getAssessmentObjectDetailsApi"
            >
              <el-option
                v-for="itemTmp in initParams.tmpList"
                :key="itemTmp.id"
                :label="itemTmp.assessmentModelName"
                :value="itemTmp.assessmentModelName"
              />
            </el-select>
            <el-input
              v-model="initParams.objParams.userName"
              class="ml-2"
              clearable
              placeholder="搜索"
              :prefix-icon="Search"
              @change="getAssessmentObjectDetailsApi"
            />
          </div>
          <div class="mr-10">
            <!-- <el-button type="primary" plain>批量调整执行人</el-button>
            <el-button type="primary" plain>批量重置流程</el-button> -->
            <Auth :value="['批量删除']">
              <el-button
                type="primary"
                plain
                :disabled="bistatus == 0"
                @click="delAssessmentObjectApi"
              >
                批量删除
              </el-button>
            </Auth>
            <Auth :value="['添加被考核人']">
              <el-button
                type="primary"
                plain
                :disabled="bistatus == 0"
                @click="dialogVisibleAddShow"
                >{{ changTitle() }}</el-button
              >
            </Auth>
          </div>
        </div>
        <el-table
          :data="objList"
          style="width: 100%"
          @selection-change="changeSelection"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column
            v-if="state.tableType == 0 || state.tableType == 3"
            prop="realName"
            label="人员"
            width="100"
          />
          <el-table-column
            v-if="state.tableType == 2"
            prop="assessmentObjectName"
            label="医疗组"
            width="100"
          />
          <el-table-column
            v-if="state.tableType == 0 || state.tableType == 3"
            prop="userName"
            label="工号"
            width="180"
          />
          <el-table-column
            v-if="state.tableType != 2"
            prop="deptName"
            label="科室"
            width="180"
          />
          <el-table-column
            prop="assessmentModelName"
            label="考核模板"
            width="300"
          />
          <el-table-column prop="name" label="更新时间" width="150" sortable>
            <template #default="{ row }">
              {{ dayjs(row.updateTime).format("YYYY-MM-DD HH:mm:ss") }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" fixed="right">
            <template #default="{ row }">
              <!-- <el-button link :icon="Edit" /> -->
              <el-icon @click="GoView(row)">
                <View />
              </el-icon>
            </template>
          </el-table-column>
        </el-table>
        <div class="flex justify-between item-center">
          <div class="float-left mt-5 ml-2 total">
            <!-- 共{{ initParams.total }}条数据 -->
          </div>
          <div class="float-right mt-5 mr-8">
            <el-pagination
              v-model:current-page="initParams.objParams.pageNumber"
              v-model:page-size="initParams.objParams.pageSize"
              background
              layout="total, sizes, prev, pager, next, jumper"
              :total="initParams.total"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="考核指标" name="second">
        <div class="w-full flex items-center justify-between">
          <div class="w-1/2 flex items-center justify-between">
            <!-- <el-text class="w-1/5">考核模板</el-text> -->
            <el-select
              v-model="initParams.indexParams.modelName"
              placeholder="请选择考核模板"
              filterable
              clearable
              style="width: 400px"
              @change="getAssessmentQuotaDetailsApi"
            >
              <el-option
                v-for="itemTmp in initParams.tmpList"
                :key="itemTmp.id"
                :label="itemTmp.assessmentModelName"
                :value="itemTmp.assessmentModelName"
              />
            </el-select>
            <el-input
              v-model="initParams.indexParams.userName"
              class="ml-1"
              placeholder="搜索"
              @change="getAssessmentQuotaDetailsApi"
            />
            <el-input
              v-model="initParams.indexParams.quotaName"
              class="ml-2"
              placeholder="搜索指标名称"
              :prefix-icon="Search"
              @change="getAssessmentQuotaDetailsApi"
            />
          </div>
          <!-- <div class="-mr-">
            <el-button type="primary" plain @click="automaticCollectionApi"
              >同步最新数据</el-button
            >
          </div> -->
          <div class="mr-10 flex items-center justify-between">
            <el-button
              type="primary"
              plain
              :disabled="bistatus == 0"
              @click="deleteMantList"
              >批量删除</el-button
            >
            <el-button
              type="primary"
              :disabled="bistatus == 0"
              plain
              @click="automaticCollectionApi"
              >{{ bistatus == 0 ? "正在同步中..." : "同步最新数据" }}</el-button
            >
            <Auth :value="['批量导入指标']">
              <el-button
                type="primary"
                plain
                :disabled="bistatus == 0"
                @click="addsImport"
                >批量导入</el-button
              >
            </Auth>
          </div>
        </div>
        <vxe-table
          ref="tableVxeRef"
          class="mt-3"
          show-overflow
          keep-source
          :edit-config="editConfig"
          :edit-rules="validRules"
          :data="initParams.Indexlist"
          @edit-closed="editClosedEvent"
          @checkbox-change="selectChangeEvent"
          @checkbox-all="selectAllChangeEvent"
          @selection-change="changeSelection"
          @edit-disabled="editDisabledEvent"
        >
          <vxe-column type="checkbox" width="60" />
          <vxe-column
            v-if="state.tableType == 0 || state.tableType == 3"
            field="realName"
            fixed
            title="人员"
            width="100"
          />
          <!-- :员工,1:部门,2:医疗组,3:部门负责人 -->
          <vxe-column
            v-if="state.tableType == 0 || state.tableType == 3"
            field="userName"
            fixed
            title="工号"
            width="180"
          />
          <vxe-column
            v-if="state.tableType == 0 || state.tableType == 3"
            field="deptName"
            fixed
            title="部门"
            width="180"
          />
          <vxe-column
            v-if="state.tableType == 2"
            field="userGroupName"
            fixed
            title="医疗组"
            width="180"
          />
          <vxe-column
            v-if="state.tableType == 2"
            field="userGroupHospitalCode"
            fixed
            title="医疗组编号"
            width="180"
          />
          <vxe-column
            v-if="state.tableType == 1"
            field="deptName"
            fixed
            title="部门"
            width="180"
          />
          <vxe-column
            v-if="state.tableType == 1"
            field="deptHospitalCode"
            fixed
            title="部门编号"
            width="200"
          />
          <vxe-column
            field="assessmentModelName"
            fixed
            title="考核模板"
            width="180"
          />
          <vxe-column field="name" fixed title="指标名称" width="180" />
          <vxe-column field="scoreRule" fixed title="评价标准" width="180" />
          <vxe-column field="source" fixed title="数据来源" width="180" />
          <vxe-column
            field="targetValue"
            fixed
            title="目标值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          />
          <vxe-column
            field="addValue"
            fixed
            title="增幅"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.addValue }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="decValue"
            fixed
            title="降幅"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.decValue }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="challengeValue"
            fixed
            title="挑战值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.challengeValue }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="startValue"
            fixed
            title="门槛值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.startValue }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="upperValue"
            fixed
            title="上期完成值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.upperValue }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="agupperValue"
            fixed
            title="上上期完成值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.agupperValue }}
              </div>
            </template>
          </vxe-column>

          <vxe-column
            field="finalValue"
            fixed
            title="完成值"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ convertToNumberIfPercentage(row.finalValue) }}
              </div>
            </template>
          </vxe-column>

          <vxe-column
            field="score"
            fixed
            title="得分"
            :edit-render="{
              name: 'input',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.score }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="remark"
            fixed
            title="备注"
            :edit-render="{
              name: 'textarea',
              enabled: bistatus == 0 ? false : true
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.remark }}
              </div>
            </template>
          </vxe-column>
          <vxe-column field="updateTime" title="更新时间" sortable width="180">
            <template #default="{ row }">
              {{ dayjs(row.updateTime).format("YYYY-MM-DD HH:mm:ss") }}
            </template>
          </vxe-column>
          <vxe-column field="" title="操作" fixed="right" width="180">
            <template #header>
              操作
              <!-- 在表头操作后面添加图标 -->
              <el-dropdown placement="top-start" trigger="click">
                <el-icon class="mt-1 w-20 h-10">
                  <Setting />
                </el-icon>
                <template #dropdown>
                  <el-dropdown-menu>
                    <div class="w-[200px] p-1">
                      <div class="mt-2">
                        <el-text class="mx-1">表头设置</el-text>
                      </div>
                      <el-text type="info" size="small">可配置字段</el-text>
                      <div class="w-full">
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">目标值</el-text>
                          </div>
                          <el-switch
                            v-model="showTargetValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">增幅</el-text>
                          </div>
                          <el-switch
                            v-model="showAddValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">降幅</el-text>
                          </div>
                          <el-switch
                            v-model="showDecValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">挑战值</el-text>
                          </div>
                          <el-switch
                            v-model="showChallengeValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">门槛值</el-text>
                          </div>
                          <el-switch
                            v-model="showStartValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small"
                              >上期完成值</el-text
                            >
                          </div>
                          <el-switch
                            v-model="showUpperValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small"
                              >上上期完成值</el-text
                            >
                          </div>
                          <el-switch
                            v-model="showAgupperValueSwitch"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                        <div class="w-full flex justify-evenly items-center">
                          <div class="w-24">
                            <el-text type="info" size="small">备注</el-text>
                          </div>
                          <el-switch
                            v-model="remarkValueValue"
                            size="small"
                            class="ml-2"
                            :disabled="bistatus == 0"
                          />
                        </div>
                      </div>
                    </div>
                    <el-dropdown-item>
                      <div class="mt-4 ml-20 mb-2 flex float-right">
                        <el-tag effect="light" class="mr-3" size="small"
                          >取消</el-tag
                        >
                        <el-tag
                          effect="dark"
                          size="small"
                          type="primary"
                          @click="setTableHeaderApi"
                          >确认</el-tag
                        >
                      </div>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>
            <template #default="{ row }">
              <div class="w-5 h-5">
                <img :src="iconEdit" alt="" @click="editIndexOpen(row)" />
              </div>
              <!-- <el-icon @click="editIndexOpen(row)">
                <Edit />
              </el-icon> -->
            </template>
          </vxe-column>
        </vxe-table>
        <div class="flex justify-between item-center">
          <div class="float-left mt-5 ml-2 total">
            <!-- 共{{ initParams.total1 }}条数据 -->
          </div>
          <div class="float-right mt-5 mr-8">
            <el-pagination
              v-model:current-page="initParams.indexParams.pageNumber"
              v-model:page-size="initParams.indexParams.pageSize"
              background
              layout="total, sizes, prev, pager, next, jumper"
              :total="initParams.total1"
              @size-change="handleSizeIndexChange"
              @current-change="handleCurrentIndexChange"
            />
          </div>
        </div>
      </el-tab-pane>
      <!-- <el-tab-pane label="统计分析" name="third">
      </el-tab-pane> -->
      <el-tab-pane label="基础信息" name="fourth">
        <!-- 延迟加载获取id -->
        <messagePerson
          v-if="messageData.id"
          :id="messageData.id"
          :bistatus="bistatus"
        />
      </el-tab-pane>
    </el-tabs>
    <!-- 添加被考核人 -->
    <el-dialog
      v-model="dialogVisibleAdd"
      :title="changTitle()"
      width="500"
      :before-close="closePerson"
    >
      <div>
        <el-form
          ref="ruleFormRef"
          label-position="top"
          label-width="auto"
          :model="addPersonParams"
          :rules="addPersonParamsRules"
        >
          <el-form-item
            v-if="$props.message.assessmentType == 0"
            label="人员"
            label-position="top"
            prop="value1"
          >
            <el-tree-select
              ref="assessmentTypeRef"
              v-model="addPersonParams.value1"
              :data="convertDepartmentDataRecursive_Person(treeDept)"
              multiple
              :render-after-expand="false"
              show-checkbox
              @check-change="handleRreeSelect"
            />
          </el-form-item>
          <el-form-item
            v-else-if="$props.message.assessmentType == 1"
            label="科室"
            label-position="top"
            prop="value1"
          >
            <el-tree-select
              ref="assessmentTypeRef"
              v-model="addPersonParams.value1"
              :data="dpetTree"
              multiple
              check-strictly
              :render-after-expand="false"
              show-checkbox
              @check-change="handleRreeSelect"
            />
          </el-form-item>
          <el-form-item
            v-else-if="$props.message.assessmentType == 2"
            label="医疗组"
            label-position="top"
            prop="value1"
          >
            <el-select
              ref="selectRefs"
              v-model="addPersonParams.value1"
              multiple
              @change="handChange"
            >
              <el-option
                v-for="(it, id) in treeDeptList"
                :key="id"
                :label="it.groupName"
                :value="it.groupCode"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            v-else-if="$props.message.assessmentType == 3"
            label="人员"
            label-position="top"
            prop="value1"
          >
            <el-select
              ref="selectRefs"
              v-model="addPersonParams.value1"
              multiple
              @change="handChange"
            >
              <el-option
                v-for="(it, id) in treeDeptList"
                :key="id"
                :label="it.realName"
                :value="it.userCode"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            label="考核模板"
            label-position="top"
            prop="modulesValue"
          >
            <el-select
              v-model="addPersonParams.modulesValue"
              @change="handleModulesSelect"
            >
              <el-option
                v-for="itemTmp in modulesList"
                :key="itemTmp.id"
                :label="itemTmp.tpName"
                :value="itemTmp.id"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer w-full flex justify-between mt-4">
          <div>
            <el-button @click="closePerson">取消</el-button>
            <el-button type="primary" @click="addPerson"> 确认 </el-button>
          </div>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped>
.bg-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  margin-right: 5px;
  background: #00a870;
  border-radius: 5px;

  div {
    // border: 1px solid red;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60%;
    height: 60%;
    color: #00a870;
    background: #fff;
    border-radius: 2px;
  }
}
</style>
