processTask.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. this.processInstanceLoading = true;
  76. this.runningTasks = [];
  77. this.auditForms = [];
  78. if (!this.listData.id) {
  79. this.processInstanceLoading = false;
  80. return;
  81. }
  82. try {
  83. const response = await getProcessInstance({
  84. id: this.listData.id,
  85. });
  86. if (!response) {
  87. uni.showToast({
  88. title: "查询不到流程信息",
  89. icon: "none",
  90. duration: 3000,
  91. });
  92. this.processInstanceLoading = false;
  93. return;
  94. }
  95. this.processInstance = response;
  96. this.uniNavBarTitle = `${response.name}`;
  97. } catch (err) {
  98. this.processInstanceLoading = false;
  99. uni.showModal({
  100. title: "getProcessInstance 失败",
  101. content: String((err && err.message) || err),
  102. showCancel: false,
  103. });
  104. return;
  105. }
  106. this.processInstanceLoading = false;
  107. try {
  108. const response = await getTaskListByProcessInstanceId({
  109. processInstanceId: this.listData.id,
  110. });
  111. if (!Array.isArray(response)) {
  112. uni.showModal({
  113. title: "任务列表格式异常",
  114. content: JSON.stringify({ raw: response }).slice(0, 1700),
  115. showCancel: false,
  116. });
  117. return;
  118. }
  119. this.tasks = [];
  120. response.forEach((task) => {
  121. if (task.result !== 4) {
  122. this.tasks.push(task);
  123. }
  124. });
  125. this.tasks.sort((a, b) => {
  126. if (a.endTime && b.endTime) {
  127. return b.endTime - a.endTime;
  128. } else if (a.endTime) {
  129. return 1;
  130. } else if (b.endTime) {
  131. return -1;
  132. } else {
  133. return b.createTime - a.createTime;
  134. }
  135. });
  136. const userInfo = uni.getStorageSync("userInfo") || {};
  137. const userId = userInfo.userId;
  138. this.tasks.forEach((task) => {
  139. if (task.result !== 1 && task.result !== 6) {
  140. return;
  141. }
  142. if (userId == null) {
  143. return;
  144. }
  145. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  146. return;
  147. }
  148. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  149. return;
  150. }
  151. this.runningTasks.push({
  152. ...task,
  153. });
  154. this.auditForms.push({
  155. reason: "",
  156. });
  157. });
  158. } catch (err) {
  159. uni.showModal({
  160. title: "getTaskList 或解析失败",
  161. content: String((err && err.message) || err),
  162. showCancel: false,
  163. });
  164. }
  165. },
  166. /** 处理审批通过和不通过的操作 */
  167. handleAudit(data) {
  168. let text = data.status === 1 ? "通过" : "不通过";
  169. this.$refs.uToast.show({
  170. type: "success",
  171. message: `审批${data.title || text}成功!`,
  172. iconUrl: "https://cdn.uviewui.com/uview/demo/toast/success.png",
  173. });
  174. // 获得最新详情
  175. setTimeout(() => {
  176. uni.navigateBack();
  177. }, 1000);
  178. // const index = this.runningTasks.indexOf(task);
  179. // this.$refs['form' + index][0].validate((valid) => {
  180. // if (!valid) {
  181. // return;
  182. // }
  183. // const data = {
  184. // id: task.id,
  185. // reason: this.auditForms[index].reason
  186. // };
  187. // if (pass) {
  188. // approveTask(data).then((response) => {
  189. // this.$message.success('审批通过成功!');
  190. // this.handleClose(); // 获得最新详情
  191. // });
  192. // } else {
  193. // rejectTask(data).then((response) => {
  194. // this.$message.success('审批不通过成功!');
  195. // this.handleClose(); // 获得最新详情
  196. // });
  197. // }
  198. // });
  199. },
  200. getTableValue(fn) {
  201. fn(this.$refs.bziRef.getTableValue());
  202. },
  203. },
  204. };
  205. </script>
  206. <style></style>