|
|
|
@ -5,6 +5,8 @@ |
|
|
|
--> |
|
|
|
<script lang='ts' setup> |
|
|
|
import { getgovcont } from '@/api/hr/org/index' |
|
|
|
import { orgInfo } from "@/api/hr/org/type"; |
|
|
|
import { getOrgTreeList } from "@/api/hr/org/index"; |
|
|
|
const props = defineProps({ |
|
|
|
orgid:{ |
|
|
|
type: String, |
|
|
|
@ -25,29 +27,21 @@ const pickOrgVal = (val:any) => { |
|
|
|
if(val != "" && val != null){ |
|
|
|
if(hasComma(val)){ |
|
|
|
|
|
|
|
let arr = commaStringToNumberArray(val) |
|
|
|
let str= '' |
|
|
|
arr.forEach((element, index, array) => { |
|
|
|
// 判断当前是否是最后一个元素 |
|
|
|
const isLast = index === array.length - 1; |
|
|
|
str = '' |
|
|
|
|
|
|
|
let item = element+"" |
|
|
|
getgovcont({id:element*1,idstr:item}) |
|
|
|
.then(({data}) =>{ |
|
|
|
str+=data.name+"," |
|
|
|
}) |
|
|
|
.finally(()=>{ |
|
|
|
if(isLast){ |
|
|
|
//alert(1) |
|
|
|
str = removeLastChar(str) |
|
|
|
orgName.value = str |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const interval = setInterval(() => { |
|
|
|
// 检查ref对象的值是否为false |
|
|
|
if (!orgTreeLoading.value) { |
|
|
|
|
|
|
|
}) |
|
|
|
clearInterval(interval); |
|
|
|
let str= '' |
|
|
|
str = replaceOrgIdWithName(val,orgTreeList.value) |
|
|
|
orgName.value = str |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
}, 200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
@ -120,12 +114,77 @@ function commaStringToNumberArray(str: string) { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const orgTreeLoading = ref(true); //加载行政组织树 |
|
|
|
onBeforeMount(() => { |
|
|
|
pickOrgVal(props.orgid) |
|
|
|
//pickOrgVal(props.orgid) |
|
|
|
getOrgTreeList({ orgid: 309 }) |
|
|
|
.then(({ data }) => { |
|
|
|
console.log("行政组织树对照值", data); |
|
|
|
|
|
|
|
orgTreeList.value = data; |
|
|
|
}) |
|
|
|
.finally(() => { |
|
|
|
orgTreeLoading.value = false; |
|
|
|
}); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 2. 核心方法:输入ID逗号字符串,返回名称逗号字符串 |
|
|
|
* @param {string} idStr - 逗号分隔的ID字符串(如 "102,103") |
|
|
|
* @returns {string} 逗号分隔的名称字符串(如 "企管部,IT") |
|
|
|
*/ |
|
|
|
function replaceOrgIdWithName(idStr: string,orgTreeData: any) { |
|
|
|
// 边界处理:输入为空或非字符串时返回空 |
|
|
|
if (!idStr || typeof idStr !== "string") { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
// 步骤1:构建ID→名称的映射表(高效查找) |
|
|
|
const idToNameMap = {}; |
|
|
|
// 递归遍历所有树形节点,收集ID和名称 |
|
|
|
function traverseNodes(nodes: any[]) { |
|
|
|
// 防止节点为空(如child: null) |
|
|
|
if (!nodes || !nodes.length) return; |
|
|
|
|
|
|
|
nodes.forEach((node: { id: string | number; name: any; child: any; }) => { |
|
|
|
// 存储当前节点的ID和名称(ID用数字作为key,匹配原始数据类型) |
|
|
|
idToNameMap[node.id] = node.name; |
|
|
|
// 递归遍历子节点(处理多层级结构) |
|
|
|
traverseNodes(node.child); |
|
|
|
}); |
|
|
|
} |
|
|
|
// 初始化遍历(从根节点开始) |
|
|
|
traverseNodes(orgTreeData); |
|
|
|
|
|
|
|
// 步骤2:解析输入ID,替换为名称 |
|
|
|
const result = idStr |
|
|
|
.split(",") // 分割为ID数组(如 "102,103" → ["102", "103"]) |
|
|
|
.map(idItem => { |
|
|
|
const pureId = idItem.trim(); // 去除空格(兼容 "102, 103" 这类输入) |
|
|
|
const idNum = Number(pureId); // 转为数字(匹配原始数据的ID类型) |
|
|
|
// 找到名称则返回名称,未找到则保留原始ID(避免丢失无效ID) |
|
|
|
return idToNameMap[idNum] || pureId; |
|
|
|
}) |
|
|
|
.join(","); // 重新拼接为字符串 |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const orgTreeList = ref<orgInfo[]>(); |
|
|
|
//加载行政组织树 |
|
|
|
const orgTreeProps = { |
|
|
|
children: "child", |
|
|
|
label: "name", |
|
|
|
}; //行政组织树对照值 |
|
|
|
onMounted(() => { |
|
|
|
pickOrgVal(props.orgid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
watch(() =>props.orgid,(val:string) => { |
|
|
|
// console.log("选择行政组织-4->",val) |
|
|
|
|