detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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-left: 10%; margin-bottom: 20px; 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="font-weight: normal; margin-right: 30px">
  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="color: #8a909c; font-weight: normal">
  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="color: #8a909c; font-weight: normal">
  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="color: #8a909c; font-weight: normal">
  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. </ContentWrap>
  189. </template>
  190. <script lang="ts" setup>
  191. import dayjs from 'dayjs'
  192. import * as UserApi from '@/api/system/user'
  193. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  194. import * as DefinitionApi from '@/api/bpm/definition'
  195. import * as TaskApi from '@/api/bpm/task'
  196. import * as ActivityApi from '@/api/bpm/activity'
  197. import { formatPast2 } from '@/utils/formatTime'
  198. import { setConfAndFields2 } from '@/utils/formCreate'
  199. // import { OptionAttrs } from '@form-create/element-ui/types/config'
  200. import type { ApiAttrs } from '@form-create/element-ui/types/config'
  201. import { useUserStore } from '@/store/modules/user'
  202. import { MyProcessViewer } from '@/components/bpmnProcessDesigner/package'
  203. defineOptions({ name: 'BpmProcessInstanceDetail' })
  204. const { query } = useRoute() // 查询参数
  205. const message = useMessage() // 消息弹窗
  206. const { t } = useI18n() // 国际化
  207. const { proxy } = getCurrentInstance() as any
  208. // ========== 审批信息 ==========
  209. const id = query.id as unknown as number
  210. const processInstanceLoading = ref(false) // 流程实例的加载中
  211. const processInstance = ref<any>({}) // 流程实例
  212. const runningTasks = ref<any[]>([]) // 运行中的任务
  213. const auditForms = ref<any[]>([]) // 审批任务的表单
  214. const auditRule = reactive({
  215. reason: [{ required: true, message: '审批建议不能为空', trigger: 'blur' }]
  216. })
  217. // 处理审批通过和不通过的操作
  218. const handleAudit = async (task, pass) => {
  219. // 1.1 获得对应表单
  220. const index = runningTasks.value.indexOf(task)
  221. const auditFormRef = proxy.$refs['form' + index][0]
  222. // alert(auditFormRef)
  223. // 1.2 校验表单
  224. const elForm = unref(auditFormRef)
  225. if (!elForm) return
  226. const valid = await elForm.validate()
  227. if (!valid) return
  228. // 2.1 提交审批
  229. const data = {
  230. id: task.id,
  231. reason: auditForms.value[index].reason
  232. }
  233. if (pass) {
  234. await TaskApi.approveTask(data)
  235. message.success('审批通过成功')
  236. } else {
  237. await TaskApi.rejectTask(data)
  238. message.success('审批不通过成功')
  239. }
  240. // 2.2 加载最新数据
  241. getDetail()
  242. }
  243. // ========== 申请信息 ==========
  244. const fApi = ref<ApiAttrs>()
  245. const userId = useUserStore().getUser.id // 当前登录的编号
  246. // 流程表单详情
  247. const detailForm = ref({
  248. rule: [],
  249. option: {},
  250. value: {}
  251. })
  252. // ========== 审批记录 ==========
  253. const tasksLoad = ref(true)
  254. const tasks = ref<any[]>([])
  255. const getTimelineItemIcon = (item) => {
  256. if (item.result === 1) {
  257. return 'el-icon-time'
  258. }
  259. if (item.result === 2) {
  260. return 'el-icon-check'
  261. }
  262. if (item.result === 3) {
  263. return 'el-icon-close'
  264. }
  265. if (item.result === 4) {
  266. return 'el-icon-remove-outline'
  267. }
  268. return ''
  269. }
  270. const getTimelineItemType = (item) => {
  271. if (item.result === 1) {
  272. return 'primary'
  273. }
  274. if (item.result === 2) {
  275. return 'success'
  276. }
  277. if (item.result === 3) {
  278. return 'danger'
  279. }
  280. if (item.result === 4) {
  281. return 'info'
  282. }
  283. return ''
  284. }
  285. // ========== 审批记录 ==========
  286. const updateAssigneeVisible = ref(false)
  287. const updateAssigneeLoading = ref(false)
  288. const updateAssigneeForm = ref({
  289. id: undefined,
  290. assigneeUserId: undefined
  291. })
  292. const updateAssigneeRules = ref({
  293. assigneeUserId: [{ required: true, message: '新审批人不能为空', trigger: 'change' }]
  294. })
  295. const updateAssigneeFormRef = ref()
  296. const userOptions = ref<any[]>([])
  297. // 处理转派审批人
  298. const handleUpdateAssignee = (task) => {
  299. // 设置表单
  300. resetUpdateAssigneeForm()
  301. updateAssigneeForm.value.id = task.id
  302. // 设置为打开
  303. updateAssigneeVisible.value = true
  304. }
  305. // 提交转派审批人
  306. const submitUpdateAssigneeForm = async () => {
  307. // 1. 校验表单
  308. const elForm = unref(updateAssigneeFormRef)
  309. if (!elForm) return
  310. const valid = await elForm.validate()
  311. if (!valid) return
  312. // 2.1 提交审批
  313. updateAssigneeLoading.value = true
  314. try {
  315. await TaskApi.updateTaskAssignee(updateAssigneeForm.value)
  316. // 2.2 设置为隐藏
  317. updateAssigneeVisible.value = false
  318. // 加载最新数据
  319. getDetail()
  320. } finally {
  321. updateAssigneeLoading.value = false
  322. }
  323. }
  324. // 重置转派审批人表单
  325. const resetUpdateAssigneeForm = () => {
  326. updateAssigneeForm.value = {
  327. id: undefined,
  328. assigneeUserId: undefined
  329. }
  330. updateAssigneeFormRef.value?.resetFields()
  331. }
  332. /** 处理审批退回的操作 */
  333. const handleDelegate = async (task) => {
  334. message.error('暂不支持【委派】功能,可以使用【转派】替代!')
  335. console.log(task)
  336. }
  337. /** 处理审批退回的操作 */
  338. const handleBack = async (task) => {
  339. message.error('暂不支持【退回】功能!')
  340. // 可参考 http://blog.wya1.com/article/636697030/details/7296
  341. // const data = {
  342. // id: task.id,
  343. // assigneeUserId: 1
  344. // }
  345. // backTask(data).then(response => {
  346. // this.$modal.msgSuccess("回退成功!");
  347. // this.getDetail(); // 获得最新详情
  348. // });
  349. console.log(task)
  350. }
  351. // ========== 高亮流程图 ==========
  352. const bpmnXML = ref(null)
  353. const bpmnControlForm = ref({
  354. prefix: 'flowable'
  355. })
  356. const activityList = ref([])
  357. // ========== 初始化 ==========
  358. onMounted(() => {
  359. // 加载详情
  360. getDetail()
  361. // 加载用户的列表
  362. UserApi.getListSimpleUsersApi().then((data) => {
  363. userOptions.value.push(...data)
  364. })
  365. })
  366. const getDetail = () => {
  367. // 1. 获得流程实例相关
  368. processInstanceLoading.value = true
  369. ProcessInstanceApi.getProcessInstanceApi(id)
  370. .then((data) => {
  371. if (!data) {
  372. message.error('查询不到流程信息!')
  373. return
  374. }
  375. processInstance.value = data
  376. // 设置表单信息
  377. const processDefinition = data.processDefinition
  378. if (processDefinition.formType === 10) {
  379. setConfAndFields2(
  380. detailForm,
  381. processDefinition.formConf,
  382. processDefinition.formFields,
  383. data.formVariables
  384. )
  385. nextTick().then(() => {
  386. fApi.value?.fapi?.btn.show(false)
  387. fApi.value?.fapi?.resetBtn.show(false)
  388. fApi.value?.fapi?.disabled(true)
  389. })
  390. }
  391. // 加载流程图
  392. DefinitionApi.getProcessDefinitionBpmnXMLApi(processDefinition.id).then((data) => {
  393. bpmnXML.value = data
  394. })
  395. // 加载活动列表
  396. ActivityApi.getActivityList({
  397. processInstanceId: data.id
  398. }).then((data) => {
  399. activityList.value = data
  400. })
  401. })
  402. .finally(() => {
  403. processInstanceLoading.value = false
  404. })
  405. // 2. 获得流程任务列表(审批记录)
  406. tasksLoad.value = true
  407. runningTasks.value = []
  408. auditForms.value = []
  409. TaskApi.getTaskListByProcessInstanceId(id)
  410. .then((data) => {
  411. // 审批记录
  412. tasks.value = []
  413. // 移除已取消的审批
  414. data.forEach((task) => {
  415. if (task.result !== 4) {
  416. tasks.value.push(task)
  417. }
  418. })
  419. // 排序,将未完成的排在前面,已完成的排在后面;
  420. tasks.value.sort((a, b) => {
  421. // 有已完成的情况,按照完成时间倒序
  422. if (a.endTime && b.endTime) {
  423. return b.endTime - a.endTime
  424. } else if (a.endTime) {
  425. return 1
  426. } else if (b.endTime) {
  427. return -1
  428. // 都是未完成,按照创建时间倒序
  429. } else {
  430. return b.createTime - a.createTime
  431. }
  432. })
  433. // 需要审核的记录
  434. tasks.value.forEach((task) => {
  435. // 1.1 只有待处理才需要
  436. if (task.result !== 1) {
  437. return
  438. }
  439. // 1.2 自己不是处理人
  440. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  441. return
  442. }
  443. // 2. 添加到处理任务
  444. runningTasks.value.push({ ...task })
  445. auditForms.value.push({
  446. reason: ''
  447. })
  448. })
  449. })
  450. .finally(() => {
  451. tasksLoad.value = false
  452. })
  453. }
  454. </script>
  455. <style lang="scss" scoped>
  456. .my-process-designer {
  457. height: calc(100vh - 200px);
  458. }
  459. .box-card {
  460. width: 100%;
  461. margin-bottom: 20px;
  462. }
  463. </style>