processTask.vue 5.4 KB

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