processTask.vue 5.2 KB

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