Selaa lähdekoodia

fix: 人员树

“ystl_myq” 1 viikko sitten
vanhempi
commit
c71c17773a

+ 51 - 66
src/api/department.ts

@@ -35,74 +35,59 @@ export const postListTreeWithUser = () => {
 export const treeDept = ref([]);
 export const postListTreeWithUserApi = async () => {
   const res = await postListTreeWithUser();
-  treeDept.value = transformData(res.data);
-  console.log("treeDept.value", transformData(res.data));
-  console.log("treeDept", res.data);
+  let treeList = res.data.map(item => {
+    return {
+      childrenRes: item.childrenRes,
+      childrenUserRes: item.childrenUserRes,
+      userCodeNew: item.deptCode,
+      userNameNew: item.deptName
+    };
+  });
+  treeDept.value = transformData(treeList);
+  // console.log("treeDept.value", transformData(treeList));
+  // console.log("treeDept", res.data);
 };
-// const transformData = data => {
-//   return data.map(item => {
-//     // 新的结构
-//     const newItem = {
-//       userName: item.deptName || item.realName, // 使用deptName或userName
-//       userCode: item.deptCode || item.userCode, // 使用deptCode或userCode
-//       children: [] // 初始化children数组
-//     };
+function transformData(
+  data,
+  newDeptCodeKey = "userCodeNew",
+  newDeptNameKey = "userNameNew"
+) {
+  return data.map(item => {
+    const newItem = { ...item };
 
-//     // 合并childrenRes和childrenUserRes
-//     const childrenRes = item.childrenRes ? transformData(item.childrenRes) : [];
-//     const childrenUserRes = item.childrenUserRes
-//       ? item.childrenUserRes.map(user => ({
-//           userName: user.userName,
-//           userCode: user.userCode
-//         }))
-//       : [];
+    // 合并 childrenUserRes 和 childrenRes,并添加类型标识
+    newItem.children = [
+      ...(newItem.childrenUserRes || []).map(child => ({
+        ...child,
+        type: "user"
+      })),
+      ...(newItem.childrenRes || []).map(child => ({ ...child, type: "dept" }))
+    ];
+    delete newItem.childrenUserRes;
+    delete newItem.childrenRes;
 
-//     newItem.children = [...childrenRes, ...childrenUserRes]; // 合并两个子项
-
-//     return newItem; // 返回处理后的新对象
-//   });
-// };
-const transformData = data => {
-  // 检查data是否存在且是数组且长度大于0
-  if (Array.isArray(data) && data.length > 0) {
-    return data.map(item => {
-      let newItem = {
-        userNameNew: item.realName || item.deptName || "", // 优先使用realName,其次使用deptName
-        userCodeNew: item.userCode || item.deptCode || "", // 优先使用userCode,其次使用deptCode
-        children: [] // 初始化children为一个空数组
-      };
-
-      // 确保childrenUserRes和childrenRes存在
-      const childrenUserRes = Array.isArray(item.childrenUserRes)
-        ? item.childrenUserRes
-        : [];
-      const childrenRes = Array.isArray(item.childrenRes)
-        ? item.childrenRes
-        : [];
-
-      // 处理子部门
-      const renRes = childrenRes.map(itEes => ({
-        userNameNew: itEes.deptName || "", // 使用deptName
-        userCodeNew: itEes.deptCode || "", // 使用deptCode
-        children: transformData(itEes.childrenRes) // 递归处理子部门
-      }));
-
-      // 处理用户
-      const userRes = childrenUserRes.map(itEes => ({
-        userNameNew: itEes.realName || "", // 使用realName
-        userCodeNew: itEes.userCode || "", // 使用userCode
-        jobTitle: itEes.jobTitle || "", // 包含职位信息
-        hospitalCode: itEes.hospitalCode || "", // 包含医院代码
-        children: transformData(itEes.childrenUserRes) // 递归处理用户子项
-      }));
-
-      // 合并两个子项
-      newItem.children = [...renRes, ...userRes];
-
-      return newItem; // 返回新的结构
+    // 重命名属性
+    newItem.children = newItem.children.map(child => {
+      const newChild = { ...child };
+      if (child.type === "user") {
+        newChild.userNameNew = child.realName;
+        newChild.userCodeNew = child.userCode;
+      } else if (child.type === "dept") {
+        newChild[newDeptCodeKey] = child.deptCode;
+        newChild[newDeptNameKey] = child.deptName;
+      }
+      return newChild;
     });
-  }
 
-  // 如果数据无效,返回空数组
-  return [];
-};
+    // 递归处理子节点
+    if (newItem.children && newItem.children.length) {
+      newItem.children = transformData(
+        newItem.children,
+        newDeptCodeKey,
+        newDeptNameKey
+      );
+    }
+
+    return newItem;
+  });
+}

+ 2 - 2
src/views/background/framework/roles/components/addPerson.vue

@@ -67,8 +67,8 @@ const filterNode = (value: string, data: any) => {
 };
 
 const defaultProps = {
-  label: "userName",
-  value: "userCode",
+  label: "userNameNew",
+  value: "userCodeNew",
   children: "children"
 };
 </script>

+ 2 - 2
src/views/background/framework/users/components/addPerson.vue

@@ -42,8 +42,8 @@ const postAssignmentUserApi = async () => {
 };
 // 树选择
 const defaultProps = {
-  label: "userName",
-  value: "userCode",
+  label: "userNameNew",
+  value: "userCodeNew",
   children: "children"
 };
 const tree = ref(null);

+ 20 - 41
src/views/evaluate/children/change/manage/addExam.vue

@@ -4,7 +4,12 @@ import { ElMessageBox, ElMessage } from "element-plus";
 import { Calendar } from "@element-plus/icons-vue";
 import dayjs from "dayjs";
 import { postAddAssessment } from "@/api/assessment";
-import { postListTreeWithUser, postListTree } from "@/api/department";
+import {
+  postListTreeWithUser,
+  postListTree,
+  postListTreeWithUserApi,
+  treeDept
+} from "@/api/department";
 import { encryption } from "@/utils/encrypt";
 // 人员,医疗组,负责人
 import {
@@ -189,47 +194,21 @@ const monthOne = item => {
   // return `从 ${start} 到 ${end}`; // 设置时间区间
 };
 // 部门人员与考核模板数据
-const treeDept = ref([]);
+const treeDeptList = ref([]);
 const templateparams = reactive({
   page: 1,
   pageSize: 100
 });
 const resTmp = ref([]);
-const postListTreeWithUserApi = async () => {
-  const res = await postListTreeWithUser();
-
-  console.log("人员", res.data);
-  console.log("人员", transformData(res.data));
-  treeDept.value = [];
-  let aa = res.data;
-  treeDept.value = transformData(aa);
-};
-
-const transformData = data => {
-  return data.map(item => {
-    const transformedItem = {
-      deptName: item.userName || item.deptName,
-      deptCode: item.userCode || item.deptCode,
-      children: []
-    };
+// const postListTreeWithUserApi = async () => {
+//   const res = await postListTreeWithUser();
 
-    if (item.childrenRes) {
-      transformedItem.children = transformData(item.childrenRes);
-    }
-
-    if (item.childrenUserRes) {
-      item.childrenUserRes.forEach(user => {
-        transformedItem.children.push({
-          deptName: user.userName,
-          deptCode: user.userCode,
-          children: []
-        });
-      });
-    }
-
-    return transformedItem;
-  });
-};
+//   console.log("人员", res.data);
+//   console.log("人员", transformData(res.data));
+//   treeDept.value = [];
+//   let aa = res.data;
+//   treeDept.value = transformData(aa);
+// };
 const assessmentTypeRef = ref();
 const handleRreeSelect = index => {
   const node = assessmentTypeRef.value[index].getCheckedNodes();
@@ -279,12 +258,12 @@ const assessmentTypeApi = async value => {
         pageNumber: 1,
         pageSize: 1000
       });
-      treeDept.value = yiliao.data.records;
+      treeDeptList.value = yiliao.data.records;
       break;
     case 3:
       const fuzhere = await getLeaderList();
       console.log(fuzhere);
-      treeDept.value = fuzhere.data;
+      treeDeptList.value = fuzhere.data;
   }
 };
 const monthTime = ref("");
@@ -424,8 +403,8 @@ defineExpose({
                       :render-after-expand="false"
                       show-checkbox
                       :props="{
-                        label: 'deptName',
-                        value: 'deptCode',
+                        label: 'userNameNew',
+                        value: 'userCodeNew',
                         children: 'children'
                       }"
                       style="width: 180px"
@@ -454,7 +433,7 @@ defineExpose({
                       @change="handChange"
                     >
                       <el-option
-                        v-for="(it, id) in treeDept"
+                        v-for="(it, id) in treeDeptList"
                         :key="id"
                         :label="it.realName"
                         :value="it.userCode"

+ 2 - 2
src/views/evaluate/children/change/mould/manageObject.vue

@@ -499,8 +499,8 @@ const editClosedEvent = ({ row, column }) => {
               :data="treeDept"
               multiple
               :props="{
-                label: 'userName',
-                value: 'userCode',
+                label: 'userNameNew',
+                value: 'userCodeNew',
                 children: 'children'
               }"
               :render-after-expand="false"