| | |
| | | }); |
| | | this.params.visible = false; |
| | | }, |
| | | initData(tenantId) { |
| | | // 读取部门列表 |
| | | getDeptTree(tenantId) |
| | | .then(res => { |
| | | let deptList = []; |
| | | _.cloneDeep(res.data.data).forEach(item => { |
| | | deptList.push(item); |
| | | if (item.children) { |
| | | item.children.forEach(ic => { |
| | | ic.title = item.title + '/' + ic.title; |
| | | }) |
| | | deptList = deptList.concat(item.children); |
| | | delete item.children; |
| | | } |
| | | }); |
| | | return { |
| | | deptList, |
| | | }; |
| | | }) |
| | | .then(({ deptList }) => { |
| | | const depts_list = _.cloneDeep(deptList); |
| | | this.depts = []; |
| | | depts_list.forEach(dept => { |
| | | getList(1, 99999, {}, dept.id).then(employeeRes => { |
| | | const { records } = employeeRes.data.data; |
| | | this.depts.push({ |
| | | deptId: dept.id, |
| | | deptName: dept.title, |
| | | users: [], |
| | | employees: records |
| | | }); |
| | | this.setDefaultValue(this.depts); |
| | | }); |
| | | }); |
| | | }); |
| | | }, |
| | | setDefaultValue(depts) { |
| | | const params = _.cloneDeep(this.params.addForm.candidateNum) || [] |
| | | const newParams = params.map(item => { |
| | | const value = depts.find(dept => item.deptId === dept.deptId); |
| | | item.employees = value?.employees || []; |
| | | return item |
| | | async initData(tenantId) { |
| | | const deptTreeRes = await getDeptTree(tenantId) |
| | | let deptList = [] |
| | | const cloneDeptTreeRes = _.cloneDeep(deptTreeRes.data.data) |
| | | // 扁平化deptTree |
| | | cloneDeptTreeRes.forEach(item => { |
| | | deptList.push(item); |
| | | if (item.children) { |
| | | item.children.forEach(ic => { |
| | | ic.title = item.title + '/' + ic.title; |
| | | }) |
| | | deptList = deptList.concat(item.children); |
| | | delete item.children; |
| | | } |
| | | }) |
| | | this.selectGroup = newParams |
| | | const depts_list = _.cloneDeep(deptList) |
| | | depts_list.forEach(async (dept) => { |
| | | const employeeRes = await getList(1, 99999, {}, dept.id) |
| | | const { records } = employeeRes.data.data |
| | | this.depts.push({ |
| | | deptId: dept.id, |
| | | deptName: dept.title, |
| | | users: [], |
| | | employees: records |
| | | }); |
| | | const params = _.cloneDeep(this.params.addForm.candidateNum) || [] |
| | | const newParams = params.map(item => { |
| | | const value = this.depts.find(dept => item.deptId === dept.deptId); |
| | | item.employees = value?.employees || []; |
| | | return item |
| | | }) |
| | | // 宏任务延迟 |
| | | setTimeout(() => { |
| | | const params = newParams.filter(item => item.employees.length > 0) |
| | | this.selectGroup = params |
| | | }, 100) |
| | | }); |
| | | }, |
| | | handleEmployeeChange(val, content) { |
| | | if (val) { |