processTask.vue 5.3 KB

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