processTask.vue 5.4 KB

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