const queryUnitList = () => {
return new Promise((resolve,reject) => {
getUnit()
.then(({ data }) => {
departList.value = data;
resolve(data);
})
.catch(error=>reject(error))
});
};
const queryList = () => {
if (name.value === "edit") {
getUserInfoByStaffNum({ staffNum: item.value.encryptStaffNum }).then(
({ data }) => {
Object.keys(ruleForm.value).map(
(key: string) => (ruleForm.value[key] = data[key])
);
ruleForm.value.sex = data.sex ? Number(data.sex) : "";
handleUnitId(departList.value);
}
);
}
};
onMounted(() => {
Promise.all([queryRoleList(), queryUnitList()]).then(() => {
queryList();
});
});
在编辑的时候下拉框数据做回显 没有对应id清空
<el-form-item label="部门:" prop="deptId">
<el-tree-select
filterable
check-strictly
style="width: 100%"
v-model="ruleForm.deptId"
:data="departList"
popper-class="own_select"
:props="defaultProps"
/>
</el-form-item>
const defaultProps = {
children: "children",
label: "name",
value: "id",
};
const handleUnitId = (data: any) => {
let a = "";
let b = (data: any) => {
data.forEach((i: any) => {
if (i.id === ruleForm.value.deptId) {
a = i.id;
}
if (i.children) {
b(i.children);
}
});
};
b(data);
a === "" ? (ruleForm.value.deptId = "") : (ruleForm.value.deptId = a);
re