processTask.vue 5.3 KB

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