From b5f856ecaf80d9a81acba73ef803f833c1b68733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=BA=A2=E5=85=B5?= <374362909@qq.com> Date: Wed, 4 Mar 2026 12:45:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(purchase):=20=E6=9B=BF=E6=8D=A2OrgSele?= =?UTF-8?q?ctor=E4=B8=BAel-select=E8=BF=9C=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 业务分管处室及人员、业务分管校领导、采购分管领导、校党委人员表单 - 改用el-select + 远程搜索方式,不依赖upms模块权限 - 复用purchase模块的searchTeachers和getSecondDeptList接口 - 人员显示格式:部门名称 - 姓名 (工号) --- .../purchase/purchasingBusinessDept/form.vue | 162 ++++++++++------- .../purchasingBusinessLeader/form.vue | 107 +++++++----- .../purchasingPurchaseManager/form.vue | 164 +++++++++++------- .../purchase/purchasingSchoolLeader/form.vue | 103 ++++++----- 4 files changed, 317 insertions(+), 219 deletions(-) diff --git a/src/views/purchase/purchasingBusinessDept/form.vue b/src/views/purchase/purchasingBusinessDept/form.vue index 97ef781..0a98c69 100644 --- a/src/views/purchase/purchasingBusinessDept/form.vue +++ b/src/views/purchase/purchasingBusinessDept/form.vue @@ -11,32 +11,58 @@ :rules="dataRules" label-width="120px" v-loading="loading"> - - - + + + + {{ item.commonDeptName ? item.commonDeptName + ' - ' : '' }}{{ item.realName || item.name }} + {{ item.teacherNo }} + + - + + + import { reactive, ref, nextTick } from 'vue' import { getObj, addObj, putObj } from '/@/api/purchase/purchasingBusinessDept'; +import { searchTeachers, getSecondDeptList } from '/@/api/purchase/purchasingrequisition'; import { useMessage } from '/@/hooks/message'; -import orgSelector from '/@/components/OrgSelector/index.vue'; -// 定义子组件向父组件传值/事件 const emit = defineEmits(['refresh']); -// 定义变量内容 const dataFormRef = ref(); -const deptList = ref([]); -const userList = ref([]); +const deptOptions = ref([]); +const userOptions = ref([]); +const userLoading = ref(false); const form = reactive({ id: '', deptId: '', @@ -89,46 +114,72 @@ const loading = ref(false); const dataRules = ref({ userId: [ - { required: true, message: '请选取用户(分管负责人)', trigger: 'change' } + { required: true, message: '请选择人员', trigger: 'change' } ], deptId: [ { required: true, message: '请选择部门', trigger: 'change' } ], name: [ - { required: true, message: '请先选取用户', trigger: 'blur' } + { required: true, message: '请先选择人员', trigger: 'blur' } ], username: [ - { required: true, message: '请先选取用户', trigger: 'blur' } + { required: true, message: '请先选择人员', trigger: 'blur' } ], }); -// 处理部门选择变化 -const handleDeptChange = (list: any[]) => { - if (list && list.length > 0) { - const dept = list[0]; - form.deptId = dept.deptId || dept.id || ''; - form.deptName = dept.name || dept.deptName || ''; - } else { - form.deptId = ''; - form.deptName = ''; +const loadDeptOptions = async () => { + try { + const res = await getSecondDeptList(); + deptOptions.value = res?.data || []; + } catch (_) { + deptOptions.value = []; } }; -// 处理用户选择变化(选取用户后自动带出姓名、工号) -const handleUserChange = (list: any[]) => { - if (list && list.length > 0) { - const user = list[0]; - form.userId = user.userId || user.id || ''; - form.username = user.username || user.userName || ''; - form.name = user.name || user.realName || ''; - } else { +const searchUser = async (query: string) => { + if (!query) { + userOptions.value = []; + return; + } + userLoading.value = true; + try { + const res = await searchTeachers(query); + userOptions.value = res?.data || []; + } catch (_) { + userOptions.value = []; + } finally { + userLoading.value = false; + } +}; + +const handleDeptChange = (deptId: string) => { + if (!deptId) { + form.deptId = ''; + form.deptName = ''; + return; + } + const selected = deptOptions.value.find((item: any) => item.deptId === deptId); + if (selected) { + form.deptId = selected.deptId; + form.deptName = selected.deptName; + } +}; + +const handleUserChange = (teacherNo: string) => { + if (!teacherNo) { form.userId = ''; form.username = ''; form.name = ''; + return; + } + const selected = userOptions.value.find((item: any) => item.teacherNo === teacherNo); + if (selected) { + form.userId = selected.teacherNo; + form.username = selected.teacherNo; + form.name = selected.realName || selected.name; } }; -// 打开弹窗 const openDialog = async (id?: string) => { visible.value = true; form.id = ''; @@ -138,13 +189,13 @@ const openDialog = async (id?: string) => { form.username = ''; form.name = ''; form.remark = ''; - deptList.value = []; - userList.value = []; + userOptions.value = []; + + await loadDeptOptions(); nextTick(() => { dataFormRef.value?.resetFields(); if (id) { - // 编辑时,先获取详情数据 loading.value = true; getObj({ id }).then((res: any) => { if (res.data && res.data.length > 0) { @@ -158,26 +209,8 @@ const openDialog = async (id?: string) => { name: data.name || '', remark: data.remark || '', }); - // 设置部门列表用于回显 - if (data.deptId) { - deptList.value = [{ - deptId: data.deptId, - name: data.deptName, - id: data.deptId, - type: 'dept', - }]; - } - // 设置用户列表用于回显 - if (data.userId) { - userList.value = [{ - userId: data.userId, - username: data.username, - name: data.name, - id: data.userId, - userName: data.username, - realName: data.name, - type: 'user', - }]; + if (form.userId) { + userOptions.value = [{ teacherNo: form.userId, realName: form.name, name: form.name }]; } } loading.value = false; @@ -189,9 +222,7 @@ const openDialog = async (id?: string) => { }); }; -// 提交 const onSubmit = async () => { - // 立即设置 loading,防止重复点击 if (loading.value) return; loading.value = true; @@ -218,7 +249,6 @@ const onSubmit = async () => { } }; -// 暴露变量 defineExpose({ openDialog, }); diff --git a/src/views/purchase/purchasingBusinessLeader/form.vue b/src/views/purchase/purchasingBusinessLeader/form.vue index d88a7b8..774cfff 100644 --- a/src/views/purchase/purchasingBusinessLeader/form.vue +++ b/src/views/purchase/purchasingBusinessLeader/form.vue @@ -11,23 +11,40 @@ :rules="dataRules" label-width="120px" v-loading="loading"> - - + + + + {{ item.commonDeptName ? item.commonDeptName + ' - ' : '' }}{{ item.realName || item.name }} + {{ item.teacherNo }} + + @@ -51,15 +68,14 @@ \ No newline at end of file + \ No newline at end of file diff --git a/src/views/purchase/purchasingPurchaseManager/form.vue b/src/views/purchase/purchasingPurchaseManager/form.vue index 4eea09b..4e3bfd6 100644 --- a/src/views/purchase/purchasingPurchaseManager/form.vue +++ b/src/views/purchase/purchasingPurchaseManager/form.vue @@ -11,32 +11,58 @@ :rules="dataRules" label-width="120px" v-loading="loading"> - - - + + + + {{ item.commonDeptName ? item.commonDeptName + ' - ' : '' }}{{ item.realName || item.name }} + {{ item.teacherNo }} + + - + + + import { reactive, ref, nextTick } from 'vue' import { getObj, addObj, putObj } from '/@/api/purchase/purchasingPurchaseManager'; +import { searchTeachers, getSecondDeptList } from '/@/api/purchase/purchasingrequisition'; import { useMessage } from '/@/hooks/message'; -import orgSelector from '/@/components/OrgSelector/index.vue'; -// 定义子组件向父组件传值/事件 const emit = defineEmits(['refresh']); -// 定义变量内容 const dataFormRef = ref(); -const deptList = ref([]); -const userList = ref([]); +const deptOptions = ref([]); +const userOptions = ref([]); +const userLoading = ref(false); const form = reactive({ id: '', deptId: '', @@ -89,46 +114,72 @@ const loading = ref(false); const dataRules = ref({ userId: [ - { required: true, message: '请选取用户(分管负责人)', trigger: 'change' } + { required: true, message: '请选择人员', trigger: 'change' } ], deptId: [ { required: true, message: '请选择部门', trigger: 'change' } ], name: [ - { required: true, message: '请先选取用户', trigger: 'blur' } + { required: true, message: '请先选择人员', trigger: 'blur' } ], username: [ - { required: true, message: '请先选取用户', trigger: 'blur' } + { required: true, message: '请先选择人员', trigger: 'blur' } ], }); -// 处理部门选择变化 -const handleDeptChange = (list: any[]) => { - if (list && list.length > 0) { - const dept = list[0]; - form.deptId = dept.deptId || dept.id || ''; - form.deptName = dept.name || dept.deptName || ''; - } else { - form.deptId = ''; - form.deptName = ''; +const loadDeptOptions = async () => { + try { + const res = await getSecondDeptList(); + deptOptions.value = res?.data || []; + } catch (_) { + deptOptions.value = []; } }; -// 处理用户选择变化(选取用户后自动带出姓名、工号) -const handleUserChange = (list: any[]) => { - if (list && list.length > 0) { - const user = list[0]; - form.userId = user.userId || user.id || ''; - form.username = user.username || user.userName || ''; - form.name = user.name || user.realName || ''; - } else { +const searchUser = async (query: string) => { + if (!query) { + userOptions.value = []; + return; + } + userLoading.value = true; + try { + const res = await searchTeachers(query); + userOptions.value = res?.data || []; + } catch (_) { + userOptions.value = []; + } finally { + userLoading.value = false; + } +}; + +const handleDeptChange = (deptId: string) => { + if (!deptId) { + form.deptId = ''; + form.deptName = ''; + return; + } + const selected = deptOptions.value.find((item: any) => item.deptId === deptId); + if (selected) { + form.deptId = selected.deptId; + form.deptName = selected.deptName; + } +}; + +const handleUserChange = (teacherNo: string) => { + if (!teacherNo) { form.userId = ''; form.username = ''; form.name = ''; + return; + } + const selected = userOptions.value.find((item: any) => item.teacherNo === teacherNo); + if (selected) { + form.userId = selected.teacherNo; + form.username = selected.teacherNo; + form.name = selected.realName || selected.name; } }; -// 打开弹窗 const openDialog = async (id?: string) => { visible.value = true; form.id = ''; @@ -138,13 +189,13 @@ const openDialog = async (id?: string) => { form.username = ''; form.name = ''; form.remark = ''; - deptList.value = []; - userList.value = []; + userOptions.value = []; + + await loadDeptOptions(); nextTick(() => { dataFormRef.value?.resetFields(); if (id) { - // 编辑时,先获取详情数据 loading.value = true; getObj(id).then((res: any) => { if (res.data && res.data.length > 0) { @@ -158,26 +209,8 @@ const openDialog = async (id?: string) => { name: data.name || '', remark: data.remark || '', }); - // 设置部门列表用于回显 - if (data.deptId) { - deptList.value = [{ - deptId: data.deptId, - name: data.deptName, - id: data.deptId, - type: 'dept', - }]; - } - // 设置用户列表用于回显 - if (data.userId) { - userList.value = [{ - userId: data.userId, - username: data.username, - name: data.name, - id: data.userId, - userName: data.username, - realName: data.name, - type: 'user', - }]; + if (form.userId) { + userOptions.value = [{ teacherNo: form.userId, realName: form.name, name: form.name }]; } } loading.value = false; @@ -189,9 +222,7 @@ const openDialog = async (id?: string) => { }); }; -// 提交 const onSubmit = async () => { - // 立即设置 loading,防止重复点击 if (loading.value) return; loading.value = true; @@ -218,11 +249,10 @@ const onSubmit = async () => { } }; -// 暴露变量 defineExpose({ openDialog, }); \ No newline at end of file + \ No newline at end of file diff --git a/src/views/purchase/purchasingSchoolLeader/form.vue b/src/views/purchase/purchasingSchoolLeader/form.vue index b182624..0b51041 100644 --- a/src/views/purchase/purchasingSchoolLeader/form.vue +++ b/src/views/purchase/purchasingSchoolLeader/form.vue @@ -11,23 +11,40 @@ :rules="dataRules" label-width="100px" v-loading="loading"> - - + + + + {{ item.commonDeptName ? item.commonDeptName + ' - ' : '' }}{{ item.realName || item.name }} + {{ item.teacherNo }} + + @@ -51,15 +68,14 @@ - + \ No newline at end of file