<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 { getTemplateInfoList } from "@/api/templateInfo";
import { useRouter } from "vue-router";
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";
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 } = department;
    return {
      value: userCodeNew,
      label: userNameNew,
      children:
        children.length > 0
          ? children.map(
              child => convertDepartmentDataRecursive_Person([child])[0]
            )
          : []
    };
  });
};
// 转换函数 --- 部门
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();
});
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) {
    console.log("指标分页查询", res);
    initParams.Indexlist = res.data.records;
    initParams.total1 = res.data.totalRow;
    alterFinishValueApi();
    getAssessmentDetailsApi(); // 获取考核指标详情表头信息
  }
};
// 考核模板
const modulesList = ref([]);
const getTemplateInfoListApi = async () => {
  const { data, code } = await getTemplateInfoList({
    page: 1,
    pageSize: 100
  });
  if (code == 200) {
    modulesList.value = data.records || [];
  }
};
const modulesValue = ref("");
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: ""
});
// 添加被考核人
const value1 = ref();
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;
  console.log("data", data);
  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 = data => {
  const list = ref({});
  let dataList;
  // console.log("data", data);
  if ($props.message.assessmentType == 0) {
    if (Array.isArray(data)) {
      dataList = flattenTree(data);
      dataList.map(item => {
        if (item.value.substring(0, 4) == "user") {
          addPersonParams.objectAddVoList.push({
            assessmentObjectId: item.value,
            assessmentObjectName: item.label
          });
        }
      });
    } else {
      addPersonParams?.objectAddVoList?.push({
        assessmentObjectId: data.value,
        assessmentObjectName: data.label
      });
    }
  }
  const arr = assessmentTypeRef.value.getCheckedNodes().filter(item => {
    return item.children.length == 0;
  });
  list.value.assessmentObjectId = arr.map(item => item.value);
  list.value.assessmentObjectName = arr.map(item => item.label);
  // addPersonParams.objectAddVoList = transformArrayFormat(list);
};
// 医疗 --- 医疗主任
const handChange = data => {
  console.log("data", 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 value1.value.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,
      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
});
// 编辑前面
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
  });
  console.log("hangdleOpenClick", row);
  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;
    // 判断表头
    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;
          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;
          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;
          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;
          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;
          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;
          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;
          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;
          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;
          updateAssessmentQuotaDetailsApi(editVxe);
        }
      }
    }
  }
};

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

// 添加被考核人
const addPerson = async () => {
  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(addPersonParams);
  if (code === 200) {
    ElMessage.success("添加成功");
    dialogVisibleAdd.value = false;
    getAssessmentObjectDetailsApi();
    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("同步数据成功");
  } else {
    ElMessage.error(msg);
  }
};
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
});
const showAssessmentHeader = reactive({
  showTargetValue: 1,
  showChallengeValue: 0,
  showStartValue: 0,
  showAddValue: 0,
  showDecValue: 0,
  showUpperValue: 0,
  showAgupperValue: 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 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");
    Object.assign(showAssessmentHeader, aa);
    ElMessage.success("表头设置成功");
  } else {
    ElMessage.error(msg);
  }
};
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;
    let aa = JSON.parse(JSON.stringify(assessmentHeader));
    console.log(111111, 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");
    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) => {
  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" />
    <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" @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 @click="delAssessmentObjectApi">
                批量删除
              </el-button>
            </Auth>
            <Auth :value="['添加被考核人']">
              <el-button type="primary" plain @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 @click="deleteMantList"
              >批量删除</el-button
            >
            <el-button type="primary" plain @click="automaticCollectionApi"
              >同步最新数据</el-button
            >
            <Auth :value="['批量导入指标']">
              <el-button type="primary" plain @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'
            }"
            width="180"
          />
          <vxe-column
            field="addValue"
            fixed
            title="增幅"
            :edit-render="{
              name: 'input'
            }"
            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'
            }"
            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'
            }"
            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'
            }"
            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'
            }"
            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'
            }"
            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'
            }"
            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'
            }"
            width="180"
          >
            <template #default="{ row }">
              <div @click="hangdleOpenClick(row)">
                {{ row.score }}
              </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"
                          />
                        </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"
                          />
                        </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"
                          />
                        </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"
                          />
                        </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"
                          />
                        </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"
                          />
                        </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"
                          />
                        </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 }">
              <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" />
      </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"
        >
          <el-form-item
            v-if="$props.message.assessmentType == 0"
            label="人员"
            label-position="top"
          >
            <el-tree-select
              ref="assessmentTypeRef"
              v-model="value1"
              :data="convertDepartmentDataRecursive_Person(treeDept)"
              multiple
              :render-after-expand="false"
              show-checkbox
              style="width: 240px"
              @check-change="handleRreeSelect"
            />
          </el-form-item>
          <el-form-item
            v-else-if="$props.message.assessmentType == 1"
            label="科室"
            label-position="top"
          >
            <el-tree-select
              ref="assessmentTypeRef"
              v-model="value1"
              :data="dpetTree"
              multiple
              :render-after-expand="false"
              show-checkbox
              style="width: 240px"
              @check-change="handleRreeSelect"
              @check="handleNodeRreeSelect"
            />
          </el-form-item>
          <el-form-item
            v-else-if="$props.message.assessmentType == 2"
            label="医疗组"
            label-position="top"
          >
            <el-select
              ref="selectRefs"
              v-model="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"
          >
            <el-select
              ref="selectRefs"
              v-model="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">
            <el-select v-model="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>
