detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <ContentWrap>
  3. <!-- 审批信息 -->
  4. <el-card
  5. class="box-card"
  6. v-loading="processInstanceLoading"
  7. v-for="(item, index) in runningTasks"
  8. :key="index"
  9. >
  10. <template #header>
  11. <span class="el-icon-picture-outline">审批任务【{{ item.name }}】</span>
  12. </template>
  13. <el-col :span="16" :offset="6">
  14. <el-form
  15. :ref="'form' + index"
  16. :model="auditForms[index]"
  17. :rules="auditRule"
  18. label-width="100px"
  19. >
  20. <el-form-item label="流程名" v-if="processInstance && processInstance.name">
  21. {{ processInstance.name }}
  22. </el-form-item>
  23. <el-form-item label="流程发起人" v-if="processInstance && processInstance.startUser">
  24. {{ processInstance.startUser.nickname }}
  25. <el-tag type="info" size="small">{{ processInstance.startUser.deptName }}</el-tag>
  26. </el-form-item>
  27. <el-form-item label="审批建议" prop="reason">
  28. <el-input
  29. type="textarea"
  30. v-model="auditForms[index].reason"
  31. placeholder="请输入审批建议"
  32. />
  33. </el-form-item>
  34. </el-form>
  35. <div style="margin-bottom: 20px; margin-left: 10%; font-size: 14px">
  36. <XButton
  37. pre-icon="ep:select"
  38. type="success"
  39. title="通过"
  40. @click="handleAudit(item, true)"
  41. />
  42. <XButton
  43. pre-icon="ep:close"
  44. type="danger"
  45. title="不通过"
  46. @click="handleAudit(item, false)"
  47. />
  48. <XButton
  49. pre-icon="ep:edit"
  50. type="primary"
  51. title="转办"
  52. @click="handleUpdateAssignee(item)"
  53. />
  54. <XButton
  55. pre-icon="ep:position"
  56. type="primary"
  57. title="委派"
  58. @click="handleDelegate(item)"
  59. />
  60. <XButton pre-icon="ep:back" type="warning" title="退回" @click="handleBack(item)" />
  61. </div>
  62. </el-col>
  63. </el-card>
  64. <!-- 申请信息 -->
  65. <el-card class="box-card" v-loading="processInstanceLoading">
  66. <template #header>
  67. <span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
  68. </template>
  69. <!-- 情况一:流程表单 -->
  70. <el-col v-if="processInstance?.processDefinition?.formType === 10" :span="16" :offset="6">
  71. <form-create
  72. ref="fApi"
  73. :rule="detailForm.rule"
  74. :option="detailForm.option"
  75. v-model="detailForm.value"
  76. />
  77. </el-col>
  78. <!-- 情况二:流程表单 -->
  79. <div v-if="processInstance?.processDefinition?.formType === 20">
  80. <router-link
  81. :to="
  82. processInstance.processDefinition.formCustomViewPath +
  83. '?id=' +
  84. processInstance.businessKey
  85. "
  86. >
  87. <XButton type="primary" preIcon="ep:view" title="点击查看" />
  88. </router-link>
  89. </div>
  90. </el-card>
  91. <!-- 审批记录 -->
  92. <el-card class="box-card" v-loading="tasksLoad">
  93. <template #header>
  94. <span class="el-icon-picture-outline">审批记录</span>
  95. </template>
  96. <el-col :span="16" :offset="4">
  97. <div class="block">
  98. <el-timeline>
  99. <el-timeline-item
  100. v-for="(item, index) in tasks"
  101. :key="index"
  102. :icon="getTimelineItemIcon(item)"
  103. :type="getTimelineItemType(item)"
  104. >
  105. <p style="font-weight: 700">任务:{{ item.name }}</p>
  106. <el-card :body-style="{ padding: '10px' }">
  107. <label v-if="item.assigneeUser" style="margin-right: 30px; font-weight: normal">
  108. 审批人:{{ item.assigneeUser.nickname }}
  109. <el-tag type="info" size="small">{{ item.assigneeUser.deptName }}</el-tag>
  110. </label>
  111. <label style="font-weight: normal" v-if="item.createTime">创建时间:</label>
  112. <label style="font-weight: normal; color: #8a909c">
  113. {{ dayjs(item?.createTime).format('YYYY-MM-DD HH:mm:ss') }}
  114. </label>
  115. <label v-if="item.endTime" style="margin-left: 30px; font-weight: normal">
  116. 审批时间:
  117. </label>
  118. <label v-if="item.endTime" style="font-weight: normal; color: #8a909c">
  119. {{ dayjs(item?.endTime).format('YYYY-MM-DD HH:mm:ss') }}
  120. </label>
  121. <label v-if="item.durationInMillis" style="margin-left: 30px; font-weight: normal">
  122. 耗时:
  123. </label>
  124. <label v-if="item.durationInMillis" style="font-weight: normal; color: #8a909c">
  125. {{ formatPast2(item?.durationInMillis) }}
  126. </label>
  127. <p v-if="item.reason">
  128. <el-tag :type="getTimelineItemType(item)">{{ item.reason }}</el-tag>
  129. </p>
  130. </el-card>
  131. </el-timeline-item>
  132. </el-timeline>
  133. </div>
  134. </el-col>
  135. </el-card>
  136. <!-- 高亮流程图 -->
  137. <el-card class="box-card" v-loading="processInstanceLoading">
  138. <template #header>
  139. <span class="el-icon-picture-outline">流程图</span>
  140. </template>
  141. <my-process-viewer
  142. key="designer"
  143. v-model="bpmnXML"
  144. :value="bpmnXML"
  145. v-bind="bpmnControlForm"
  146. :prefix="bpmnControlForm.prefix"
  147. :activityData="activityList"
  148. :processInstanceData="processInstance"
  149. :taskData="tasks"
  150. />
  151. </el-card>
  152. <!-- 对话框(转派审批人) -->
  153. <XModal v-model="updateAssigneeVisible" title="转派审批人" width="500">
  154. <el-form
  155. ref="updateAssigneeFormRef"
  156. :model="updateAssigneeForm"
  157. :rules="updateAssigneeRules"
  158. label-width="110px"
  159. >
  160. <el-form-item label="新审批人" prop="assigneeUserId">
  161. <el-select v-model="updateAssigneeForm.assigneeUserId" clearable style="width: 100%">
  162. <el-option
  163. v-for="item in userOptions"
  164. :key="parseInt(item.id)"
  165. :label="item.nickname"
  166. :value="parseInt(item.id)"
  167. />
  168. </el-select>
  169. </el-form-item>
  170. </el-form>
  171. <!-- 操作按钮 -->
  172. <template #footer>
  173. <!-- 按钮:保存 -->
  174. <XButton
  175. type="primary"
  176. :title="t('action.save')"
  177. :loading="updateAssigneeLoading"
  178. @click="submitUpdateAssigneeForm"
  179. />
  180. <!-- 按钮:关闭 -->
  181. <XButton
  182. :loading="updateAssigneeLoading"
  183. :title="t('dialog.close')"
  184. @click="updateAssigneeLoading = false"
  185. />
  186. </template>
  187. </XModal>
  188. <!-- 弹窗,回退节点 -->
  189. <TaskReturnDialog ref="taskReturnDialogRef" @success="getDetail" />
  190. <!-- 委派,将任务委派给别人处理,处理完成后,会重新回到原审批人手中-->
  191. <TaskDelegateForm ref="taskDelegateForm" @success="getDetail" />
  192. </ContentWrap>
  193. </template>
  194. <script lang="ts" setup>
  195. import dayjs from 'dayjs'
  196. import * as UserApi from '@/api/system/user'
  197. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  198. import * as DefinitionApi from '@/api/bpm/definition'
  199. import * as TaskApi from '@/api/bpm/task'
  200. import * as ActivityApi from '@/api/bpm/activity'
  201. import { formatPast2 } from '@/utils/formatTime'
  202. import { setConfAndFields2 } from '@/utils/formCreate'
  203. // import { OptionAttrs } from '@form-create/element-ui/types/config'
  204. import type { ApiAttrs } from '@form-create/element-ui/types/config'
  205. import { useUserStore } from '@/store/modules/user'
  206. import { MyProcessViewer } from '@/components/bpmnProcessDesigner/package'
  207. import TaskReturnDialog from './detail/TaskReturnDialogForm.vue'
  208. import TaskDelegateForm from './detail/taskDelegateForm.vue'
  209. defineOptions({ name: 'BpmProcessInstanceDetail' })
  210. const { query } = useRoute() // 查询参数
  211. const message = useMessage() // 消息弹窗
  212. const { t } = useI18n() // 国际化
  213. const { proxy } = getCurrentInstance() as any
  214. // ========== 审批信息 ==========
  215. const id = query.id as unknown as number
  216. const processInstanceLoading = ref(false) // 流程实例的加载中
  217. const processInstance = ref<any>({}) // 流程实例
  218. const runningTasks = ref<any[]>([]) // 运行中的任务
  219. const auditForms = ref<any[]>([]) // 审批任务的表单
  220. const auditRule = reactive({
  221. reason: [{ required: true, message: '审批建议不能为空', trigger: 'blur' }]
  222. })
  223. // 处理审批通过和不通过的操作
  224. const handleAudit = async (task, pass) => {
  225. // 1.1 获得对应表单
  226. const index = runningTasks.value.indexOf(task)
  227. const auditFormRef = proxy.$refs['form' + index][0]
  228. // alert(auditFormRef)
  229. // 1.2 校验表单
  230. const elForm = unref(auditFormRef)
  231. if (!elForm) return
  232. const valid = await elForm.validate()
  233. if (!valid) return
  234. // 2.1 提交审批
  235. const data = {
  236. id: task.id,
  237. reason: auditForms.value[index].reason
  238. }
  239. if (pass) {
  240. await TaskApi.approveTask(data)
  241. message.success('审批通过成功')
  242. } else {
  243. await TaskApi.rejectTask(data)
  244. message.success('审批不通过成功')
  245. }
  246. // 2.2 加载最新数据
  247. getDetail()
  248. }
  249. // ========== 申请信息 ==========
  250. const fApi = ref<ApiAttrs>()
  251. const userId = useUserStore().getUser.id // 当前登录的编号
  252. // 流程表单详情
  253. const detailForm = ref({
  254. rule: [],
  255. option: {},
  256. value: {}
  257. })
  258. // ========== 审批记录 ==========
  259. const tasksLoad = ref(true)
  260. const tasks = ref<any[]>([])
  261. const getTimelineItemIcon = (item) => {
  262. if (item.result === 1) {
  263. return 'el-icon-time'
  264. }
  265. if (item.result === 2) {
  266. return 'el-icon-check'
  267. }
  268. if (item.result === 3) {
  269. return 'el-icon-close'
  270. }
  271. if (item.result === 4) {
  272. return 'el-icon-remove-outline'
  273. }
  274. if (item.result === 5) {
  275. return 'el-icon-back'
  276. }
  277. return ''
  278. }
  279. const getTimelineItemType = (item) => {
  280. if (item.result === 1) {
  281. return 'primary'
  282. }
  283. if (item.result === 2) {
  284. return 'success'
  285. }
  286. if (item.result === 3) {
  287. return 'danger'
  288. }
  289. if (item.result === 4) {
  290. return 'info'
  291. }
  292. if (item.result === 5) {
  293. return 'warning'
  294. }
  295. if (item.result === 6) {
  296. return 'default'
  297. }
  298. return ''
  299. }
  300. // ========== 审批记录 ==========
  301. const updateAssigneeVisible = ref(false)
  302. const updateAssigneeLoading = ref(false)
  303. const updateAssigneeForm = ref({
  304. id: undefined,
  305. assigneeUserId: undefined
  306. })
  307. const updateAssigneeRules = ref({
  308. assigneeUserId: [{ required: true, message: '新审批人不能为空', trigger: 'change' }]
  309. })
  310. const updateAssigneeFormRef = ref()
  311. const userOptions = ref<any[]>([])
  312. // 处理转派审批人
  313. const handleUpdateAssignee = (task) => {
  314. // 设置表单
  315. resetUpdateAssigneeForm()
  316. updateAssigneeForm.value.id = task.id
  317. // 设置为打开
  318. updateAssigneeVisible.value = true
  319. }
  320. // 提交转派审批人
  321. const submitUpdateAssigneeForm = async () => {
  322. // 1. 校验表单
  323. const elForm = unref(updateAssigneeFormRef)
  324. if (!elForm) return
  325. const valid = await elForm.validate()
  326. if (!valid) return
  327. // 2.1 提交审批
  328. updateAssigneeLoading.value = true
  329. try {
  330. await TaskApi.updateTaskAssignee(updateAssigneeForm.value)
  331. // 2.2 设置为隐藏
  332. updateAssigneeVisible.value = false
  333. // 加载最新数据
  334. getDetail()
  335. } finally {
  336. updateAssigneeLoading.value = false
  337. }
  338. }
  339. // 重置转派审批人表单
  340. const resetUpdateAssigneeForm = () => {
  341. updateAssigneeForm.value = {
  342. id: undefined,
  343. assigneeUserId: undefined
  344. }
  345. updateAssigneeFormRef.value?.resetFields()
  346. }
  347. const taskDelegateForm = ref()
  348. /** 处理审批退回的操作 */
  349. const handleDelegate = async (task) => {
  350. taskDelegateForm.value.open(task.id)
  351. }
  352. //回退弹框组件
  353. const taskReturnDialogRef = ref()
  354. /** 处理审批退回的操作 */
  355. const handleBack = async (task) => {
  356. taskReturnDialogRef.value.open(task.id)
  357. }
  358. // ========== 高亮流程图 ==========
  359. const bpmnXML = ref(null)
  360. const bpmnControlForm = ref({
  361. prefix: 'flowable'
  362. })
  363. const activityList = ref([])
  364. // ========== 初始化 ==========
  365. onMounted(() => {
  366. // 加载详情
  367. getDetail()
  368. // 加载用户的列表
  369. UserApi.getListSimpleUsersApi().then((data) => {
  370. userOptions.value.push(...data)
  371. })
  372. })
  373. const getDetail = () => {
  374. // 1. 获得流程实例相关
  375. processInstanceLoading.value = true
  376. ProcessInstanceApi.getProcessInstanceApi(id)
  377. .then((data) => {
  378. if (!data) {
  379. message.error('查询不到流程信息!')
  380. return
  381. }
  382. processInstance.value = data
  383. // 设置表单信息
  384. const processDefinition = data.processDefinition
  385. if (processDefinition.formType === 10) {
  386. setConfAndFields2(
  387. detailForm,
  388. processDefinition.formConf,
  389. processDefinition.formFields,
  390. data.formVariables
  391. )
  392. nextTick().then(() => {
  393. fApi.value?.fapi?.btn.show(false)
  394. fApi.value?.fapi?.resetBtn.show(false)
  395. fApi.value?.fapi?.disabled(true)
  396. })
  397. }
  398. // 加载流程图
  399. DefinitionApi.getProcessDefinitionBpmnXMLApi(processDefinition.id).then((data) => {
  400. bpmnXML.value = data
  401. })
  402. // 加载活动列表
  403. ActivityApi.getActivityList({
  404. processInstanceId: data.id
  405. }).then((data) => {
  406. activityList.value = data
  407. })
  408. })
  409. .finally(() => {
  410. processInstanceLoading.value = false
  411. })
  412. // 2. 获得流程任务列表(审批记录)
  413. tasksLoad.value = true
  414. runningTasks.value = []
  415. auditForms.value = []
  416. TaskApi.getTaskListByProcessInstanceId(id)
  417. .then((data) => {
  418. // 审批记录
  419. tasks.value = []
  420. // 移除已取消的审批
  421. data.forEach((task) => {
  422. if (task.result !== 4) {
  423. tasks.value.push(task)
  424. }
  425. })
  426. // 排序,将未完成的排在前面,已完成的排在后面;
  427. tasks.value.sort((a, b) => {
  428. // 有已完成的情况,按照完成时间倒序
  429. if (a.endTime && b.endTime) {
  430. return b.endTime - a.endTime
  431. } else if (a.endTime) {
  432. return 1
  433. } else if (b.endTime) {
  434. return -1
  435. // 都是未完成,按照创建时间倒序
  436. } else {
  437. return b.createTime - a.createTime
  438. }
  439. })
  440. // 需要审核的记录
  441. tasks.value.forEach((task) => {
  442. // 1.1 只有待处理才需要
  443. if (task.result !== 1 && task.result !== 6) {
  444. return
  445. }
  446. // 1.2 自己不是处理人
  447. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  448. return
  449. }
  450. // 2. 添加到处理任务
  451. runningTasks.value.push({ ...task })
  452. auditForms.value.push({
  453. reason: ''
  454. })
  455. })
  456. })
  457. .finally(() => {
  458. tasksLoad.value = false
  459. })
  460. }
  461. </script>
  462. <style lang="scss" scoped>
  463. .my-process-designer {
  464. height: calc(100vh - 200px);
  465. }
  466. .box-card {
  467. width: 100%;
  468. margin-bottom: 20px;
  469. }
  470. </style>