houzhongjian
2024-11-27 9e876a11f6f0b384d4b1f0a60e066944dbcdeaa5
提交 | 用户 | 时间
820397 1 <template>
H 2   <el-card v-loading="loading" class="box-card">
3     <template #header>
4       <span class="el-icon-picture-outline">审批记录</span>
5     </template>
6     <el-col :offset="3" :span="17">
7       <div class="block">
8         <el-timeline>
9           <el-timeline-item
10             v-if="processInstance.endTime"
11             :type="getProcessInstanceTimelineItemType(processInstance)"
12           >
13             <p style="font-weight: 700">
14               结束流程:在 {{ formatDate(processInstance?.endTime) }} 结束
15               <dict-tag
16                 :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS"
17                 :value="processInstance.status"
18               />
19             </p>
20           </el-timeline-item>
21           <el-timeline-item
22             v-for="(item, index) in tasks"
23             :key="index"
24             :type="getTaskTimelineItemType(item)"
25           >
26             <p style="font-weight: 700">
27               审批任务:{{ item.name }}
28               <dict-tag :type="DICT_TYPE.BPM_TASK_STATUS" :value="item.status" />
29               <el-button
30                 class="ml-10px"
31                 v-if="!isEmpty(item.children)"
32                 @click="openChildrenTask(item)"
33                 size="small"
34               >
35                 <Icon icon="ep:memo" /> 子任务
36               </el-button>
37               <el-button
38                 class="ml-10px"
39                 size="small"
40                 v-if="item.formId > 0"
41                 @click="handleFormDetail(item)"
42               >
43                 <Icon icon="ep:document" /> 查看表单
44               </el-button>
45             </p>
46             <el-card :body-style="{ padding: '10px' }">
47               <label v-if="item.assigneeUser" style="margin-right: 30px; font-weight: normal">
48                 审批人:{{ item.assigneeUser.nickname }}
49                 <el-tag size="small" type="info">{{ item.assigneeUser.deptName }}</el-tag>
50               </label>
51               <label v-if="item.createTime" style="font-weight: normal">创建时间:</label>
52               <label style="font-weight: normal; color: #8a909c">
53                 {{ formatDate(item?.createTime) }}
54               </label>
55               <label v-if="item.endTime" style="margin-left: 30px; font-weight: normal">
56                 审批时间:
57               </label>
58               <label v-if="item.endTime" style="font-weight: normal; color: #8a909c">
59                 {{ formatDate(item?.endTime) }}
60               </label>
61               <label v-if="item.durationInMillis" style="margin-left: 30px; font-weight: normal">
62                 耗时:
63               </label>
64               <label v-if="item.durationInMillis" style="font-weight: normal; color: #8a909c">
65                 {{ formatPast2(item?.durationInMillis) }}
66               </label>
67               <p v-if="item.reason"> 审批建议:{{ item.reason }} </p>
68             </el-card>
69           </el-timeline-item>
70           <el-timeline-item type="success">
71             <p style="font-weight: 700">
72               发起流程:【{{ processInstance.startUser?.nickname }}】在
73               {{ formatDate(processInstance?.startTime) }} 发起【 {{ processInstance.name }} 】流程
74             </p>
75           </el-timeline-item>
76         </el-timeline>
77       </div>
78     </el-col>
79   </el-card>
80
81   <!-- 弹窗:子任务  -->
82   <TaskSignList ref="taskSignListRef" @success="refresh" />
83   <!-- 弹窗:表单 -->
84   <Dialog title="表单详情" v-model="taskFormVisible" width="600">
85     <form-create
86       ref="fApi"
87       v-model="taskForm.value"
88       :option="taskForm.option"
89       :rule="taskForm.rule"
90     />
91   </Dialog>
92 </template>
93 <script lang="ts" setup>
94 import { formatDate, formatPast2 } from '@/utils/formatTime'
95 import { propTypes } from '@/utils/propTypes'
96 import { DICT_TYPE } from '@/utils/dict'
97 import { isEmpty } from '@/utils/is'
98 import TaskSignList from './dialog/TaskSignList.vue'
99 import type { ApiAttrs } from '@form-create/element-ui/types/config'
100 import { setConfAndFields2 } from '@/utils/formCreate'
101
102 defineOptions({ name: 'BpmProcessInstanceTaskList' })
103
104 defineProps({
105   loading: propTypes.bool, // 是否加载中
106   processInstance: propTypes.object, // 流程实例
107   tasks: propTypes.arrayOf(propTypes.object) // 流程任务的数组
108 })
109
110 /** 获得流程实例对应的颜色 */
111 const getProcessInstanceTimelineItemType = (item: any) => {
112   if (item.status === 2) {
113     return 'success'
114   }
115   if (item.status === 3) {
116     return 'danger'
117   }
118   if (item.status === 4) {
119     return 'warning'
120   }
121   return ''
122 }
123
124 /** 获得任务对应的颜色 */
125 const getTaskTimelineItemType = (item: any) => {
126   if ([0, 1, 6, 7].includes(item.status)) {
127     return 'primary'
128   }
129   if (item.status === 2) {
130     return 'success'
131   }
132   if (item.status === 3) {
133     return 'danger'
134   }
135   if (item.status === 4) {
136     return 'info'
137   }
138   if (item.status === 5) {
139     return 'warning'
140   }
141   return ''
142 }
143
144 /** 子任务 */
145 const taskSignListRef = ref()
146 const openChildrenTask = (item: any) => {
147   taskSignListRef.value.open(item)
148 }
149
150 /** 查看表单 */
151 const fApi = ref<ApiAttrs>() // form-create 的 API 操作类
152 const taskForm = ref({
153   rule: [],
154   option: {},
155   value: {}
156 }) // 流程任务的表单详情
157 const taskFormVisible = ref(false)
158 const handleFormDetail = async (row) => {
159   // 设置表单
160   setConfAndFields2(taskForm, row.formConf, row.formFields, row.formVariables)
161   // 弹窗打开
162   taskFormVisible.value = true
163   // 隐藏提交、重置按钮,设置禁用只读
164   await nextTick()
165   fApi.value.fapi.btn.show(false)
166   fApi.value?.fapi?.resetBtn.show(false)
167   fApi.value?.fapi?.disabled(true)
168 }
169
170 /** 刷新数据 */
171 const emit = defineEmits(['refresh']) // 定义 success 事件,用于操作成功后的回调
172 const refresh = () => {
173   emit('refresh')
174 }
175 </script>