detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div class="app-container">
  3. <!-- 审批信息 -->
  4. <el-card class="box-card" v-loading="processInstanceLoading" v-for="(item, index) in runningTasks" :key="index">
  5. <div slot="header" class="clearfix">
  6. <span class="el-icon-picture-outline">审批任务【{{ item.name }}】</span>
  7. </div>
  8. <el-col :span="16" :offset="6" >
  9. <el-form :ref="'form' + index" :model="auditForms[index]" :rules="auditRule" label-width="100px">
  10. <el-form-item label="流程名" v-if="processInstance && processInstance.name">
  11. {{ processInstance.name }}
  12. </el-form-item>
  13. <el-form-item label="流程发起人" v-if="processInstance && processInstance.startUser">
  14. {{ processInstance.startUser.nickname }}
  15. <el-tag type="info" size="mini">{{ processInstance.startUser.deptName }}</el-tag>
  16. </el-form-item>
  17. <el-form-item label="审批建议" prop="comment">
  18. <el-input type="textarea" v-model="auditForms[index].comment" placeholder="请输入审批建议" />
  19. </el-form-item>
  20. </el-form>
  21. <div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px;">
  22. <el-button icon="el-icon-edit-outline" type="success" size="mini" @click="handleAudit(item, true)">通过</el-button>
  23. <el-button icon="el-icon-circle-close" type="danger" size="mini" @click="handleAudit(item, false)">不通过</el-button>
  24. <el-button icon="el-icon-edit-outline" type="primary" size="mini" @click="handleUpdateAssignee(item)">转办</el-button>
  25. <el-button icon="el-icon-edit-outline" type="primary" size="mini" @click="handleDelegate(item)">委派</el-button>
  26. <el-button icon="el-icon-refresh-left" type="warning" size="mini" @click="handleBack(item)">退回</el-button>
  27. </div>
  28. </el-col>
  29. </el-card>
  30. <!-- 申请信息 -->
  31. <el-card class="box-card" v-loading="processInstanceLoading">
  32. <div slot="header" class="clearfix">
  33. <span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
  34. </div>
  35. <el-col v-if="this.processInstance.processDefinition && this.processInstance.processDefinition.formType === 10"
  36. :span="16" :offset="6">
  37. <div >
  38. <parser :key="new Date().getTime()" :form-conf="detailForm" @submit="submitForm" />
  39. </div>
  40. </el-col>
  41. <div v-if="this.processInstance.processDefinition && this.processInstance.processDefinition.formType === 20">
  42. <router-link :to="this.processInstance.processDefinition.formCustomViewPath + '?id='
  43. + this.processInstance.businessKey">
  44. <el-button type="primary">点击查看</el-button>
  45. </router-link>
  46. </div>
  47. </el-card>
  48. <el-card class="box-card" v-loading="tasksLoad">
  49. <div slot="header" class="clearfix">
  50. <span class="el-icon-picture-outline">审批记录</span>
  51. </div>
  52. <el-col :span="16" :offset="4" >
  53. <div class="block">
  54. <el-timeline>
  55. <el-timeline-item v-for="(item, index) in tasks" :key="index"
  56. :icon="getTimelineItemIcon(item)" :type="getTimelineItemType(item)">
  57. <p style="font-weight: 700">任务:{{ item.name }}</p>
  58. <el-card :body-style="{ padding: '10px' }">
  59. <label v-if="item.assigneeUser" style="font-weight: normal; margin-right: 30px;">
  60. 审批人:{{ item.assigneeUser.nickname }}
  61. <el-tag type="info" size="mini">{{ item.assigneeUser.deptName }}</el-tag>
  62. </label>
  63. <label style="font-weight: normal">创建时间:</label>
  64. <label style="color:#8a909c; font-weight: normal">{{ parseTime(item.createTime) }}</label>
  65. <label v-if="item.endTime" style="margin-left: 30px;font-weight: normal">审批时间:</label>
  66. <label v-if="item.endTime" style="color:#8a909c;font-weight: normal"> {{ parseTime(item.endTime) }}</label>
  67. <label v-if="item.durationInMillis" style="margin-left: 30px;font-weight: normal">耗时:</label>
  68. <label v-if="item.durationInMillis" style="color:#8a909c;font-weight: normal"> {{ getDateStar(item.durationInMillis) }} </label>
  69. <p v-if="item.comment">
  70. <el-tag :type="getTimelineItemType(item)">{{ item.comment }}</el-tag>
  71. </p>
  72. </el-card>
  73. </el-timeline-item>
  74. </el-timeline>
  75. </div>
  76. </el-col>
  77. </el-card>
  78. <!-- 高亮流程图 -->
  79. <el-card class="box-card" v-loading="processInstanceLoading">
  80. <div slot="header" class="clearfix">
  81. <span class="el-icon-picture-outline">流程图</span>
  82. </div>
  83. <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" :activityData="activityList"
  84. :processInstanceData="processInstance" :taskData="tasks" />
  85. </el-card>
  86. <!-- 对话框(转派审批人) -->
  87. <el-dialog title="转派审批人" :visible.sync="updateAssignee.open" width="500px" append-to-body>
  88. <el-form ref="updateAssigneeForm" :model="updateAssignee.form" :rules="updateAssignee.rules" label-width="110px">
  89. <el-form-item label="新审批人" prop="assigneeUserId">
  90. <el-select v-model="updateAssignee.form.assigneeUserId" clearable style="width: 100%">
  91. <el-option v-for="item in userOptions" :key="parseInt(item.id)" :label="item.nickname" :value="parseInt(item.id)" />
  92. </el-select>
  93. </el-form-item>
  94. </el-form>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="submitUpdateAssigneeForm">确 定</el-button>
  97. <el-button @click="cancelUpdateAssigneeForm">取 消</el-button>
  98. </div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import {getProcessDefinitionBpmnXML} from "@/api/bpm/definition";
  104. import {DICT_TYPE, getDictDatas} from "@/utils/dict";
  105. import store from "@/store";
  106. import {decodeFields} from "@/utils/formGenerator";
  107. import Parser from '@/components/parser/Parser'
  108. import {createProcessInstance, getProcessInstance} from "@/api/bpm/processInstance";
  109. import {approveTask, getTaskListByProcessInstanceId, rejectTask, updateTaskAssignee} from "@/api/bpm/task";
  110. import {getDate} from "@/utils/dateUtils";
  111. import {listSimpleUsers} from "@/api/system/user";
  112. import {getActivityList} from "@/api/bpm/activity";
  113. // 流程实例的详情页,可用于审批
  114. export default {
  115. name: "ProcessInstanceDetail",
  116. components: {
  117. Parser
  118. },
  119. data() {
  120. return {
  121. // 遮罩层
  122. processInstanceLoading: true,
  123. // 流程实例
  124. id: undefined, // 流程实例的编号
  125. processInstance: {},
  126. // 流程表单详情
  127. detailForm: {
  128. fields: []
  129. },
  130. // BPMN 数据
  131. bpmnXML: null,
  132. bpmnControlForm: {
  133. prefix: "activiti"
  134. },
  135. activityList: [],
  136. // 审批记录
  137. tasksLoad: true,
  138. tasks: [],
  139. // 审批表单
  140. runningTasks: [],
  141. auditForms: [],
  142. auditRule: {
  143. comment: [{ required: true, message: "审批建议不能为空", trigger: "blur" }],
  144. },
  145. // 转派审批人
  146. userOptions: [],
  147. updateAssignee: {
  148. open: false,
  149. form: {
  150. assigneeUserId: undefined,
  151. },
  152. rules: {
  153. assigneeUserId: [{ required: true, message: "新审批人不能为空", trigger: "change" }],
  154. }
  155. },
  156. // 数据字典
  157. categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
  158. };
  159. },
  160. created() {
  161. this.id = this.$route.query.id;
  162. if (!this.id) {
  163. this.$message.error('未传递 id 参数,无法查看流程信息');
  164. return;
  165. }
  166. this.getDetail();
  167. // 获得用户列表
  168. this.userOptions = [];
  169. listSimpleUsers().then(response => {
  170. this.userOptions.push(...response.data);
  171. });
  172. },
  173. methods: {
  174. /** 获得流程实例 */
  175. getDetail() {
  176. // 获得流程实例相关
  177. this.processInstanceLoading = true;
  178. getProcessInstance(this.id).then(response => {
  179. if (!response.data) {
  180. this.$message.error('查询不到流程信息!');
  181. return;
  182. }
  183. // 设置流程信息
  184. this.processInstance = response.data;
  185. // 设置表单信息
  186. if (this.processInstance.processDefinition.formType === 10) {
  187. this.detailForm = {
  188. ...JSON.parse(this.processInstance.processDefinition.formConf),
  189. disabled: true, // 表单禁用
  190. formBtns: false, // 按钮隐藏
  191. fields: decodeFields(this.processInstance.processDefinition.formFields)
  192. }
  193. // 设置表单的值
  194. this.detailForm.fields.forEach(item => {
  195. const val = this.processInstance.formVariables[item.__vModel__]
  196. if (val) {
  197. item.__config__.defaultValue = val
  198. }
  199. });
  200. }
  201. // 加载流程图
  202. getProcessDefinitionBpmnXML(this.processInstance.processDefinition.id).then(response => {
  203. this.bpmnXML = response.data
  204. });
  205. // 加载活动列表
  206. getActivityList({
  207. processInstanceId: this.processInstance.id
  208. }).then(response => {
  209. this.activityList = response.data;
  210. });
  211. // 取消加载中
  212. this.processInstanceLoading = false;
  213. });
  214. // 获得流程任务列表(审批记录)
  215. this.tasksLoad = true;
  216. this.runningTasks = [];
  217. this.auditForms = [];
  218. getTaskListByProcessInstanceId(this.id).then(response => {
  219. // 审批记录
  220. this.tasks = response.data;
  221. // 排序,将未完成的排在前面,已完成的排在后面;
  222. this.tasks.sort((a, b) => {
  223. // 有已完成的情况,按照完成时间倒序
  224. if (a.endTime && b.endTime) {
  225. return b.endTime - a.endTime;
  226. } else if (a.endTime) {
  227. return 1;
  228. } else if (b.endTime) {
  229. return -1;
  230. // 都是未完成,按照创建时间倒序
  231. } else {
  232. return b.createTime - a.createTime;
  233. }
  234. });
  235. // 需要审核的记录
  236. const userId = store.getters.userId;
  237. this.tasks.forEach(task => {
  238. if (task.result !== 1) { // 只有待处理才需要
  239. return;
  240. }
  241. if (!task.assigneeUser || task.assigneeUser.id !== userId) { // 自己不是处理人
  242. return;
  243. }
  244. this.runningTasks.push({...task});
  245. this.auditForms.push({
  246. comment: ''
  247. })
  248. });
  249. // 取消加载中
  250. this.tasksLoad = false;
  251. });
  252. },
  253. /** 处理选择流程的按钮操作 **/
  254. handleSelect(row) {
  255. // 设置选择的流程
  256. this.selectProcessInstance = row;
  257. // 流程表单
  258. if (row.formId) {
  259. // 设置对应的表单
  260. this.detailForm = {
  261. ...JSON.parse(row.formConf),
  262. fields: decodeFields(row.formFields)
  263. }
  264. } else if (row.formCustomCreatePath) {
  265. this.$router.push({ path: row.formCustomCreatePath});
  266. // 这里暂时无需加载流程图,因为跳出到另外个 Tab;
  267. }
  268. },
  269. /** 提交按钮 */
  270. submitForm(params) {
  271. if (!params) {
  272. return;
  273. }
  274. // 设置表单禁用
  275. const conf = params.conf;
  276. conf.disabled = true; // 表单禁用
  277. conf.formBtns = false; // 按钮隐藏
  278. // 提交表单,创建流程
  279. const variables = params.values;
  280. createProcessInstance({
  281. processDefinitionId: this.selectProcessInstance.id,
  282. variables: variables
  283. }).then(response => {
  284. this.msgSuccess("发起流程成功");
  285. // 关闭当前窗口
  286. this.$store.dispatch("tagsView/delView", this.$route);
  287. this.$router.go(-1);
  288. }).catch(() => {
  289. conf.disabled = false; // 表单开启
  290. conf.formBtns = true; // 按钮展示
  291. })
  292. },
  293. getDateStar(ms) {
  294. return getDate(ms);
  295. },
  296. getTimelineItemIcon(item) {
  297. if (item.result === 1) {
  298. return 'el-icon-time';
  299. }
  300. if (item.result === 2) {
  301. return 'el-icon-check';
  302. }
  303. if (item.result === 3) {
  304. return 'el-icon-close';
  305. }
  306. if (item.result === 4) {
  307. return 'el-icon-remove-outline';
  308. }
  309. return '';
  310. },
  311. getTimelineItemType(item) {
  312. if (item.result === 1) {
  313. return 'primary';
  314. }
  315. if (item.result === 2) {
  316. return 'success';
  317. }
  318. if (item.result === 3) {
  319. return 'danger';
  320. }
  321. if (item.result === 4) {
  322. return 'info';
  323. }
  324. return '';
  325. },
  326. /** 处理审批通过和不通过的操作 */
  327. handleAudit(task, pass) {
  328. const index = this.runningTasks.indexOf(task);
  329. this.$refs['form' + index][0].validate(valid => {
  330. if (!valid) {
  331. return;
  332. }
  333. const data = {
  334. id: task.id,
  335. comment: this.auditForms[index].comment
  336. }
  337. if (pass) {
  338. approveTask(data).then(response => {
  339. this.msgSuccess("审批通过成功!");
  340. this.getDetail(); // 获得最新详情
  341. });
  342. } else {
  343. rejectTask(data).then(response => {
  344. this.msgSuccess("审批不通过成功!");
  345. this.getDetail(); // 获得最新详情
  346. });
  347. }
  348. });
  349. },
  350. /** 处理转派审批人 */
  351. handleUpdateAssignee(task) {
  352. // 设置表单
  353. this.resetUpdateAssigneeForm();
  354. this.updateAssignee.form.id = task.id;
  355. // 设置为打开
  356. this.updateAssignee.open = true;
  357. },
  358. /** 提交转派审批人 */
  359. submitUpdateAssigneeForm() {
  360. this.$refs['updateAssigneeForm'].validate(valid => {
  361. if (!valid) {
  362. return;
  363. }
  364. updateTaskAssignee(this.updateAssignee.form).then(response => {
  365. this.msgSuccess("转派任务成功!");
  366. this.updateAssignee.open = false;
  367. this.getDetail(); // 获得最新详情
  368. });
  369. });
  370. },
  371. /** 取消转派审批人 */
  372. cancelUpdateAssigneeForm() {
  373. this.updateAssignee.open = false;
  374. this.resetUpdateAssigneeForm();
  375. },
  376. /** 重置转派审批人 */
  377. resetUpdateAssigneeForm() {
  378. this.updateAssignee.form = {
  379. id: undefined,
  380. assigneeUserId: undefined,
  381. };
  382. this.resetForm("updateAssigneeForm");
  383. },
  384. /** 处理审批退回的操作 */
  385. handleDelegate(task) {
  386. this.msgError("暂不支持【委派】功能,可以使用【转派】替代!");
  387. },
  388. /** 处理审批退回的操作 */
  389. handleBack(task) {
  390. this.msgError("暂不支持【退回】功能!");
  391. }
  392. }
  393. };
  394. </script>
  395. <style lang="scss">
  396. .my-process-designer {
  397. height: calc(100vh - 200px);
  398. }
  399. .box-card {
  400. width: 100%;
  401. margin-bottom: 20px;
  402. }
  403. </style>