bpmTask.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <el-row v-bind="$attrs" v-loading="tasksLoad">
  3. <bpmSubmit
  4. v-if="currenItem"
  5. @handleAudit="handleAudit"
  6. :id="id"
  7. :taskId="currenItem.id"
  8. :businessId="businessId"
  9. :taskDefinitionKey="currenItem.taskDefinitionKey"
  10. ></bpmSubmit>
  11. <el-col :span="currenItem ? 12 : 24">
  12. <!-- 审批记录 -->
  13. <el-card class="box-card">
  14. <div slot="header" class="clearfix">
  15. <span class="el-icon-picture-outline">审批记录</span>
  16. </div>
  17. <div class="block details-bpm-list">
  18. <el-timeline>
  19. <el-timeline-item
  20. v-for="(item, index) in tasks"
  21. :key="index"
  22. :icon="getTimelineItemIcon(item)"
  23. :type="getTimelineItemType(item)"
  24. >
  25. <p style="font-weight: 700">任务:{{ item.name }}</p>
  26. <el-card :body-style="{ padding: '10px' }">
  27. <label
  28. v-if="item.assigneeUser"
  29. style="font-weight: normal; margin-right: 30px"
  30. >
  31. 审批人:{{ item.assigneeUser.nickname }}
  32. <el-tag type="info" size="mini">{{
  33. item.assigneeUser.deptName
  34. }}</el-tag>
  35. </label>
  36. <label style="font-weight: normal" v-if="item.createTime"
  37. >创建时间:</label
  38. >
  39. <label style="color: #8a909c; font-weight: normal">{{
  40. item.createTime
  41. }}</label>
  42. <label
  43. v-if="item.endTime"
  44. style="margin-left: 30px; font-weight: normal"
  45. >审批时间:</label
  46. >
  47. <label
  48. v-if="item.endTime"
  49. style="color: #8a909c; font-weight: normal"
  50. >
  51. {{ item.endTime }}</label
  52. >
  53. <label
  54. v-if="item.durationInMillis"
  55. style="margin-left: 30px; font-weight: normal"
  56. >耗时:</label
  57. >
  58. <label
  59. v-if="item.durationInMillis"
  60. style="color: #8a909c; font-weight: normal"
  61. >
  62. {{ getDateStar(item.durationInMillis) }}
  63. </label>
  64. <p v-if="item.reason">
  65. <el-tag :type="getTimelineItemType(item)">{{
  66. item.reason
  67. }}</el-tag>
  68. </p>
  69. </el-card>
  70. </el-timeline-item>
  71. </el-timeline>
  72. </div>
  73. </el-card>
  74. </el-col>
  75. </el-row>
  76. </template>
  77. <script>
  78. import {
  79. getProcessDefinitionBpmnXML,
  80. getProcessInstance,
  81. getActivityList,
  82. getTaskListByProcessInstanceId
  83. } from '@/api/produce/bom.js';
  84. import store from '@/store';
  85. // import { getProcessInstance } from '@/api/bpm/processInstance';
  86. import { getDate } from '@/utils/dateUtils';
  87. import dictMixins from '@/mixins/dictMixins';
  88. // import { getTaskListByProcessInstanceId } from '@/api/bpm/task';
  89. // import { getActivityList } from '@/api/bpm/activity';
  90. import bpmSubmit from './bpmSubmit.vue';
  91. // 流程实例的详情页,可用于审批
  92. export default {
  93. mixins: [dictMixins],
  94. components: { bpmSubmit },
  95. emits: ['handleAudit'],
  96. props: {
  97. // 流程id
  98. id: {
  99. default: ''
  100. },
  101. // 业务id
  102. businessId: {
  103. default: ''
  104. }
  105. },
  106. data() {
  107. return {
  108. // 遮罩层
  109. processInstanceLoading: true,
  110. dialogVisible: false,
  111. processInstance: {},
  112. // BPMN 数据
  113. bpmnXML: null,
  114. bpmnControlForm: {
  115. prefix: 'flowable'
  116. },
  117. activityList: [],
  118. // 审批记录
  119. tasksLoad: true,
  120. tasks: [],
  121. currenItem: null
  122. };
  123. },
  124. created() {
  125. // this.id = this.$route.query.id;
  126. // if (!this.id) {
  127. // this.$message.error('未传递 id 参数,无法查看流程信息');
  128. // return;
  129. // }
  130. this.getDetail();
  131. },
  132. methods: {
  133. /** 获得流程实例 */
  134. getDetail() {
  135. // 获得流程实例相关
  136. this.processInstanceLoading = true;
  137. getProcessInstance(this.id).then((response) => {
  138. if (!response) {
  139. this.$message.error('查询不到流程信息!');
  140. return;
  141. }
  142. // 设置流程信息
  143. this.processInstance = response;
  144. // //将业务表单,注册为动态组件
  145. // const path = this.processInstance.processDefinition.formCustomViewPath;
  146. // Vue.component("async-biz-form-component", function (resolve) {
  147. // require([`@/views${path}`], resolve);
  148. // });
  149. // 加载流程图
  150. getProcessDefinitionBpmnXML(
  151. this.processInstance.processDefinition.id
  152. ).then((response) => {
  153. this.bpmnXML = response;
  154. });
  155. // 加载活动列表
  156. getActivityList({
  157. processInstanceId: this.processInstance.id
  158. }).then((response) => {
  159. console.log(response, 'response');
  160. this.activityList = response;
  161. });
  162. // 取消加载中
  163. this.processInstanceLoading = false;
  164. });
  165. // 获得流程任务列表(审批记录)
  166. this.tasksLoad = true;
  167. getTaskListByProcessInstanceId(this.id).then((response) => {
  168. // 审批记录
  169. this.tasks = [];
  170. // 移除已取消的审批
  171. response.forEach((task) => {
  172. if (task.result !== 4) {
  173. this.tasks.push(task);
  174. }
  175. });
  176. // 排序,将未完成的排在前面,已完成的排在后面;
  177. this.tasks.sort((a, b) => {
  178. // 有已完成的情况,按照完成时间倒序
  179. if (a.endTime && b.endTime) {
  180. return b.endTime - a.endTime;
  181. } else if (a.endTime) {
  182. return 1;
  183. } else if (b.endTime) {
  184. return -1;
  185. // 都是未完成,按照创建时间倒序
  186. } else {
  187. return b.createTime - a.createTime;
  188. }
  189. });
  190. // 需要审核的记录
  191. const userId = store.getters.userId;
  192. this.tasks.forEach((task) => {
  193. if (task.result !== 1 && task.result !== 6) {
  194. // 只有待处理才需要
  195. return;
  196. }
  197. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  198. // 自己不是处理人
  199. return;
  200. }
  201. });
  202. const currenItem = this.tasks.find((i) => i.result == 1);
  203. if (currenItem) {
  204. // 当前处理中的节点
  205. this.currenItem = currenItem;
  206. }
  207. // 取消加载中
  208. this.tasksLoad = false;
  209. });
  210. },
  211. getDateStar(ms) {
  212. return getDate(ms);
  213. },
  214. getTimelineItemIcon(item) {
  215. if (item.result === 1) {
  216. return 'el-icon-time';
  217. }
  218. if (item.result === 2) {
  219. return 'el-icon-check';
  220. }
  221. if (item.result === 3) {
  222. return 'el-icon-close';
  223. }
  224. if (item.result === 4) {
  225. return 'el-icon-remove-outline';
  226. }
  227. if (item.result === 5) {
  228. return 'el-icon-back';
  229. }
  230. return '';
  231. },
  232. getTimelineItemType(item) {
  233. if (item.result === 1) {
  234. return 'primary';
  235. }
  236. if (item.result === 2) {
  237. return 'success';
  238. }
  239. if (item.result === 3) {
  240. return 'danger';
  241. }
  242. if (item.result === 4) {
  243. return 'info';
  244. }
  245. if (item.result === 5) {
  246. return 'warning';
  247. }
  248. if (item.result === 6) {
  249. return 'default';
  250. }
  251. return '';
  252. },
  253. handleAudit(e) {
  254. this.$emit('handleAudit', e);
  255. }
  256. }
  257. };
  258. </script>
  259. <style lang="scss">
  260. .my-process-designer {
  261. height: calc(100vh - 200px);
  262. }
  263. .box-card {
  264. width: 100%;
  265. margin-bottom: 20px;
  266. }
  267. .details-bpm-list {
  268. max-height: 120px;
  269. overflow-y: auto;
  270. }
  271. </style>