processTask.vue 5.1 KB

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