processTask.vue 5.0 KB

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