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