processTask.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. <view v-if="processInstance.processDefinition">
  13. <taskForm
  14. id="async-biz-form-component"
  15. :taskId="listData.taskId"
  16. :businessId="listData.businessId"
  17. :id="listData.id"
  18. :taskDefinitionKey="listData.taskDefinitionKey"
  19. ref="bziRef"
  20. ></taskForm>
  21. </view>
  22. <view v-for="(item, index) in runningTasks" :key="index">
  23. <div v-if="processInstance.processDefinition">
  24. <taskSubmit
  25. id="async-sub-form-component"
  26. :taskId="listData.taskId"
  27. :businessId="listData.businessId"
  28. :id="listData.id"
  29. :taskDefinitionKey="listData.taskDefinitionKey"
  30. @handleAudit="handleAudit"
  31. @getTableValue="getTableValue"
  32. ref="subForm"
  33. >
  34. </taskSubmit>
  35. </div>
  36. </view>
  37. <u-toast ref="uToast"></u-toast>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. getProcessInstance,
  43. getTaskListByProcessInstanceId,
  44. } from "@/api/wt/index.js";
  45. import taskForm from "./taskForm.vue";
  46. import taskSubmit from "./taskSubmit.vue";
  47. export default {
  48. name: "processTask",
  49. components: { taskForm, taskSubmit },
  50. data() {
  51. return {
  52. uniNavBarTitle: "",
  53. processInstanceLoading: false,
  54. listData: {},
  55. processInstance: {},
  56. runningTasks: [],
  57. auditForms: [],
  58. };
  59. },
  60. onLoad(option) {
  61. this.listData = option || {};
  62. this.getDetail();
  63. },
  64. methods: {
  65. async getDetail() {
  66. this.processInstanceLoading = true;
  67. this.runningTasks = [];
  68. this.auditForms = [];
  69. if (!this.listData.id) {
  70. this.processInstanceLoading = false;
  71. return;
  72. }
  73. try {
  74. const response = await getProcessInstance({
  75. id: this.listData.id,
  76. });
  77. if (!response) {
  78. uni.showToast({
  79. title: "查询不到流程信息",
  80. icon: "none",
  81. duration: 3000,
  82. });
  83. this.processInstanceLoading = false;
  84. return;
  85. }
  86. this.processInstance = response;
  87. this.uniNavBarTitle = `${response.name}`;
  88. } catch (err) {
  89. this.processInstanceLoading = false;
  90. uni.showModal({
  91. title: "getProcessInstance 失败",
  92. content: String((err && err.message) || err),
  93. showCancel: false,
  94. });
  95. return;
  96. }
  97. this.processInstanceLoading = false;
  98. try {
  99. const response = await getTaskListByProcessInstanceId({
  100. processInstanceId: this.listData.id,
  101. });
  102. if (!Array.isArray(response)) {
  103. uni.showModal({
  104. title: "任务列表格式异常",
  105. content: JSON.stringify({ raw: response }).slice(0, 1700),
  106. showCancel: false,
  107. });
  108. return;
  109. }
  110. this.tasks = [];
  111. response.forEach((task) => {
  112. if (task.result !== 4) {
  113. this.tasks.push(task);
  114. }
  115. });
  116. this.tasks.sort((a, b) => {
  117. if (a.endTime && b.endTime) {
  118. return b.endTime - a.endTime;
  119. } else if (a.endTime) {
  120. return 1;
  121. } else if (b.endTime) {
  122. return -1;
  123. } else {
  124. return b.createTime - a.createTime;
  125. }
  126. });
  127. const userInfo = uni.getStorageSync("userInfo") || {};
  128. const userId = userInfo.userId;
  129. this.tasks.forEach((task) => {
  130. if (task.result !== 1 && task.result !== 6) {
  131. return;
  132. }
  133. if (userId == null) {
  134. return;
  135. }
  136. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  137. return;
  138. }
  139. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  140. return;
  141. }
  142. this.runningTasks.push({
  143. ...task,
  144. });
  145. this.auditForms.push({
  146. reason: "",
  147. });
  148. });
  149. } catch (err) {
  150. uni.showModal({
  151. title: "getTaskList 或解析失败",
  152. content: String((err && err.message) || err),
  153. showCancel: false,
  154. });
  155. }
  156. },
  157. handleAudit(data) {
  158. let text = data.status === 1 ? "通过" : "不通过";
  159. this.$refs.uToast.show({
  160. type: "success",
  161. message: `审批${data.title || text}成功!`,
  162. iconUrl: "https://cdn.uviewui.com/uview/demo/toast/success.png",
  163. });
  164. setTimeout(() => {
  165. uni.navigateBack();
  166. }, 1000);
  167. },
  168. getTableValue(fn) {
  169. fn(this.$refs.bziRef.getTableValue());
  170. },
  171. },
  172. };
  173. </script>
  174. <style></style>