| | |
| | | // 监听 record 变化,更新表单数据 |
| | | watch(() => props.record, (newRecord) => { |
| | | if (newRecord && isShow.value) { |
| | | const userPowerNames = newRecord.userPower ? newRecord.userPower.split(',') : []; |
| | | const userPowerIds = userPowerNames.map(name => { |
| | | const user = findUserByName(name); |
| | | return user ? user.id : null; |
| | | }).filter(id => id !== null); |
| | | |
| | | formState.value = { |
| | | id: newRecord.id, |
| | | name: newRecord.name || '', |
| | |
| | | remark: newRecord.remark || '', |
| | | salaryQuota: newRecord.salaryQuota || '', |
| | | isQuality: newRecord.isQuality, |
| | | userPower: userPowerIds, |
| | | userPower: [], |
| | | }; |
| | | |
| | | // 等待 staffList 加载完成后,再查找用户ID |
| | | if (staffList.value.length > 0) { |
| | | setUserPowerIds(newRecord.userPower); |
| | | } else { |
| | | // staffList 还没加载,等待一下再查找 |
| | | const checkStaffList = () => { |
| | | if (staffList.value.length > 0) { |
| | | setUserPowerIds(newRecord.userPower); |
| | | } else { |
| | | setTimeout(checkStaffList, 100); |
| | | } |
| | | }; |
| | | checkStaffList(); |
| | | } |
| | | } |
| | | }, { immediate: true, deep: true }); |
| | | |
| | | // 根据用户名查找用户ID |
| | | const setUserPowerIds = (userPowerStr) => { |
| | | const userPowerNames = userPowerStr ? userPowerStr.split(',') : []; |
| | | const userPowerIds = []; |
| | | const findUserIds = (nodes, targetName) => { |
| | | nodes.forEach(node => { |
| | | if (node.isUser && node.label === targetName) { |
| | | userPowerIds.push(node.id); |
| | | } |
| | | if (node.children && node.children.length > 0) { |
| | | findUserIds(node.children, targetName); |
| | | } |
| | | }); |
| | | }; |
| | | userPowerNames.forEach(name => { |
| | | findUserIds(staffList.value, name); |
| | | }); |
| | | formState.value.userPower = userPowerIds; |
| | | }; |
| | | |
| | | let { proxy } = getCurrentInstance() |
| | | |
| | | const closeModal = () => { |