processTask.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="havedone-container">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="uniNavBarTitle"
  4. background-color="#157A2C" color="#fff"
  5. @clickLeft="back"></uni-nav-bar>
  6. <!-- <iframe src="http://aiot.zoomwin.com.cn:51001/test/a.html" style="width: 200px;height: 600px" frameborder="0"></iframe> -->
  7. <view v-if="processInstance.processDefinition && taskFormComp">
  8. <component :is="taskFormComp" id='async-biz-form-component' :taskId="listData.taskId" :businessId="listData.businessId" :id="listData.id"
  9. :taskDefinitionKey="listData.taskDefinitionKey"
  10. ref="bziRef"></component>
  11. </view>
  12. <!-- <view v-for="(item, index) in runningTasks" :key="index">
  13. <div v-if="processInstance.processDefinition">
  14. <taskSubmit id='async-sub-form-component' :taskId="listData.taskId" :businessId="listData.businessId" :id="listData.id"
  15. :taskDefinitionKey="listData.taskDefinitionKey" @handleAudit="handleAudit"
  16. @getTableValue="getTableValue" @handleUpdateAssignee="handleUpdateAssignee(item)"
  17. @handleBackList="handleBackList(item)" ref="subForm">
  18. </taskSubmit>
  19. </div>
  20. </view> -->
  21. <u-toast ref="uToast"></u-toast>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. getProcessInstance,
  27. getTaskListByProcessInstanceId
  28. } from '@/api/wt/index.js'
  29. import Vue from 'vue'
  30. // import taskForm from './taskForm.vue'
  31. // import taskSubmit from './taskSubmit.vue'
  32. export default {
  33. name: 'processTask',
  34. // components:{ taskForm,taskSubmit },
  35. data() {
  36. return {
  37. uniNavBarTitle: '',
  38. processInstanceLoading: false,
  39. listData: {},
  40. processInstance: {},
  41. runningTasks: [],
  42. auditForms: [],
  43. activeComp: null,
  44. taskFormComp: null, // 动态加载的 taskForm 组件
  45. }
  46. },
  47. onLoad(option) {
  48. this.listData = option
  49. this.getDetail()
  50. this.activeComp = 'tab1'
  51. // 动态加载 miniHandleRouter 对应的 taskForm 组件
  52. if (option.miniHandleRouter) {
  53. this.loadTaskFormComponent(option.miniHandleRouter)
  54. }
  55. },
  56. methods: {
  57. /** 动态加载 miniHandleRouter 对应的 taskForm 组件 */
  58. loadTaskFormComponent(router) {
  59. try {
  60. // router 格式: /wt/components/purchaseOrder/taskForm
  61. // require.context 在编译期解析所有 taskForm.vue,运行时按 key 取值
  62. const context = require.context('@/pages/home', true, /taskForm\.vue$/)
  63. const key = '.' + router + '.vue' // -> ./wt/components/purchaseOrder/taskForm.vue
  64. const module = context(key)
  65. if (module) {
  66. this.taskFormComp = module.default || module
  67. }
  68. } catch (e) {
  69. console.error('动态加载 taskForm 组件失败:', router, e)
  70. uni.showModal({
  71. title: '组件加载失败',
  72. content: `无法加载: ${router}`,
  73. showCancel: false
  74. })
  75. }
  76. },
  77. /** 获得流程实例 */
  78. async getDetail() {
  79. // 获得流程实例相关
  80. this.processInstanceLoading = true;
  81. getProcessInstance({
  82. id: this.listData.id
  83. }).then(async (response) => {
  84. if (!response) {
  85. this.$message.error('查询不到流程信息!');
  86. return;
  87. }
  88. // 设置流程信息
  89. this.processInstance = response;
  90. this.uniNavBarTitle =`${ response.name } 【${ response.startUser?.nickname}】`
  91. // //将业务表单,注册为动态组件
  92. // Vue.component('async-biz-form-component', (resolve) => {
  93. // require(['pages/home' + this.listData.miniHandleRouter], resolve);
  94. // });
  95. // Vue.component('async-sub-form-component', (resolve) => {
  96. // require(['pages/home' + this.listData.miniViewRouter], resolve);
  97. // });
  98. this.processInstanceLoading = false;
  99. });
  100. this.runningTasks = [];
  101. this.auditForms = [];
  102. getTaskListByProcessInstanceId({
  103. processInstanceId: this.listData.id
  104. }).then((response) => {
  105. console.log(response, 'response');
  106. // 审批记录
  107. this.tasks = [];
  108. // 移除已取消的审批
  109. response.forEach((task) => {
  110. if (task.result !== 4) {
  111. this.tasks.push(task);
  112. }
  113. });
  114. // 排序,将未完成的排在前面,已完成的排在后面;
  115. this.tasks.sort((a, b) => {
  116. // 有已完成的情况,按照完成时间倒序
  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. // 都是未完成,按照创建时间倒序
  124. } else {
  125. return b.createTime - a.createTime;
  126. }
  127. });
  128. // 需要审核的记录
  129. let userInfo = wx.getStorageSync("userInfo");
  130. this.tasks.forEach((task) => {
  131. if (task.result !== 1 && task.result !== 6) {
  132. // 只有待处理才需要
  133. return;
  134. }
  135. if (!task.assigneeUser || task.assigneeUser.id !== userInfo.userId) {
  136. // 自己不是处理人
  137. return;
  138. }
  139. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  140. // 不是当前流程的
  141. return;
  142. }
  143. this.runningTasks.push({
  144. ...task
  145. });
  146. console.log(this.runningTasks, ' this.runningTasks');
  147. this.auditForms.push({
  148. reason: ''
  149. });
  150. });
  151. });
  152. },
  153. /** 处理审批通过和不通过的操作 */
  154. handleAudit(data) {
  155. let text = data.status === 1 ? '通过' : '不通过';
  156. this.$refs.uToast.show({
  157. type: 'success',
  158. message: `审批${data.title || text}成功!`,
  159. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  160. })
  161. // 获得最新详情
  162. setTimeout(() => {
  163. uni.navigateBack()
  164. }, 1000)
  165. // const index = this.runningTasks.indexOf(task);
  166. // this.$refs['form' + index][0].validate((valid) => {
  167. // if (!valid) {
  168. // return;
  169. // }
  170. // const data = {
  171. // id: task.id,
  172. // reason: this.auditForms[index].reason
  173. // };
  174. // if (pass) {
  175. // approveTask(data).then((response) => {
  176. // this.$message.success('审批通过成功!');
  177. // this.handleClose(); // 获得最新详情
  178. // });
  179. // } else {
  180. // rejectTask(data).then((response) => {
  181. // this.$message.success('审批不通过成功!');
  182. // this.handleClose(); // 获得最新详情
  183. // });
  184. // }
  185. // });
  186. },
  187. getTableValue(fn) {
  188. fn(this.$refs.bziRef.getTableValue());
  189. }
  190. }
  191. }
  192. </script>
  193. <style>
  194. </style>