detail.vue 8.4 KB

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