processTask.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="havedone-container">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="uniNavBarTitle"
  4. background-color="#157A2C" color="#fff"
  5. @clickLeft="back"></uni-nav-bar>
  6. <view v-if="processInstance.processDefinition">
  7. <async-biz-form-component :taskId="listData.taskId" :businessId="listData.businessId" :id="listData.id"
  8. :taskDefinitionKey="listData.taskDefinitionKey" @activeCompChange="activeCompChange"
  9. @handleClose="handleClose" ref="bziRef"></async-biz-form-component>
  10. </view>
  11. <view v-for="(item, index) in runningTasks" :key="index">
  12. <div v-if="processInstance.processDefinition">
  13. <async-sub-form-component :taskId="listData.taskId" :businessId="listData.businessId" :id="listData.id"
  14. :taskDefinitionKey="listData.taskDefinitionKey" @handleAudit="handleAudit"
  15. @getTableValue="getTableValue" @handleUpdateAssignee="handleUpdateAssignee(item)"
  16. @handleBackList="handleBackList(item)" @submit="submit" ref="subForm">
  17. </async-sub-form-component>
  18. </div>
  19. </view>
  20. <u-toast ref="uToast"></u-toast>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. getProcessInstance,
  26. getTaskListByProcessInstanceId
  27. } from '@/api/wt/index.js'
  28. import Vue from 'vue'
  29. export default {
  30. name: 'processTask',
  31. data() {
  32. return {
  33. uniNavBarTitle: '',
  34. processInstanceLoading: false,
  35. listData: {},
  36. processInstance: {},
  37. runningTasks: [],
  38. auditForms: [],
  39. }
  40. },
  41. onLoad(option) {
  42. console.log(option)
  43. this.listData = option
  44. this.getDetail()
  45. },
  46. methods: {
  47. /** 获得流程实例 */
  48. getDetail() {
  49. // 获得流程实例相关
  50. this.processInstanceLoading = true;
  51. getProcessInstance({
  52. id: this.listData.id
  53. }).then((response) => {
  54. if (!response) {
  55. this.$message.error('查询不到流程信息!');
  56. return;
  57. }
  58. // 设置流程信息
  59. this.processInstance = response;
  60. this.uniNavBarTitle =
  61. `${ this.processInstance.name } 【${ this.processInstance.startUser?.nickname}】`
  62. //将业务表单,注册为动态组件
  63. Vue.component('async-biz-form-component', (resolve) => {
  64. require(['pages/home' + this.listData.miniHandleRouter], resolve);
  65. });
  66. Vue.component('async-sub-form-component', (resolve) => {
  67. require(['pages/home' + this.listData.miniViewRouter], resolve);
  68. console.log('pages/home' + this.listData.miniHandleRouter,56565656)
  69. });
  70. console.log(getCurrentPages())
  71. // 取消加载中
  72. this.processInstanceLoading = false;
  73. });
  74. this.runningTasks = [];
  75. this.auditForms = [];
  76. getTaskListByProcessInstanceId({
  77. processInstanceId: this.listData.id
  78. }).then((response) => {
  79. console.log(response, 'response');
  80. // 审批记录
  81. this.tasks = [];
  82. // 移除已取消的审批
  83. response.forEach((task) => {
  84. if (task.result !== 4) {
  85. this.tasks.push(task);
  86. }
  87. });
  88. // 排序,将未完成的排在前面,已完成的排在后面;
  89. this.tasks.sort((a, b) => {
  90. // 有已完成的情况,按照完成时间倒序
  91. if (a.endTime && b.endTime) {
  92. return b.endTime - a.endTime;
  93. } else if (a.endTime) {
  94. return 1;
  95. } else if (b.endTime) {
  96. return -1;
  97. // 都是未完成,按照创建时间倒序
  98. } else {
  99. return b.createTime - a.createTime;
  100. }
  101. });
  102. // 需要审核的记录
  103. let userInfo = wx.getStorageSync("userInfo");
  104. this.tasks.forEach((task) => {
  105. if (task.result !== 1 && task.result !== 6) {
  106. // 只有待处理才需要
  107. return;
  108. }
  109. if (!task.assigneeUser || task.assigneeUser.id !== userInfo.userId) {
  110. // 自己不是处理人
  111. return;
  112. }
  113. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  114. // 不是当前流程的
  115. return;
  116. }
  117. this.runningTasks.push({
  118. ...task
  119. });
  120. console.log(this.runningTasks, ' this.runningTasks');
  121. this.auditForms.push({
  122. reason: ''
  123. });
  124. });
  125. });
  126. },
  127. /** 处理审批通过和不通过的操作 */
  128. handleAudit(data) {
  129. let text = data.status === 1 ? '通过' : '不通过';
  130. this.$refs.uToast.show({
  131. type: 'success',
  132. message: `审批${data.title || text}成功!`,
  133. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  134. })
  135. // 获得最新详情
  136. setTimeout(() => {
  137. uni.navigateBack()
  138. }, 1000)
  139. // const index = this.runningTasks.indexOf(task);
  140. // this.$refs['form' + index][0].validate((valid) => {
  141. // if (!valid) {
  142. // return;
  143. // }
  144. // const data = {
  145. // id: task.id,
  146. // reason: this.auditForms[index].reason
  147. // };
  148. // if (pass) {
  149. // approveTask(data).then((response) => {
  150. // this.$message.success('审批通过成功!');
  151. // this.handleClose(); // 获得最新详情
  152. // });
  153. // } else {
  154. // rejectTask(data).then((response) => {
  155. // this.$message.success('审批不通过成功!');
  156. // this.handleClose(); // 获得最新详情
  157. // });
  158. // }
  159. // });
  160. },
  161. getTableValue(fn) {
  162. fn(this.$refs.bziRef.getTableValue());
  163. }
  164. }
  165. }
  166. </script>
  167. <style>
  168. </style>