44
44
:rows =" 4"
45
45
/>
46
46
</el-form-item >
47
- <el-form-item label =" 下一个节点的审批人" prop =" nextAssignees" v-if =" nextAssigneesVisible" >
47
+ <el-form-item
48
+ label =" 下一个节点的审批人"
49
+ prop =" nextAssignees"
50
+ v-if =" nextAssigneesActivityNode.length > 0"
51
+ >
48
52
<div class =" ml-10px -mt-15px -mb-35px" >
49
53
<ProcessInstanceTimeline
50
54
:activity-nodes =" nextAssigneesActivityNode"
@@ -522,6 +526,7 @@ import { BpmModelFormType, BpmProcessInstanceStatus } from '@/utils/constants'
522
526
import type { FormInstance , FormRules } from ' element-plus'
523
527
import SignDialog from ' ./SignDialog.vue'
524
528
import ProcessInstanceTimeline from ' ../detail/ProcessInstanceTimeline.vue'
529
+ import { isEmpty } from ' @/utils/is'
525
530
526
531
defineOptions ({ name: ' ProcessInstanceBtnContainer' })
527
532
@@ -565,7 +570,6 @@ const reasonRequire = ref()
565
570
const approveFormRef = ref <FormInstance >()
566
571
const signRef = ref ()
567
572
const approveSignFormRef = ref ()
568
- const nextAssigneesVisible = ref (false ) // 是否显示下一个节点的审批人
569
573
const nextAssigneesActivityNode = ref <ProcessInstanceApi .ApprovalNodeInfo []>([]) // 下一个审批节点信息
570
574
const approveReasonForm = reactive ({
571
575
reason: ' ' ,
@@ -711,43 +715,51 @@ const closePopover = (type: string, formRef: FormInstance | undefined) => {
711
715
formRef .resetFields ()
712
716
}
713
717
popOverVisible .value [type ] = false
714
- nextAssigneesVisible .value = false
718
+ nextAssigneesActivityNode .value = []
715
719
}
716
720
717
721
/** 流程通过时,根据表单变量查询新的流程节点,判断下一个节点类型是否为自选审批人 */
718
722
const initNextAssigneesFormField = async () => {
719
723
// 获取修改的流程变量, 暂时只支持流程表单
720
724
const variables = getUpdatedProcessInstanceVariables ()
721
- const data = await ProcessInstanceApi .getApprovalDetail ({
725
+ const data = await ProcessInstanceApi .getNextApprovalNodes ({
722
726
processInstanceId: props .processInstance .id ,
727
+ taskId: runningTask .value .id ,
723
728
processVariablesStr: JSON .stringify (variables )
724
729
})
725
-
726
- const activityId = data .todoTask ?.taskDefinitionKey
727
- if (data .activityNodes && data .activityNodes .length > 0 ) {
728
- // 找到当前节点的索引
729
- const currentNodeIndex = data .activityNodes .findIndex ((node : any ) => node .id === activityId )
730
- const nextNode = data .activityNodes [currentNodeIndex + 1 ]
731
- // 情况一:发起人选择审批人:此时一般是因为条件发生变化,需要当前审批人补充选择
732
- if (
733
- nextNode .candidateStrategy === CandidateStrategy .START_USER_SELECT &&
734
- ! nextNode .tasks &&
735
- nextNode .candidateUsers ?.length === 0
736
- ) {
737
- // 自选审批人,则弹出选择审批人弹窗
738
- // TODO @小北:需要考虑下,这里的 nextNode 可能是多个节点,需要怎么处理;类似你在后端的处理哈
739
- // TODO @小北:有点纠结,是不是写个预测下一个节点的接口,更合适?
740
- nextAssigneesActivityNode .value = [nextNode ]
741
- nextAssigneesVisible .value = true
742
- }
743
- // TODO @小北:情况二:审批人选择的情况
730
+ if (data && data .length > 0 ) {
731
+ data .forEach ((node : any ) => {
732
+ // 如果是发起人自选,并且没有审批人 或者 是审批人自选
733
+ if (
734
+ (isEmpty (node .tasks ) &&
735
+ isEmpty (node .candidateUsers ) &&
736
+ CandidateStrategy .START_USER_SELECT === node .candidateStrategy ) ||
737
+ CandidateStrategy .APPROVE_USER_SELECT === node .candidateStrategy
738
+ ) {
739
+ nextAssigneesActivityNode .value .push (node )
740
+ }
741
+ })
744
742
}
745
743
}
746
744
747
745
/** 选择下一个节点的审批人 */
748
746
const selectNextAssigneesConfirm = (id : string , userList : any []) => {
749
747
approveReasonForm .nextAssignees [id ] = userList ?.map ((item : any ) => item .id )
750
748
}
749
+ /** 审批通过时,校验每个自选审批人的节点是否都已配置了审批人 */
750
+ const validateNextAssignees = () => {
751
+ // 如果需要自选审批人,则校验自选审批人
752
+ if (Object .keys (nextAssigneesActivityNode .value ).length > 0 ) {
753
+ // 校验每个节点是否都已配置审批人
754
+ for (const item of nextAssigneesActivityNode .value ) {
755
+ if (isEmpty (approveReasonForm .nextAssignees [item .id ])) {
756
+ message .warning (' 下一个节点的审批人不能为空!' )
757
+ return false
758
+ }
759
+ }
760
+ }
761
+ return true
762
+ }
751
763
752
764
/** 处理审批通过和不通过的操作 */
753
765
const handleAudit = async (pass : boolean , formRef : FormInstance | undefined ) => {
@@ -764,11 +776,8 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
764
776
}
765
777
766
778
if (pass ) {
767
- // 如果需要自选审批人,则校验自选审批人
768
- if (nextAssigneesVisible .value && Object .keys (approveReasonForm .nextAssignees ).length === 0 ) {
769
- message .warning (' 下一个节点的审批人不能为空!' )
770
- return
771
- }
779
+ const nextAssigneesValid = validateNextAssignees ()
780
+ if (! nextAssigneesValid ) return
772
781
const variables = getUpdatedProcessInstanceVariables ()
773
782
// 审批通过数据
774
783
const data = {
@@ -791,7 +800,7 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
791
800
}
792
801
await TaskApi .approveTask (data )
793
802
popOverVisible .value .approve = false
794
- nextAssigneesVisible .value = false
803
+ nextAssigneesActivityNode .value = []
795
804
message .success (' 审批通过成功' )
796
805
} else {
797
806
// 审批不通过数据
0 commit comments