detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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="tasks" />
  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. // 流程实例的详情页,可用于审批
  105. export default {
  106. name: "ProcessInstanceDetail",
  107. components: {
  108. Parser
  109. },
  110. data() {
  111. return {
  112. // 遮罩层
  113. processInstanceLoading: true,
  114. // 流程实例
  115. id: undefined, // 流程实例的编号
  116. processInstance: {},
  117. // 流程表单详情
  118. detailForm: {
  119. fields: []
  120. },
  121. // BPMN 数据
  122. bpmnXML: null,
  123. bpmnControlForm: {
  124. prefix: "activiti"
  125. },
  126. // 审批记录
  127. tasksLoad: true,
  128. tasks: [],
  129. // 审批表单
  130. runningTasks: [],
  131. auditForms: [],
  132. auditRule: {
  133. comment: [{ required: true, message: "审批建议不能为空", trigger: "blur" }],
  134. },
  135. // 转派审批人
  136. userOptions: [],
  137. updateAssignee: {
  138. open: false,
  139. form: {
  140. assigneeUserId: undefined,
  141. },
  142. rules: {
  143. assigneeUserId: [{ required: true, message: "新审批人不能为空", trigger: "change" }],
  144. }
  145. },
  146. // 数据字典
  147. categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
  148. };
  149. },
  150. created() {
  151. this.id = this.$route.query.id;
  152. if (!this.id) {
  153. this.$message.error('未传递 id 参数,无法查看流程信息');
  154. return;
  155. }
  156. this.getDetail();
  157. // 获得用户列表
  158. this.userOptions = [];
  159. listSimpleUsers().then(response => {
  160. this.userOptions.push(...response.data);
  161. });
  162. },
  163. methods: {
  164. /** 获得流程实例 */
  165. getDetail() {
  166. // 获得流程实例相关
  167. this.processInstanceLoading = true;
  168. getProcessInstance(this.id).then(response => {
  169. if (!response.data) {
  170. this.$message.error('查询不到流程信息!');
  171. return;
  172. }
  173. // 设置流程信息
  174. this.processInstance = response.data;
  175. // 设置表单信息
  176. this.detailForm = {
  177. ...JSON.parse(this.processInstance.processDefinition.formConf),
  178. disabled: true, // 表单禁用
  179. formBtns: false, // 按钮隐藏
  180. fields: decodeFields(this.processInstance.processDefinition.formFields)
  181. }
  182. // 设置表单的值
  183. this.detailForm.fields.forEach(item => {
  184. const val = this.processInstance.formVariables[item.__vModel__]
  185. if (val) {
  186. item.__config__.defaultValue = val
  187. }
  188. })
  189. // 加载流程图
  190. getProcessDefinitionBpmnXML(this.processInstance.processDefinition.id).then(response => {
  191. this.bpmnXML = response.data
  192. })
  193. // 取消加载中
  194. this.processInstanceLoading = false;
  195. });
  196. // 获得流程任务列表(审批记录)
  197. this.tasksLoad = true;
  198. this.runningTasks = [];
  199. this.auditForms = [];
  200. getTaskListByProcessInstanceId(this.id).then(response => {
  201. // 审批记录
  202. this.tasks = response.data;
  203. // 排序,将未完成的排在前面,已完成的排在后面;
  204. this.tasks.sort((a, b) => {
  205. // 有已完成的情况,按照完成时间倒序
  206. if (a.endTime && b.endTime) {
  207. return b.endTime - a.endTime;
  208. } else if (a.endTime) {
  209. return 1;
  210. } else if (b.endTime) {
  211. return -1;
  212. // 都是未完成,按照创建时间倒序
  213. } else {
  214. return b.createTime - a.createTime;
  215. }
  216. });
  217. // 需要审核的记录
  218. const userId = store.getters.userId;
  219. this.tasks.forEach(task => {
  220. if (task.result !== 1) { // 只有待处理才需要
  221. return;
  222. }
  223. if (!task.assigneeUser || task.assigneeUser.id !== userId) { // 自己不是处理人
  224. return;
  225. }
  226. this.runningTasks.push({...task});
  227. this.auditForms.push({
  228. comment: ''
  229. })
  230. });
  231. // 取消加载中
  232. this.tasksLoad = false;
  233. });
  234. },
  235. /** 处理选择流程的按钮操作 **/
  236. handleSelect(row) {
  237. // 设置选择的流程
  238. this.selectProcessInstance = row;
  239. // 流程表单
  240. if (row.formId) {
  241. // 设置对应的表单
  242. this.detailForm = {
  243. ...JSON.parse(row.formConf),
  244. fields: decodeFields(row.formFields)
  245. }
  246. } else if (row.formCustomCreatePath) {
  247. this.$router.push({ path: row.formCustomCreatePath});
  248. // 这里暂时无需加载流程图,因为跳出到另外个 Tab;
  249. }
  250. },
  251. /** 提交按钮 */
  252. submitForm(params) {
  253. if (!params) {
  254. return;
  255. }
  256. // 设置表单禁用
  257. const conf = params.conf;
  258. conf.disabled = true; // 表单禁用
  259. conf.formBtns = false; // 按钮隐藏
  260. // 提交表单,创建流程
  261. const variables = params.values;
  262. createProcessInstance({
  263. processDefinitionId: this.selectProcessInstance.id,
  264. variables: variables
  265. }).then(response => {
  266. this.msgSuccess("发起流程成功");
  267. // 关闭当前窗口
  268. this.$store.dispatch("tagsView/delView", this.$route);
  269. this.$router.go(-1);
  270. }).catch(() => {
  271. conf.disabled = false; // 表单开启
  272. conf.formBtns = true; // 按钮展示
  273. })
  274. },
  275. getDateStar(ms) {
  276. return getDate(ms);
  277. },
  278. getTimelineItemIcon(item) {
  279. if (item.result === 1) {
  280. return 'el-icon-time';
  281. }
  282. if (item.result === 2) {
  283. return 'el-icon-check';
  284. }
  285. if (item.result === 3) {
  286. return 'el-icon-close';
  287. }
  288. if (item.result === 4) {
  289. return 'el-icon-remove-outline';
  290. }
  291. return '';
  292. },
  293. getTimelineItemType(item) {
  294. if (item.result === 1) {
  295. return 'primary';
  296. }
  297. if (item.result === 2) {
  298. return 'success';
  299. }
  300. if (item.result === 3) {
  301. return 'danger';
  302. }
  303. if (item.result === 4) {
  304. return 'info';
  305. }
  306. return '';
  307. },
  308. /** 处理审批通过和不通过的操作 */
  309. handleAudit(task, pass) {
  310. const index = this.runningTasks.indexOf(task);
  311. this.$refs['form' + index][0].validate(valid => {
  312. if (!valid) {
  313. return;
  314. }
  315. const data = {
  316. id: task.id,
  317. comment: this.auditForms[index].comment
  318. }
  319. if (pass) {
  320. approveTask(data).then(response => {
  321. this.msgSuccess("审批通过成功!");
  322. this.getDetail(); // 获得最新详情
  323. });
  324. } else {
  325. rejectTask(data).then(response => {
  326. this.msgSuccess("审批不通过成功!");
  327. this.getDetail(); // 获得最新详情
  328. });
  329. }
  330. });
  331. },
  332. /** 处理转派审批人 */
  333. handleUpdateAssignee(task) {
  334. // 设置表单
  335. this.resetUpdateAssigneeForm();
  336. this.updateAssignee.form.id = task.id;
  337. // 设置为打开
  338. this.updateAssignee.open = true;
  339. },
  340. /** 提交转派审批人 */
  341. submitUpdateAssigneeForm() {
  342. this.$refs['updateAssigneeForm'].validate(valid => {
  343. if (!valid) {
  344. return;
  345. }
  346. updateTaskAssignee(this.updateAssignee.form).then(response => {
  347. this.msgSuccess("转派任务成功!");
  348. this.updateAssignee.open = false;
  349. this.getDetail(); // 获得最新详情
  350. });
  351. });
  352. },
  353. /** 取消转派审批人 */
  354. cancelUpdateAssigneeForm() {
  355. this.updateAssignee.open = false;
  356. this.resetUpdateAssigneeForm();
  357. },
  358. /** 重置转派审批人 */
  359. resetUpdateAssigneeForm() {
  360. this.updateAssignee.form = {
  361. id: undefined,
  362. assigneeUserId: undefined,
  363. };
  364. this.resetForm("updateAssigneeForm");
  365. },
  366. /** 处理审批退回的操作 */
  367. handleDelegate(task) {
  368. this.msgError("暂不支持【委派】功能,可以使用【转派】替代!");
  369. },
  370. /** 处理审批退回的操作 */
  371. handleBack(task) {
  372. this.msgError("暂不支持【退回】功能!");
  373. }
  374. }
  375. };
  376. </script>
  377. <style lang="scss">
  378. .my-process-designer {
  379. height: calc(100vh - 200px);
  380. }
  381. .box-card {
  382. width: 100%;
  383. margin-bottom: 20px;
  384. }
  385. </style>