浏览代码

fix: 部门控件返回 部门名而不是部门id

ZhaoJun 1 年之前
父节点
当前提交
749d7a1815
共有 1 个文件被更改,包括 21 次插入1 次删除
  1. 21 1
      src/components/DDComponents/DepartmentField/index.js

+ 21 - 1
src/components/DDComponents/DepartmentField/index.js

@@ -28,8 +28,28 @@ function DepartmentField(props) {
   //   }
   // };
 
+  const findDepName = (list, ID) => {
+    let result = '';
+    const dep = list.find(item => item.ID === ID);
+    if (dep) {
+      result = dep.Name;
+      return result;
+    }
+    for (let index = 0; index < list.length; index++) {
+      const element = list[index];
+      if (element?.children && element?.children.length) {
+        result = findDepName(element.children, ID);
+        if (result) {
+          break;
+        }
+      }
+    }
+    return result;
+  };
+
   const onChangeValue = newValue => {
-    onChange(`${newValue}`);
+    const depName = findDepName(depUserTree, newValue);
+    onChange(depName);
   };
 
   return (