detail.vue 14 KB

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