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