From e047db3cbdd85e666f567f10c3b17dd887ae74f6 Mon Sep 17 00:00:00 2001 From: lh Date: Mon, 8 Dec 2025 14:12:56 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=91=A8=E6=8A=A5=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/user/index.ts | 13 +- src/enums/OAEnum.ts | 2 +- src/views/oa/erp/projectReport/edit.vue | 507 +++++++++++++++++++---- src/views/oa/erp/projectReport/index.vue | 320 +++++++++++++- 4 files changed, 751 insertions(+), 91 deletions(-) diff --git a/src/api/system/user/index.ts b/src/api/system/user/index.ts index 7c26320..f529e16 100644 --- a/src/api/system/user/index.ts +++ b/src/api/system/user/index.ts @@ -221,6 +221,16 @@ export const getUserList = (query: UserQuery): AxiosPromise => { }); }; +/** + * 根据部门id以及角色名查询用户下拉列表 + */ +export const listUserByDeptAndRole = (query: any): AxiosPromise => { + return request({ + url: '/system/user/listByDeptAndRole', + method: 'get', + params: query + }); +}; export default { listUser, @@ -239,5 +249,6 @@ export default { updateAuthRole, deptTreeSelect, listUserByDeptId, - getUserList + getUserList, + listUserByDeptAndRole }; diff --git a/src/enums/OAEnum.ts b/src/enums/OAEnum.ts index 4bc0d79..dc5512a 100644 --- a/src/enums/OAEnum.ts +++ b/src/enums/OAEnum.ts @@ -22,7 +22,7 @@ export enum CodeRuleEnum { */ AFTER_SALES = '1012', - PROJECT_REPORT = '1011' + PROJECT_REPORT = '1013' } /** diff --git a/src/views/oa/erp/projectReport/edit.vue b/src/views/oa/erp/projectReport/edit.vue index d1a4708..d70daa4 100644 --- a/src/views/oa/erp/projectReport/edit.vue +++ b/src/views/oa/erp/projectReport/edit.vue @@ -12,6 +12,8 @@ :pageType="routeParams.type" :mode="false" /> + + - + + + @@ -38,22 +50,22 @@ - + - + - + - + @@ -115,6 +127,8 @@ + + diff --git a/src/views/oa/erp/projectReport/index.vue b/src/views/oa/erp/projectReport/index.vue index 268d134..37d19be 100644 --- a/src/views/oa/erp/projectReport/index.vue +++ b/src/views/oa/erp/projectReport/index.vue @@ -7,7 +7,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -191,6 +319,9 @@ import { ProjectReportVO, ProjectReportQuery, ProjectReportForm } from '@/api/oa import { listProjectReport, getProjectReport, delProjectReport, addProjectReport, updateProjectReport } from '@/api/oa/erp/projectReport'; import ProjectSelect from '@/components/ProjectSelect/index.vue'; import { report } from 'process'; +import { fa } from 'element-plus/es/locale/index.mjs'; +import { allListDept, listDept } from '@/api/system/dept'; +import { listUserByDeptAndRole, listUserByDeptId } from '@/api/system/user'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; @@ -229,7 +360,7 @@ const columns = ref([ { key: 9, label: `周报情况说明`, visible: true }, { key: 10, label: `排序号`, visible: false }, { key: 11, label: `附件ID`, visible: true }, - { key: 12, label: `备注`, visible: true }, + { key: 12, label: `备注`, visible: false }, { key: 13, label: `激活标识`, visible: false }, { key: 14, label: `删除标志`, visible: false }, { key: 15, label: `创建部门`, visible: true }, @@ -284,12 +415,141 @@ const data = reactive>({ params: {} }, rules: { - projectName: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }] + projectName: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }], + projectCode: [{ required: true, message: '项目编码不能为空', trigger: 'blur' }] } }); const { queryParams, form, rules } = toRefs(data); +const deptList = ref([]); +const managerList = ref([]); +const chargeList = ref([]); +const deputyList = ref([]); +const loadingManagers = ref(false); +const loadingCharges = ref(false); +const loadingDeputies = ref(false); +const loadingUsers = ref(false); +// 获取部门列表 +const getDeptList = async () => { + try { + const res = await allListDept(); + deptList.value = res.data || []; + } catch (error) { + console.error('获取部门列表失败:', error); + deptList.value = []; + } +}; +// 获取项目经理列表 +const getManagers = async (deptId: number | string) => { + try { + loadingManagers.value = true; + const res = await listUserByDeptAndRole({ + deptId: deptId, + roleName: '' + }); + managerList.value = res.data || []; + } catch (error) { + console.error('获取项目经理列表失败:', error); + managerList.value = []; + } finally { + loadingManagers.value = false; + } +}; + +// 获取部门负责人列表 +const getCharges = async (deptId: number | string) => { + try { + loadingCharges.value = true; + const res = await listUserByDeptAndRole({ + deptId: deptId, + roleName: '' + }); + chargeList.value = res.data || []; + } catch (error) { + console.error('获取部门负责人列表失败:', error); + chargeList.value = []; + } finally { + loadingCharges.value = false; + } +}; + +// 获取分管副总列表 +const getDeputies = async (deptId: number | string) => { + try { + loadingDeputies.value = true; + const res = await listUserByDeptAndRole({ + deptId: deptId, + roleName: '' + }); + deputyList.value = res.data || []; + } catch (error) { + console.error('获取分管副总列表失败:', error); + deputyList.value = []; + } finally { + loadingDeputies.value = false; + } +}; +// 根据部门ID获取所有角色的用户列表 +const getUsersByDept = async (deptId: number | string) => { + if (!deptId) { + managerList.value = []; + chargeList.value = []; + deputyList.value = []; + return; + } + + try { + // 并行获取三个角色的用户 + await Promise.all([getManagers(deptId), getCharges(deptId), getDeputies(deptId)]); + } catch (error) { + console.error('获取用户列表失败:', error); + } +}; +// 部门选择变化时触发 +const handleDeptChange = async (deptId: number | string) => { + // 清空之前选择的用户 + form.value.managerId = undefined; + form.value.chargeId = undefined; + form.value.deputyId = undefined; + form.value.managerName = undefined; + form.value.chargeName = undefined; + form.value.deputyName = undefined; + + // 获取该部门的用户(按不同角色) + await getUsersByDept(deptId); + + // 更新部门名称 + const selectedDept = deptList.value.find((dept) => { + // 宽松比较,因为ID可能是字符串或数字 + return String(dept.deptId) === String(deptId) || String(dept.id) === String(deptId); + }); + if (selectedDept) { + form.value.deptName = selectedDept.deptName || selectedDept.label; + } +}; + +// 用户选择变化时更新对应名称 +const handleManagerChange = (userId: number | string) => { + const selectedUser = managerList.value.find((user) => String(user.userId) === String(userId)); + if (selectedUser) { + form.value.managerName = selectedUser.nickName || selectedUser.label; + } +}; + +const handleChargeChange = (userId: number | string) => { + const selectedUser = chargeList.value.find((user) => String(user.userId) === String(userId)); + if (selectedUser) { + form.value.chargeName = selectedUser.nickName || selectedUser.label; + } +}; + +const handleDeputyChange = (userId: number | string) => { + const selectedUser = deputyList.value.find((user) => String(user.userId) === String(userId)); + if (selectedUser) { + form.value.deputyName = selectedUser.nickName || selectedUser.label; + } +}; // 打开项目选择框 const openProjectSelect = () => { projectSelectRef.value.open(); @@ -360,6 +620,22 @@ const handleSelectionChange = (selection: ProjectReportVO[]) => { single.value = selection.length != 1; multiple.value = !selection.length; }; +/** 提交按钮 */ +const submitForm = () => { + projectReportFormRef.value?.validate(async (valid: boolean) => { + if (valid) { + buttonLoading.value = true; + if (form.value.reportId) { + await updateProjectReport(form.value).finally(() => (buttonLoading.value = false)); + } else { + await addProjectReport(form.value).finally(() => (buttonLoading.value = false)); + } + proxy?.$modal.msgSuccess('操作成功'); + dialog.visible = false; + await getList(); + } + }); +}; /** 新增按钮操作 */ const handleAdd = (row?: ProjectReportVO) => { reset(); @@ -409,7 +685,30 @@ const handleUpdate = async (row?: ProjectReportVO) => { reset(); const _reportId = row?.reportId || ids.value[0]; const res = await getProjectReport(_reportId); + + // 重置表单 + form.value = { ...initFormData }; Object.assign(form.value, res.data); + + console.log('编辑获取的数据:', res.data); + + // 获取部门对应的用户列表 + if (form.value.deptId) { + await getUsersByDept(form.value.deptId); + const a = listUserByDeptId(form.value.deptId); + console.log(a); + // 调试信息 + console.log('项目经理列表:', managerList.value); + console.log('部门负责人列表:', chargeList.value); + console.log('分管副总列表:', deputyList.value); + + // 直接设置对应的名称,这样下拉框就能正确显示了 + // 因为下拉框会根据ID在选项列表中查找对应的label + + // 注意:这里我们不需要手动设置managerName等,因为下拉框会自动显示 + // 我们只需要确保对应的用户列表中包含当前选中的用户 + } + dialog.visible = true; dialog.title = '修改项目周报信息'; }; @@ -436,5 +735,6 @@ const handleExport = () => { onMounted(() => { getList(); + getDeptList(); });