From 422aaa62d055ef2c7da6b5f5a60f844fbec5d578 Mon Sep 17 00:00:00 2001 From: wsm <2746563060@qq.com> Date: Tue, 4 Aug 2026 10:25:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(fixcontact):=20=E5=8F=8D=E9=A6=88=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8C=89=E5=BD=93=E5=89=8D=E5=AD=90=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E8=8C=83=E5=9B=B4=E8=BF=87=E6=BB=A4=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=80=E9=A2=86=E5=AF=BC=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 反馈保存时 feedback_dept 存当前子流程部门(无子流程节点时回退登录人部门) - 子流程部门读取改为优先读多实例局部变量 dept_id(原 impl_dept_id 从未写入导致过滤落空) - filterByDept=1 时反馈列表仅展示当前子流程内的反馈,同子流程内其他部门反馈可见 - 刷新 watch 增加 taskId,切换同实例不同子流程任务时正确重刷 - 新增是否需要所领导审批开关与审批人(is_need_leader_approve / leader_approve_user 全局变量) Co-Authored-By: Claude Opus 4.7 --- .../FixedContact20260730BPMFeedbackModal.vue | 13 +- .../FixedContact20260730BPMForm.vue | 159 ++++++++++++++++-- 2 files changed, 150 insertions(+), 22 deletions(-) diff --git a/src/views/bg/fixcontact/components/FixedContact20260730BPMFeedbackModal.vue b/src/views/bg/fixcontact/components/FixedContact20260730BPMFeedbackModal.vue index e409279..7cbeb6f 100644 --- a/src/views/bg/fixcontact/components/FixedContact20260730BPMFeedbackModal.vue +++ b/src/views/bg/fixcontact/components/FixedContact20260730BPMFeedbackModal.vue @@ -87,6 +87,7 @@ const formRef = ref(); const uploadFileRef = ref | null>(null); const uploadKey = ref(0); + const subProcessDeptId = ref(''); const labelCol = { xs: { span: 24 }, sm: { span: 7 } }; const wrapperCol = { xs: { span: 24 }, sm: { span: 17 } }; const wideLabelCol = { xs: { span: 24 }, sm: { span: 5 } }; @@ -114,18 +115,19 @@ planFinishStatus: [{ required: true, message: '请输入计划完成情况' }], }; - function resetForm(mainId = '', bpmProcessId = '') { + function resetForm(mainId = '', bpmProcessId = '', deptId = '') { Object.keys(formData).forEach((key) => { formData[key] = ''; }); formData.fixedContact20260730Id = mainId; formData.bpmProcessId = bpmProcessId; + subProcessDeptId.value = deptId; uploadKey.value += 1; nextTick(() => formRef.value?.clearValidate?.()); } - function open(mainId: string, bpmProcessId = '', record?: Record) { - resetForm(mainId, bpmProcessId); + function open(mainId: string, bpmProcessId = '', deptId = '', record?: Record) { + resetForm(mainId, bpmProcessId, deptId); if (record?.id) { isEdit.value = true; modalTitle.value = '编辑反馈'; @@ -158,9 +160,8 @@ const userInfo = (userStore.getUserInfo || {}) as Record; formData.feedbackUser = userInfo.id || userInfo.userId || ''; const loginDepart = getCurrentLoginDepart(); - if (loginDepart) { - formData.feedbackDept = loginDepart.id || ''; - } + // 反馈部门存当前子流程范围(impl_dept_id),供子流程内按范围过滤;非子流程节点回退到登录人部门 + formData.feedbackDept = subProcessDeptId.value || loginDepart?.id || ''; } function handleCancel() { diff --git a/src/views/bg/fixcontact/components/FixedContact20260730BPMForm.vue b/src/views/bg/fixcontact/components/FixedContact20260730BPMForm.vue index 4d5b1ea..484da3b 100644 --- a/src/views/bg/fixcontact/components/FixedContact20260730BPMForm.vue +++ b/src/views/bg/fixcontact/components/FixedContact20260730BPMForm.vue @@ -195,6 +195,23 @@ + + + + + + 否(不需要) + 是(需要所领导审批) + + + + + + + + + + >({ id: '', @@ -320,6 +340,7 @@ const showAddFeedback = computed( () => String(props.formData?.extendUrlParams?.showAddFeedback ?? props.formData?.extendUrlParams?.addfeedback ?? '') === '1' ); + const filterByDept = computed(() => String(props.formData?.extendUrlParams?.filterByDept ?? '') === '1'); const processInfo = computed(() => ({ taskId: props.formData?.taskId, @@ -347,12 +368,19 @@ () => String(props.formData?.extendUrlParams?.showSubApproveUser ?? props.formData?.extendUrlParams?.selectuser ?? '') === '1' ); const showSubApproveUserSelector = computed(() => showSubApproveUser.value && String(isEnd.value) !== '1'); + const showIsNeedLeaderApprove = computed(() => String(props.formData?.extendUrlParams?.showIsNeedLeaderApprove ?? '') === '1'); + const showIsNeedLeaderApproveSelector = computed(() => showIsNeedLeaderApprove.value && String(isNeedLeaderApprove.value) === '1'); onMounted(() => { initFormData(); }); - watch([() => props.formData?.dataId, () => processInfo.value.processInstanceId], () => initFormData()); + // taskId 参与刷新:同实例多个子流程(督办经办人确认等)的 taskId 不同但 processInstanceId/dataId 相同, + // 切换子流程任务时若不刷新会沿用上一个子流程的部门过滤结果 + watch( + [() => props.formData?.dataId, () => processInfo.value.processInstanceId, () => props.formData?.taskId], + () => initFormData() + ); watch( () => props.formData?.vars?.isEnd, @@ -368,6 +396,20 @@ vars.isEnd = String(val); } }); + watch( + () => props.formData?.vars?.isNeedLeaderApprove, + (value) => { + isNeedLeaderApprove.value = String(value ?? '0') === '1' ? 1 : 0; + }, + { immediate: true } + ); + watch(isNeedLeaderApprove, (val) => { + const vars = props.formData?.vars; + if (vars) { + vars.is_need_leader_approve = String(val); + vars.isNeedLeaderApprove = String(val); + } + }); async function initFormData() { const dataId = props.formData?.dataId; @@ -395,6 +437,9 @@ Object.keys(mainForm).forEach((key) => { mainForm[key] = record[key] ?? ''; }); + // 所领导审批人默认取定点联系所领导 + 相关分管所领导,若流程变量已保存则沿用 + const savedLeaderApproveUser = props.formData?.vars?.leader_approve_user ?? props.formData?.vars?.leaderApproveUser; + leaderApproveUser.value = String(savedLeaderApproveUser ?? '') || [mainForm.contactLeader, mainForm.relatedLeader].filter(Boolean).join(','); // 从 approveInfo JSON 初始化当前子流程部门的 isEnd 和部门经办人 const approveInfo = record.approveInfo; const deptId = await getCurrentProcessDeptId(); @@ -412,17 +457,20 @@ async function getCurrentProcessDeptId() { const taskId = props.formData?.taskId; if (taskId) { - try { - const res = await getProcessVariable({ taskId, key: 'impl_dept_id', isLocal: true }); - const value = res?.result?.value ?? res?.value; - if (value) { - const deptId = String(value).replace('[', '').replace(']', '').trim(); - if (deptId) { - return deptId; + // 子流程当前部门ID实际存于多实例元素变量 dept_id(impl_dept_id 从未写入),优先读取 + for (const key of ['dept_id', 'impl_dept_id']) { + try { + const res = await getProcessVariable({ taskId, key, isLocal: true }); + const value = res?.result?.value ?? res?.value; + if (value) { + const deptId = String(value).replace('[', '').replace(']', '').trim(); + if (deptId) { + return deptId; + } } + } catch (e) { + // 局部变量读取失败,尝试下一个候选键 } - } catch (e) { - // 局部变量读取失败,回退到当前用户部门 } } return getCurrentUserDeptId(); @@ -444,6 +492,11 @@ return userInfo.username || ''; } + async function getProcessVarDeptIds(): Promise { + const deptId = await getCurrentProcessDeptId(); + return deptId ? [deptId] : []; + } + async function loadFeedbackList() { const bpmProcessId = processInfo.value.processInstanceId; if (!mainForm.id || !bpmProcessId) { @@ -452,7 +505,21 @@ return; } const res = await fixedContactFeedbackList({ id: mainForm.id, bpmProcessId }); - feedbackList.value = Array.isArray(res) ? res : res?.records || []; + let list = Array.isArray(res) ? res : res?.records || []; + // 子流程过滤:filterByDept=1 时仅展示当前子流程内的反馈(反馈部门即保存时写入的子流程范围) + if (list.length && filterByDept.value) { + const deptIds = await getProcessVarDeptIds(); + if (deptIds.length) { + list = list.filter((item) => { + const itemDeptIds = String(item.feedbackDept || '') + .split(',') + .map((s: string) => s.trim()) + .filter(Boolean); + return itemDeptIds.some((id) => deptIds.includes(id)); + }); + } + } + feedbackList.value = list; feedbackAttachmentRefreshKey.value += 1; } @@ -501,7 +568,16 @@ } } if (showSubApproveUser.value) { - return saveSubApproveUserVariable({ showSuccessMessage: false }); + const subSaved = await saveSubApproveUserVariable({ showSuccessMessage: false }); + if (!subSaved) { + return false; + } + } + if (showIsNeedLeaderApprove.value) { + const leaderSaved = await saveIsNeedLeaderApproveVariable({ showSuccessMessage: false }); + if (!leaderSaved) { + return false; + } } return true; } @@ -573,6 +649,56 @@ } } + async function saveIsNeedLeaderApproveVariable(options: { showSuccessMessage?: boolean } = {}) { + const { showSuccessMessage = true } = options; + const processInstanceId = processInfo.value.processInstanceId; + const isNeedLeaderApproveValue = String(isNeedLeaderApprove.value); + const leaderUsernameValue = normalizeUsernameList(leaderApproveUser.value); + if (!processInstanceId) { + createMessage.warning('流程实例ID不能为空'); + return false; + } + if (isNeedLeaderApproveValue === '1' && !leaderUsernameValue) { + createMessage.warning('请选择所领导审批人'); + return false; + } + + savingIsNeedLeaderApprove.value = true; + try { + const result = await saveGlobalProcessVariable('is_need_leader_approve', isNeedLeaderApproveValue); + if (!result?.success) { + createMessage.warning(result.message || '保存失败'); + return false; + } + if (isNeedLeaderApproveValue === '1') { + const leaderResult = await saveGlobalProcessVariable('leader_approve_user', leaderUsernameValue); + if (!leaderResult?.success) { + createMessage.warning(leaderResult.message || '保存失败'); + return false; + } + } + if (showSuccessMessage) { + createMessage.success('保存成功'); + } + return true; + } catch (error) { + createMessage.warning('保存失败'); + return false; + } finally { + savingIsNeedLeaderApprove.value = false; + } + } + + // 所领导审批为顶层流程决策,写入全局流程变量供流程网关判断 + function saveGlobalProcessVariable(varField: string, varVal: any) { + return setProcessVariable({ + processInstanceId: processInfo.value.processInstanceId, + local: false, + varField, + varVal, + }); + } + // 局部变量写入(默认向上追溯 2 层父级执行实例),与 FixContactDeptLeaderApproveListener 存储目标保持一致 function saveProcessVariableLocal(varField: string, varVal: any) { return setBpmVariableLocal({ @@ -592,7 +718,7 @@ .join(','); } - function openFeedbackModal() { + async function openFeedbackModal() { if (!mainForm.id) { createMessage.warning('主表数据不存在,无法新增反馈'); return; @@ -602,7 +728,8 @@ createMessage.warning('流程实例ID不能为空,无法新增反馈'); return; } - feedbackModalRef.value?.open(mainForm.id, processInstanceId); + const deptId = await getCurrentProcessDeptId(); + feedbackModalRef.value?.open(mainForm.id, processInstanceId, deptId); } function openFeedbackEditModal(record: Recordable) { @@ -614,7 +741,7 @@ createMessage.warning('反馈记录不存在,无法编辑'); return; } - feedbackModalRef.value?.open(mainForm.id, processInfo.value.processInstanceId, record); + feedbackModalRef.value?.open(mainForm.id, processInfo.value.processInstanceId, '', record); } async function handleFeedbackDelete(record: Recordable) {