detail.vue 15 KB

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