processTask.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. mounted() {
  57. this.$nextTick(() => {
  58. this.loadComponent()
  59. })
  60. },
  61. methods: {
  62. async loadComponent() {
  63. // pages/home/wt/components/purchaseOrder/processTask
  64. // 动态引入组件
  65. console.log('this.listData.miniHandleRouter', this.listData.miniHandleRouter)
  66. const Component = await import('@/pages/home' + this.listData.miniHandleRouter + '.vue');
  67. // 局部注册组件
  68. this.taskFormComp = Component.default || Component;
  69. },
  70. /** 动态加载 miniHandleRouter 对应的 taskForm 组件 */
  71. loadTaskFormComponent(router) {
  72. try {
  73. // router 格式: /wt/components/purchaseOrder/taskForm
  74. // require.context 在编译期解析所有 taskForm.vue,运行时按 key 取值
  75. const context = require.context('@/pages/home', true, /taskForm\.vue$/)
  76. const key = '.' + router + '.vue' // -> ./wt/components/purchaseOrder/taskForm.vue
  77. const module = context(key)
  78. if (module) {
  79. this.taskFormComp = module.default || module
  80. }
  81. } catch (e) {
  82. console.error('动态加载 taskForm 组件失败:', router, e)
  83. uni.showModal({
  84. title: '组件加载失败',
  85. content: `无法加载: ${router}`,
  86. showCancel: false
  87. })
  88. }
  89. },
  90. /** 获得流程实例 */
  91. async getDetail() {
  92. // 获得流程实例相关
  93. this.processInstanceLoading = true;
  94. getProcessInstance({
  95. id: this.listData.id
  96. }).then(async (response) => {
  97. if (!response) {
  98. this.$message.error('查询不到流程信息!');
  99. return;
  100. }
  101. // 设置流程信息
  102. this.processInstance = response;
  103. this.uniNavBarTitle =`${ response.name } 【${ response.startUser?.nickname}】`
  104. // //将业务表单,注册为动态组件
  105. // Vue.component('async-biz-form-component', (resolve) => {
  106. // require(['pages/home' + this.listData.miniHandleRouter], resolve);
  107. // });
  108. // Vue.component('async-sub-form-component', (resolve) => {
  109. // require(['pages/home' + this.listData.miniViewRouter], resolve);
  110. // });
  111. this.processInstanceLoading = false;
  112. });
  113. this.runningTasks = [];
  114. this.auditForms = [];
  115. getTaskListByProcessInstanceId({
  116. processInstanceId: this.listData.id
  117. }).then((response) => {
  118. console.log(response, 'response');
  119. // 审批记录
  120. this.tasks = [];
  121. // 移除已取消的审批
  122. response.forEach((task) => {
  123. if (task.result !== 4) {
  124. this.tasks.push(task);
  125. }
  126. });
  127. // 排序,将未完成的排在前面,已完成的排在后面;
  128. this.tasks.sort((a, b) => {
  129. // 有已完成的情况,按照完成时间倒序
  130. if (a.endTime && b.endTime) {
  131. return b.endTime - a.endTime;
  132. } else if (a.endTime) {
  133. return 1;
  134. } else if (b.endTime) {
  135. return -1;
  136. // 都是未完成,按照创建时间倒序
  137. } else {
  138. return b.createTime - a.createTime;
  139. }
  140. });
  141. // 需要审核的记录
  142. let userInfo = wx.getStorageSync("userInfo");
  143. this.tasks.forEach((task) => {
  144. if (task.result !== 1 && task.result !== 6) {
  145. // 只有待处理才需要
  146. return;
  147. }
  148. if (!task.assigneeUser || task.assigneeUser.id !== userInfo.userId) {
  149. // 自己不是处理人
  150. return;
  151. }
  152. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  153. // 不是当前流程的
  154. return;
  155. }
  156. this.runningTasks.push({
  157. ...task
  158. });
  159. console.log(this.runningTasks, ' this.runningTasks');
  160. this.auditForms.push({
  161. reason: ''
  162. });
  163. });
  164. });
  165. },
  166. /** 处理审批通过和不通过的操作 */
  167. handleAudit(data) {
  168. let text = data.status === 1 ? '通过' : '不通过';
  169. this.$refs.uToast.show({
  170. type: 'success',
  171. message: `审批${data.title || text}成功!`,
  172. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  173. })
  174. // 获得最新详情
  175. setTimeout(() => {
  176. uni.navigateBack()
  177. }, 1000)
  178. // const index = this.runningTasks.indexOf(task);
  179. // this.$refs['form' + index][0].validate((valid) => {
  180. // if (!valid) {
  181. // return;
  182. // }
  183. // const data = {
  184. // id: task.id,
  185. // reason: this.auditForms[index].reason
  186. // };
  187. // if (pass) {
  188. // approveTask(data).then((response) => {
  189. // this.$message.success('审批通过成功!');
  190. // this.handleClose(); // 获得最新详情
  191. // });
  192. // } else {
  193. // rejectTask(data).then((response) => {
  194. // this.$message.success('审批不通过成功!');
  195. // this.handleClose(); // 获得最新详情
  196. // });
  197. // }
  198. // });
  199. },
  200. getTableValue(fn) {
  201. fn(this.$refs.bziRef.getTableValue());
  202. }
  203. }
  204. }
  205. </script>
  206. <style>
  207. </style>