processTask.vue 5.5 KB

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