| | |
| | | |
| | | const emit = defineEmits(['success']); |
| | | const formType = ref<FormType>('create'); |
| | | const currentEmployeeId = ref<number>(); |
| | | |
| | | // 员工简单列表做一次缓存,供「选中员工后带出原部门」使用 |
| | | let employeeCache: any[] = []; |
| | | async function loadEmployees() { |
| | | if (employeeCache.length === 0) { |
| | | employeeCache = await getEmployeeSimpleList(); |
| | | } |
| | | return employeeCache; |
| | | } |
| | | |
| | | const isDetail = computed(() => formType.value === 'detail'); |
| | | const getTitle = computed(() => { |
| | |
| | | layout: 'horizontal', |
| | | schema: [], |
| | | showDefaultActions: false, |
| | | // 选中「被调岗员工」后带出原部门/原岗位(仅用于展示; |
| | | // 真正的 currentDeptId / currentPostId 由后端按员工档案补全,避免非空约束报错) |
| | | handleValuesChange: async (values: any, fieldsChanged: string[]) => { |
| | | if (!fieldsChanged.includes('employeeId')) { |
| | | return; |
| | | } |
| | | const employees = await loadEmployees(); |
| | | const employee = employees.find((item: any) => item.id === values.employeeId); |
| | | if (!employee) { |
| | | return; |
| | | } |
| | | await formApi.setValues({ |
| | | currentDeptName: employee.deptName || '', |
| | | currentPostName: employee.postName || '', |
| | | }); |
| | | }, |
| | | }); |
| | | |
| | | const [Modal, modalApi] = useVbenModal({ |
| | |
| | | } |
| | | modalApi.lock(); |
| | | const data = (await formApi.getValues()) as HrmTransferApi.Transfer; |
| | | data.employeeId = currentEmployeeId.value; |
| | | try { |
| | | if (data.id) { |
| | | await updateTransfer(data); |
| | |
| | | formApi.setDisabled(data.formType === 'detail'); |
| | | modalApi.setState({ showConfirmButton: data.formType !== 'detail' }); |
| | | if (!data?.id) { |
| | | // 新增时,自动获取当前登录员工的部门和岗位信息 |
| | | const employees = await getEmployeeSimpleList(); |
| | | // TODO: 这里应该根据登录用户获取对应的员工信息,暂时取第一个员工作为示例 |
| | | const currentEmployee = employees[0]; |
| | | if (currentEmployee) { |
| | | currentEmployeeId.value = currentEmployee.id; |
| | | await formApi.setValues({ |
| | | currentDeptName: currentEmployee.deptName, |
| | | currentPostName: currentEmployee.postName, |
| | | }); |
| | | } |
| | | // 新增:被调岗员工由用户在表单里选择,选中后自动带出原部门/原岗位 |
| | | return; |
| | | } |
| | | modalApi.lock(); |
| | | try { |
| | | const transfer = await getTransfer(data.id); |
| | | currentEmployeeId.value = transfer.employeeId; |
| | | await formApi.setValues(transfer); |
| | | if (transfer.attachmentList?.length) { |
| | | await formApi.setFieldValue('blobIds', transfer.attachmentList.map(item => ({ |