index.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. <template>
  2. <ele-modal
  3. :before-close="handleClose"
  4. :visible.sync="dialogVisible"
  5. :close-on-click-modal="false"
  6. :append-to-body="true"
  7. width="80%"
  8. title="处理"
  9. :maxable="true"
  10. >
  11. <div class="app-container">
  12. <!-- 申请信息 :tasks="tasks" -->
  13. <el-card class="box-card" v-loading="processInstanceLoading">
  14. <div slot="header" class="clearfix">
  15. <span class="el-icon-document"
  16. >申请信息【{{ processInstance.name }}】 申请人:【{{
  17. processInstance.startUser?.nickname
  18. }}】</span
  19. >
  20. </div>
  21. <div v-if="processInstance.processDefinition">
  22. <async-biz-form-component
  23. :taskId="listData?.taskId"
  24. :businessId="listData?.businessId"
  25. :businessCode="listData?.businessCode"
  26. :id="listData?.id"
  27. :businessType="listData?.businessType"
  28. :processDefinitionId="processInstance.processDefinition.id"
  29. :taskDefinitionKey="listData?.taskDefinitionKey"
  30. :fromUser="processInstance.startUser?.nickname"
  31. :deptName="processInstance.startUser?.deptName"
  32. :deptId="processInstance.startUser?.deptId"
  33. :createTime="processInstance.createTime"
  34. @activeCompChange="activeCompChange"
  35. @handleClose="handleClose"
  36. ref="bziRef"
  37. ></async-biz-form-component>
  38. </div>
  39. </el-card>
  40. <div style="display: flex">
  41. <!-- 审批信息 -->
  42. <el-card
  43. style="min-width: 500px"
  44. class="box-card"
  45. v-loading="processInstanceLoading"
  46. v-for="(item, index) in runningTasks"
  47. :key="item.id || index"
  48. >
  49. <div slot="header" class="clearfix">
  50. <span class="el-icon-picture-outline">审批任务</span>
  51. </div>
  52. <div v-if="processInstance.processDefinition">
  53. <async-sub-form-component
  54. :taskId="item.id || listData?.taskId"
  55. :businessId="listData?.businessId"
  56. :businessCode="listData?.businessCode"
  57. :id="listData?.id"
  58. :taskDefinitionKey="listData?.taskDefinitionKey"
  59. :fromUser="processInstance.startUser?.nickname"
  60. :businessType="listData?.businessType"
  61. @handleAudit="handleAudit"
  62. @getTableValue="getTableValue"
  63. @handleUpdateAssignee="handleUpdateAssignee(item)"
  64. @handleBackList="handleBackList(item)"
  65. @submit="submit"
  66. @handleClose="handleClose"
  67. ref="subForm"
  68. ></async-sub-form-component>
  69. </div>
  70. <!-- <div> </div> -->
  71. <!-- <el-col :span="16" :offset="6">
  72. <el-form
  73. :ref="'form' + index"
  74. :model="auditForms[index]"
  75. :rules="auditRule"
  76. label-width="100px"
  77. >
  78. <el-form-item
  79. label="审批建议"
  80. prop="reason"
  81. style="margin-bottom: 20px"
  82. >
  83. <el-input
  84. type="textarea"
  85. v-model="auditForms[index].reason"
  86. placeholder="请输入审批建议"
  87. />
  88. </el-form-item>
  89. </el-form>
  90. <div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px">
  91. <el-button
  92. icon="el-icon-edit-outline"
  93. type="success"
  94. size="mini"
  95. @click="handleAudit(item, true)"
  96. >通过
  97. </el-button>
  98. <el-button
  99. icon="el-icon-circle-close"
  100. type="danger"
  101. size="mini"
  102. @click="handleAudit(item, false)"
  103. >不通过
  104. </el-button>
  105. <el-button
  106. icon="el-icon-edit-outline"
  107. type="primary"
  108. size="mini"
  109. @click="handleUpdateAssignee(item)"
  110. >转办
  111. </el-button>
  112. <el-button
  113. icon="el-icon-edit-outline"
  114. type="primary"
  115. size="mini"
  116. @click="handleDelegate(item)"
  117. >委派
  118. </el-button>
  119. <el-button
  120. icon="el-icon-refresh-left"
  121. type="warning"
  122. size="mini"
  123. @click="handleBackList(item)"
  124. >退回
  125. </el-button>
  126. </div>
  127. </el-col> -->
  128. </el-card>
  129. <!-- 审批记录 -->
  130. <el-card
  131. class="box-card"
  132. style="flex: 1; min-width: 540px; margin-top: 0; margin-left: 10px"
  133. v-loading="processInstanceLoading"
  134. >
  135. <div slot="header" class="clearfix">
  136. <span class="el-icon-picture-outline">审批记录</span>
  137. </div>
  138. <div style="overflow-y: auto; height: 120px">
  139. <el-timeline>
  140. <el-timeline-item
  141. v-for="(item, index) in tasks"
  142. :key="index"
  143. :icon="getTimelineItemIcon(item)"
  144. :type="getTimelineItemType(item)"
  145. >
  146. <p style="font-weight: 500; margin-top: 5px"
  147. >任务:{{ item.name }}</p
  148. >
  149. <label
  150. v-if="item.assigneeUser"
  151. style="font-weight: normal; margin-right: 30px"
  152. >
  153. {{ index == 0 ? ' 审批人' : '发起人' }}:{{
  154. item.assigneeUser.nickname
  155. }}
  156. <el-tag type="info" size="mini">{{
  157. item.assigneeUser.deptName
  158. }}</el-tag>
  159. </label>
  160. <label
  161. v-if="item.endTime"
  162. style="margin-left: 10px; font-weight: normal"
  163. >审批时间:</label
  164. >
  165. <label
  166. v-if="item.endTime"
  167. style="color: #8a909c; font-weight: normal"
  168. >
  169. {{ item.endTime }}</label
  170. >
  171. <div>
  172. <label v-if="item.reason" style="font-weight: normal"
  173. >审批意见:</label
  174. >
  175. <label
  176. v-if="item.reason"
  177. style="color: #8a909c; font-weight: normal"
  178. >
  179. {{ item.reason }}</label
  180. >
  181. </div>
  182. </el-timeline-item>
  183. </el-timeline>
  184. </div>
  185. </el-card>
  186. </div>
  187. <!-- 对话框(转办审批人) -->
  188. <el-dialog
  189. title="转办审批人"
  190. :visible.sync="updateAssignee.open"
  191. width="500px"
  192. append-to-body
  193. >
  194. <el-form
  195. ref="updateAssigneeForm"
  196. :model="updateAssignee.form"
  197. :rules="updateAssignee.rules"
  198. label-width="110px"
  199. >
  200. <el-form-item label="新审批人" prop="assigneeUserId">
  201. <el-select
  202. v-model="updateAssignee.form.assigneeUserId"
  203. clearable
  204. style="width: 100%"
  205. :filterable="true"
  206. >
  207. <el-option
  208. v-for="item in userOptions"
  209. :key="item.id"
  210. :label="item.name"
  211. :value="item.id"
  212. />
  213. </el-select>
  214. </el-form-item>
  215. </el-form>
  216. <div slot="footer" class="dialog-footer">
  217. <el-button type="primary" @click="submitUpdateAssigneeForm"
  218. >确 定
  219. </el-button>
  220. <el-button @click="cancelUpdateAssigneeForm">取 消</el-button>
  221. </div>
  222. </el-dialog>
  223. <!-- 对话框(委派审批人) -->
  224. <el-dialog
  225. title="委派审批人"
  226. :visible.sync="updateDelegate.open"
  227. width="500px"
  228. append-to-body
  229. >
  230. <el-form
  231. ref="updateDelegateForm"
  232. :model="updateDelegate.form"
  233. :rules="updateDelegate.rules"
  234. label-width="110px"
  235. >
  236. <el-form-item label="新审批人" prop="assigneeUserId">
  237. <el-select
  238. v-model="updateDelegate.form.delegateUserId"
  239. clearable
  240. style="width: 100%"
  241. :filterable="true"
  242. >
  243. <el-option
  244. v-for="item in userOptions"
  245. :key="item.id"
  246. :label="item.name"
  247. :value="item.id"
  248. />
  249. </el-select>
  250. </el-form-item>
  251. <el-form-item label="委派理由" prop="reason">
  252. <el-input
  253. v-model="updateDelegate.form.reason"
  254. clearable
  255. placeholder="请输入委派理由"
  256. />
  257. </el-form-item>
  258. </el-form>
  259. <div slot="footer" class="dialog-footer">
  260. <el-button type="primary" @click="submitUpdateDelegateForm"
  261. >确 定
  262. </el-button>
  263. <el-button @click="cancelUpdateDelegateForm">取 消</el-button>
  264. </div>
  265. </el-dialog>
  266. <!--退回流程-->
  267. <el-dialog
  268. title="退回流程"
  269. :visible.sync="returnOpen"
  270. width="40%"
  271. append-to-body
  272. >
  273. <el-form
  274. ref="formRef"
  275. v-loading="formLoading"
  276. :model="formData"
  277. :rules="formRules"
  278. label-width="110px"
  279. >
  280. <el-form-item label="退回节点" prop="targetDefinitionKey">
  281. <el-select
  282. v-model="formData.targetDefinitionKey"
  283. clearable
  284. style="width: 100%"
  285. >
  286. <el-option
  287. v-for="item in returnList"
  288. :key="item.definitionKey"
  289. :label="item.name"
  290. :value="item.definitionKey"
  291. />
  292. </el-select>
  293. </el-form-item>
  294. <el-form-item label="回退理由" prop="reason">
  295. <el-input
  296. v-model="formData.reason"
  297. clearable
  298. placeholder="请输入回退理由"
  299. />
  300. </el-form-item>
  301. </el-form>
  302. <span slot="footer" class="dialog-footer">
  303. <el-button @click="returnOpen = false">取 消</el-button>
  304. <el-button
  305. :disabled="formLoading"
  306. type="primary"
  307. @click="submitReturn"
  308. >确 定</el-button
  309. >
  310. </span>
  311. </el-dialog>
  312. </div>
  313. </ele-modal>
  314. </template>
  315. <script>
  316. // import { getProcessDefinitionBpmnXML } from '@/api/bpm/definition';
  317. import store from '@/store';
  318. // import {decodeFields} from "@/utils/formGenerator";
  319. // import Parser from '@/components/parser/Parser'
  320. import { getProcessInstance } from '@/api/bpm/processInstance';
  321. import { listAllUserBind } from '@/api/system/organization';
  322. import Vue from 'vue';
  323. import purchaseReturnDetail from '@/views/bpm/handleTask/components/purchaseOrder/returnGoods/detailDialog.vue';
  324. import purchaseReturnSubmit from '@/views/bpm/handleTask/components/purchaseOrder/returnGoods/submit.vue';
  325. import {
  326. delegateTask,
  327. getReturnList,
  328. getTaskListByProcessInstanceId,
  329. returnTask,
  330. updateTaskAssignee
  331. } from '@/api/bpm/task';
  332. import { getProcessDefinitionBpmnXML } from '@/api/bpm/definition';
  333. import { getActivityList } from '@/api/bpm/activity';
  334. // import { getDate } from '@/utils/dateUtils';
  335. // 已有审批组件的流程未配路由时,使用的本项目约定路径(按流程标识匹配)
  336. const FORM_FALLBACK_MAP = {
  337. contact_approve: {
  338. pcView: '/bpm/handleTask/components/contact/contactDetailDialog.vue',
  339. pcHandle: '/bpm/handleTask/components/contact/submit.vue'
  340. },
  341. // 生产性物资采购收货多人审批(只展示收货单详情,不含入库单)
  342. purchase_receive_approve3: {
  343. pcView:
  344. '/bpm/handleTask/components/purchaseReceiveMultiApproval/detailDialog.vue',
  345. pcHandle:
  346. '/bpm/handleTask/components/purchaseReceiveMultiApproval/submit.vue'
  347. },
  348. hr_recruit_hiring_approval: {
  349. pcView:
  350. '/bpm/handleTask/components/hiringApproval/hiringApprovalDetail.vue',
  351. pcHandle: '/bpm/handleTask/components/hiringApproval/submit.vue'
  352. },
  353. hr_contract_approval: {
  354. pcView:
  355. '/bpm/handleTask/components/hrContractManagement/hrContractDetail.vue',
  356. pcHandle: '/bpm/handleTask/components/hrContractManagement/submit.vue'
  357. },
  358. hr_contract_termination_approval: {
  359. pcView:
  360. '/bpm/handleTask/components/hrRemoveContractManagement/hrRemoveContractDetail.vue',
  361. pcHandle:
  362. '/bpm/handleTask/components/hrRemoveContractManagement/submit.vue'
  363. },
  364. hr_contract_change_approval: {
  365. pcView:
  366. '/bpm/handleTask/components/hrChangeContractManagement/hrChangeContractDetail.vue',
  367. pcHandle:
  368. '/bpm/handleTask/components/hrChangeContractManagement/submit.vue'
  369. },
  370. // 考勤申请:补卡 / 请假 / 外出 / 加班 / 出差
  371. hr_attendance_card_repair_apply: {
  372. pcView:
  373. '/bpm/handleTask/components/hrCardRepairManagement/hrCardRepairDetail.vue',
  374. pcHandle: '/bpm/handleTask/components/hrCardRepairManagement/submit.vue'
  375. },
  376. hr_attendance_leave_apply: {
  377. pcView: '/bpm/handleTask/components/hrLeaveManagement/hrLeaveDetail.vue',
  378. pcHandle: '/bpm/handleTask/components/hrLeaveManagement/submit.vue'
  379. },
  380. hr_attendance_outing_apply: {
  381. pcView:
  382. '/bpm/handleTask/components/hrOutingManagement/hrOutingDetail.vue',
  383. pcHandle: '/bpm/handleTask/components/hrOutingManagement/submit.vue'
  384. },
  385. hr_attendance_overtime_apply: {
  386. pcView:
  387. '/bpm/handleTask/components/hrOvertimeManagement/hrOvertimeDetail.vue',
  388. pcHandle: '/bpm/handleTask/components/hrOvertimeManagement/submit.vue'
  389. },
  390. hr_attendance_trip_apply: {
  391. pcView: '/bpm/handleTask/components/hrTripManagement/hrTripDetail.vue',
  392. pcHandle: '/bpm/handleTask/components/hrTripManagement/submit.vue'
  393. },
  394. // 薪资核算批次审批:批次汇总 + 异常,不含个人薪资明细
  395. hr_payroll_batch_approval: {
  396. pcView: '/bpm/handleTask/components/payrollBatchApproval/detail.vue',
  397. pcHandle: '/bpm/handleTask/components/payrollBatchApproval/submit.vue'
  398. },
  399. // 工资条异议审批:只看申诉内容与来源,金额调整另走更正审批
  400. hr_payroll_payslip_appeal_approval: {
  401. pcView: '/bpm/handleTask/components/payrollAppealApproval/detail.vue',
  402. pcHandle: '/bpm/handleTask/components/payrollAppealApproval/submit.vue'
  403. }
  404. };
  405. // 流程实例的详情页,可用于审批
  406. export default {
  407. name: 'ProcessInstanceDetail',
  408. components: {},
  409. data() {
  410. return {
  411. fullscreen: false,
  412. // 遮罩层
  413. processInstanceLoading: true,
  414. dialogVisible: false,
  415. // 流程实例
  416. listData: {
  417. id: undefined, // 流程实例的编号
  418. pcHandleRouter: '',
  419. pcViewRouter: '',
  420. businessId: '', // 业务id
  421. businessCode: '', //业务编码
  422. taskDefinitionKey: '',
  423. businessType: '',
  424. taskId: '' //任务编码
  425. },
  426. processInstance: {},
  427. formLoading: false,
  428. // 流程表单详情
  429. detailForm: {
  430. fields: []
  431. },
  432. //回退列表数据
  433. returnList: [],
  434. formData: {
  435. id: '',
  436. targetDefinitionKey: undefined,
  437. reason: ''
  438. },
  439. formRules: {
  440. targetDefinitionKey: [
  441. { required: true, message: '必须选择回退节点', trigger: 'change' }
  442. ],
  443. reason: [
  444. { required: true, message: '回退理由不能为空', trigger: 'blur' }
  445. ]
  446. },
  447. returnOpen: false,
  448. activityList: [],
  449. tasks: [],
  450. // 审批表单
  451. runningTasks: [],
  452. auditForms: [],
  453. auditRule: {
  454. reason: [
  455. { required: true, message: '审批建议不能为空', trigger: 'blur' }
  456. ]
  457. },
  458. // 转派审批人
  459. userOptions: [],
  460. updateAssignee: {
  461. open: false,
  462. form: {
  463. assigneeUserId: undefined
  464. },
  465. rules: {
  466. assigneeUserId: [
  467. { required: true, message: '新审批人不能为空', trigger: 'change' }
  468. ]
  469. }
  470. },
  471. updateDelegate: {
  472. open: false,
  473. form: {
  474. delegateUserId: undefined,
  475. reason: ''
  476. },
  477. rules: {
  478. delegateUserId: [
  479. { required: true, message: '新审批人不能为空', trigger: 'change' }
  480. ],
  481. reason: [
  482. { required: true, message: '委派理由不能为空', trigger: 'blur' }
  483. ]
  484. }
  485. }
  486. };
  487. },
  488. created() {
  489. // this.id = this.$route.query.id;
  490. // if (!this.id) {
  491. // this.$message.error('未传递 id 参数,无法查看流程信息');
  492. // return;
  493. // }
  494. // this.getDetail();
  495. // 获得用户列表
  496. this.userOptions = [];
  497. listAllUserBind().then((data) => {
  498. this.userOptions.push(...data);
  499. });
  500. },
  501. methods: {
  502. isStockBatchChange() {
  503. return (
  504. String(this.listData.businessCode || '').startsWith('PCBG') ||
  505. String(this.listData.pcViewRouter || '').includes('stockBatchChange') ||
  506. String(this.listData.pcViewRouter || '').includes(
  507. 'warehouseManagement/stockLedger'
  508. )
  509. );
  510. },
  511. /** 解析流程模型里配置的表单路由 JSON:{ pcView, pcHandle, ... } */
  512. parseFormRouteConfig(raw) {
  513. if (!raw) return null;
  514. if (typeof raw === 'object') return raw;
  515. const text = String(raw).trim();
  516. if (!text || text[0] !== '{') return null;
  517. try {
  518. return JSON.parse(text);
  519. } catch (e) {
  520. return null;
  521. }
  522. },
  523. /** 规范化为 /bpm/.../*.vue,便于 require(`@/views${path}`) */
  524. normalizeViewPath(path) {
  525. let text = String(path || '').trim();
  526. if (!text) return '';
  527. text = text.replace(/\\/g, '/');
  528. text = text.replace(/^@\/views/, '');
  529. text = text.replace(/^src\/views/, '');
  530. if (!text.startsWith('/')) text = `/${text}`;
  531. if (text === '/') return '';
  532. return text;
  533. },
  534. /**
  535. * 解析 PC 详情/处理组件路径
  536. * 优先待办带回的 pcViewRouter/pcHandleRouter,
  537. * 其次流程定义 formCustomCreatePath / formKey(pcView、pcHandle)
  538. */
  539. resolveFormRouters() {
  540. const fromTodo = {
  541. view: this.normalizeViewPath(this.listData.pcViewRouter),
  542. handle: this.normalizeViewPath(this.listData.pcHandleRouter)
  543. };
  544. const def = this.processInstance?.processDefinition || {};
  545. const fromDef =
  546. this.parseFormRouteConfig(def.formCustomCreatePath) ||
  547. this.parseFormRouteConfig(def.formKey) ||
  548. this.parseFormRouteConfig(this.listData.formKey) ||
  549. this.parseFormRouteConfig(this.listData.formCustomCreatePath) ||
  550. {};
  551. // 已有审批组件的流程未配路由时使用本项目约定路径
  552. const businessKey = String(
  553. def.key ||
  554. this.listData.businessKey ||
  555. this.listData.processDefinitionKey ||
  556. ''
  557. );
  558. const formFallback = FORM_FALLBACK_MAP[businessKey] || {};
  559. const resolved = {
  560. view:
  561. fromTodo.view ||
  562. this.normalizeViewPath(fromDef.pcView || fromDef.pcViewRouter) ||
  563. this.normalizeViewPath(formFallback.pcView),
  564. handle:
  565. fromTodo.handle ||
  566. this.normalizeViewPath(
  567. fromDef.pcHandle || fromDef.pcHandleRouter
  568. ) ||
  569. this.normalizeViewPath(formFallback.pcHandle)
  570. };
  571. // 排查路由串台:打印三级来源,确认最终组件路径是谁给的
  572. if (process.env.NODE_ENV !== 'production') {
  573. // eslint-disable-next-line no-console
  574. console.log('[流程表单路由解析]', {
  575. businessKey,
  576. '①待办数据': fromTodo,
  577. '②流程定义原始': {
  578. key: def.key,
  579. formCustomCreatePath: def.formCustomCreatePath,
  580. formKey: def.formKey
  581. },
  582. '②流程定义解析': fromDef,
  583. '③前端兜底': formFallback,
  584. 最终: resolved
  585. });
  586. }
  587. return resolved;
  588. },
  589. getBusinessComponentRouter(type) {
  590. const routers = this.resolveFormRouters();
  591. const router = type === 'view' ? routers.view : routers.handle;
  592. if (this.isStockBatchChange()) {
  593. const invalidViewRouter =
  594. type === 'view' &&
  595. String(router || '').includes('warehouseManagement/stockLedger');
  596. if (!router || invalidViewRouter) {
  597. return `/bpm/handleTask/components/stockBatchChange/${
  598. type === 'view' ? 'detailDialog' : 'submit'
  599. }.vue`;
  600. }
  601. }
  602. return router || '';
  603. },
  604. registerAsyncBizComponents() {
  605. const viewRouter = this.getBusinessComponentRouter('view');
  606. const handleRouter = this.getBusinessComponentRouter('handle');
  607. if (!viewRouter || !handleRouter) {
  608. console.error('流程表单路由未配置', {
  609. pcViewRouter: this.listData.pcViewRouter,
  610. pcHandleRouter: this.listData.pcHandleRouter,
  611. formCustomCreatePath:
  612. this.processInstance?.processDefinition?.formCustomCreatePath,
  613. formKey: this.processInstance?.processDefinition?.formKey,
  614. resolved: { viewRouter, handleRouter },
  615. businessCode: this.listData.businessCode,
  616. businessType: this.listData.businessType
  617. });
  618. this.$message.error(
  619. '流程未配置 PC 表单路由。请在流程模型「业务表单」或节点 formKey 中配置:{"pcView":"/bpm/handleTask/components/.../detail.vue","pcHandle":"/bpm/handleTask/components/.../submit.vue"}'
  620. );
  621. return false;
  622. }
  623. // 回填到 listData,便于后续使用
  624. this.listData.pcViewRouter = viewRouter;
  625. this.listData.pcHandleRouter = handleRouter;
  626. console.log('加载业务表单组件', { viewRouter, handleRouter });
  627. const staticComponents = {
  628. '/bpm/handleTask/components/purchaseOrder/returnGoods/detailDialog.vue':
  629. purchaseReturnDetail,
  630. '/bpm/handleTask/components/purchaseOrder/returnGoods/detailDialog':
  631. purchaseReturnDetail,
  632. '/bpm/handleTask/components/purchaseOrder/returnGoods/submit.vue':
  633. purchaseReturnSubmit,
  634. '/bpm/handleTask/components/purchaseOrder/returnGoods/submit':
  635. purchaseReturnSubmit
  636. };
  637. const viewComponent = staticComponents[viewRouter];
  638. const handleComponent = staticComponents[handleRouter];
  639. Vue.component(
  640. 'async-biz-form-component',
  641. viewComponent || ((resolve) => {
  642. require([`@/views${viewRouter}`], resolve);
  643. })
  644. );
  645. Vue.component(
  646. 'async-sub-form-component',
  647. handleComponent || ((resolve) => {
  648. require([`@/views${handleRouter}`], resolve);
  649. })
  650. );
  651. return true;
  652. },
  653. submit(data) {
  654. this.$refs.bziRef.save(data);
  655. },
  656. open(data) {
  657. // 先清空上一条流程,让业务表单组件在新数据渲染前卸载,
  658. // 避免旧流程的组件带着新流程的 businessId 重新取数(串 id 请求)
  659. this.processInstance = {};
  660. this.listData = data;
  661. console.log('实例流程~~~~~~', data);
  662. this.dialogVisible = true;
  663. this.getDetail();
  664. // this.getTasksRecordDetail();
  665. },
  666. activeCompChange(activeComp) {
  667. this.$refs.subForm[0].activeCompChange(activeComp);
  668. },
  669. /** 获得流程实例 */
  670. getDetail() {
  671. // 获得流程实例相关
  672. this.processInstanceLoading = true;
  673. getProcessInstance(this.listData.id).then((response) => {
  674. if (!response) {
  675. this.$message.error('查询不到流程信息!');
  676. return;
  677. }
  678. // 设置流程信息
  679. this.processInstance = response;
  680. // //将业务表单,注册为动态组件
  681. // let formCustomCreatePath = JSON.parse(
  682. // this.processInstance.processDefinition.formCustomCreatePath
  683. // );
  684. // const bizpath = formCustomCreatePath.pcView;
  685. // const subpath = formCustomCreatePath.pcHandle;
  686. this.registerAsyncBizComponents();
  687. // // 设置表单信息
  688. // if (this.processInstance.processDefinition.formType === 10) {
  689. // this.detailForm = {
  690. // ...JSON.parse(this.processInstance.processDefinition.formConf),
  691. // disabled: true, // 表单禁用
  692. // formBtns: false, // 按钮隐藏
  693. // fields: decodeFields(this.processInstance.processDefinition.formFields)
  694. // }
  695. // // 设置表单的值
  696. // this.detailForm.fields.forEach(item => {
  697. // const val = this.processInstance.formVariables[item.__vModel__]
  698. // if (val) {
  699. // item.__config__.defaultValue = val
  700. // }
  701. // });
  702. // }
  703. // 取消加载中
  704. this.processInstanceLoading = false;
  705. });
  706. this.runningTasks = [];
  707. this.auditForms = [];
  708. getTaskListByProcessInstanceId(this.listData.id).then((response) => {
  709. console.log(response, 'response');
  710. // 审批记录
  711. this.tasks = [];
  712. // 移除已取消的审批
  713. response.forEach((task) => {
  714. if (task.result !== 4) {
  715. this.tasks.push(task);
  716. }
  717. });
  718. // 排序,将未完成的排在前面,已完成的排在后面;
  719. this.tasks.sort((a, b) => {
  720. // 有已完成的情况,按照完成时间倒序
  721. if (a.endTime && b.endTime) {
  722. return b.endTime - a.endTime;
  723. } else if (a.endTime) {
  724. return 1;
  725. } else if (b.endTime) {
  726. return -1;
  727. // 都是未完成,按照创建时间倒序
  728. } else {
  729. return b.createTime - a.createTime;
  730. }
  731. });
  732. // 需要审核的记录
  733. const userId = store.getters.user.info.userId;
  734. if (this.tasks.some((item) => item.result == 7)) {
  735. let taskItem = this.tasks.find((item) => item.result == 7);
  736. const stack = [];
  737. let task = [];
  738. stack.push(taskItem.children);
  739. while (stack.length > 0) {
  740. const node = stack.pop();
  741. console.log(node, '-----');
  742. node.forEach((n) => {
  743. if (n.children?.length === 0) {
  744. task.push(n);
  745. } else {
  746. task = [];
  747. stack.push(n.children);
  748. }
  749. });
  750. }
  751. task.forEach((task) => {
  752. if (task.result !== 1 && task.result !== 6) {
  753. // 只有待处理才需要
  754. return;
  755. }
  756. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  757. // 自己不是处理人
  758. return;
  759. }
  760. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  761. // 不是当前流程的
  762. return;
  763. }
  764. this.runningTasks.push({ ...task });
  765. this.auditForms.push({
  766. reason: ''
  767. });
  768. });
  769. } else {
  770. this.tasks.forEach((task) => {
  771. if (task.result !== 1 && task.result !== 6) {
  772. // 只有待处理才需要
  773. return;
  774. }
  775. if (!task.assigneeUser || task.assigneeUser.id !== userId) {
  776. // 自己不是处理人
  777. return;
  778. }
  779. if (task.taskDefinitionKey !== this.listData.taskDefinitionKey) {
  780. // 不是当前流程的
  781. return;
  782. }
  783. this.runningTasks.push({ ...task });
  784. this.auditForms.push({
  785. reason: ''
  786. });
  787. });
  788. }
  789. this.normalizeRunningTasks();
  790. });
  791. },
  792. normalizeRunningTasks() {
  793. const currentTaskIndex = this.runningTasks.findIndex(
  794. (task) => `${task.id}` === `${this.listData.taskId}`
  795. );
  796. const task =
  797. this.runningTasks[currentTaskIndex > -1 ? currentTaskIndex : 0];
  798. this.runningTasks = task ? [task] : [];
  799. this.auditForms = this.runningTasks.map(() => ({
  800. reason: ''
  801. }));
  802. },
  803. getTimelineItemIcon(item) {
  804. if (item.result === 1) {
  805. return 'el-icon-time';
  806. }
  807. if (item.result === 2) {
  808. return 'el-icon-check';
  809. }
  810. if (item.result === 3) {
  811. return 'el-icon-close';
  812. }
  813. if (item.result === 4) {
  814. return 'el-icon-remove-outline';
  815. }
  816. if (item.result === 5) {
  817. return 'el-icon-back';
  818. }
  819. return '';
  820. },
  821. getTimelineItemType(item) {
  822. if (item.result === 1) {
  823. return 'primary';
  824. }
  825. if (item.result === 2) {
  826. return 'success';
  827. }
  828. if (item.result === 3) {
  829. return 'danger';
  830. }
  831. if (item.result === 4) {
  832. return 'info';
  833. }
  834. if (item.result === 5) {
  835. return 'warning';
  836. }
  837. if (item.result === 6) {
  838. return 'default';
  839. }
  840. return '';
  841. },
  842. /** 处理审批通过和不通过的操作 */
  843. handleAudit(data) {
  844. let text = data.status === 1 ? '通过' : '不通过';
  845. this.$message.success(`审批${data.title || text}成功!`);
  846. this.handleClose(); // 获得最新详情
  847. // const index = this.runningTasks.indexOf(task);
  848. // this.$refs['form' + index][0].validate((valid) => {
  849. // if (!valid) {
  850. // return;
  851. // }
  852. // const data = {
  853. // id: task.id,
  854. // reason: this.auditForms[index].reason
  855. // };
  856. // if (pass) {
  857. // approveTask(data).then((response) => {
  858. // this.$message.success('审批通过成功!');
  859. // this.handleClose(); // 获得最新详情
  860. // });
  861. // } else {
  862. // rejectTask(data).then((response) => {
  863. // this.$message.success('审批不通过成功!');
  864. // this.handleClose(); // 获得最新详情
  865. // });
  866. // }
  867. // });
  868. },
  869. /** 处理转办审批人 */
  870. handleUpdateAssignee(task) {
  871. // 设置表单
  872. this.resetUpdateAssigneeForm();
  873. this.updateAssignee.form.id = task.id;
  874. // 设置为打开
  875. this.updateAssignee.open = true;
  876. },
  877. /** 提交转办审批人 */
  878. submitUpdateAssigneeForm() {
  879. this.$refs['updateAssigneeForm'].validate((valid) => {
  880. if (!valid) {
  881. return;
  882. }
  883. if (this.$refs.subForm[0].formUpdate) {
  884. this.$refs.subForm[0].formUpdate();
  885. }
  886. updateTaskAssignee(this.updateAssignee.form).then((response) => {
  887. this.$message.success('转办任务成功!');
  888. this.updateAssignee.open = false;
  889. this.handleClose(); // 获得最新详情
  890. });
  891. });
  892. },
  893. /** 取消转办审批人 */
  894. cancelUpdateAssigneeForm() {
  895. this.updateAssignee.open = false;
  896. this.resetUpdateAssigneeForm();
  897. },
  898. /** 重置转办审批人 */
  899. resetUpdateAssigneeForm() {
  900. this.updateAssignee.form = {
  901. id: undefined,
  902. assigneeUserId: undefined
  903. };
  904. this.resetForm('updateAssigneeForm');
  905. },
  906. /** 处理审批委派的操作 */
  907. handleDelegate(task) {
  908. //this.$modal.msgError("暂不支持【委派】功能,可以使用【转派】替代!");
  909. this.resetUpdateDelegateForm();
  910. this.updateDelegate.form.id = task.id;
  911. // 设置为打开
  912. this.updateDelegate.open = true;
  913. },
  914. /** 提交委派审批人 */
  915. submitUpdateDelegateForm() {
  916. this.$refs['updateDelegateForm'].validate((valid) => {
  917. if (!valid) {
  918. return;
  919. }
  920. delegateTask(this.updateDelegate.form).then((response) => {
  921. this.$message.success('委派任务成功!');
  922. this.updateDelegate.open = false;
  923. this.handleClose(); // 获得最新详情
  924. });
  925. });
  926. },
  927. /** 取消委派审批人 */
  928. cancelUpdateDelegateForm() {
  929. this.updateDelegate.open = false;
  930. this.resetUpdateDelegateForm();
  931. },
  932. /** 重置委派审批人 */
  933. resetUpdateDelegateForm() {
  934. this.updateDelegate.form = {
  935. id: undefined,
  936. delegateUserId: undefined
  937. };
  938. this.resetForm('updateDelegateForm');
  939. },
  940. /** 处理审批退回的操作 */
  941. /** 返回退回节点列表 */
  942. handleBackList(task) {
  943. // 可参考 http://blog.wya1.com/article/636697030/details/7296
  944. getReturnList(task.id).then((response) => {
  945. this.returnList = response.data.data;
  946. if (this.returnList.length == 0) {
  947. this.$message.error('当前没有可回退的节点!');
  948. return;
  949. }
  950. this.formData.id = task.id;
  951. this.returnOpen = true;
  952. });
  953. },
  954. /** 提交退回任务 */
  955. submitReturn() {
  956. if (!this.formData.targetDefinitionKey) {
  957. this.$message.error('请选择退回节点!');
  958. }
  959. this.$refs['formRef'].validate((valid) => {
  960. if (!valid) {
  961. return;
  962. }
  963. returnTask(this.formData).then((res) => {
  964. if (res.data) {
  965. this.$message.success('回退成功!');
  966. this.returnOpen = false;
  967. this.handleClose(); // 获得最新详情
  968. }
  969. });
  970. });
  971. },
  972. handleClose() {
  973. this.$emit('reload');
  974. this.dialogVisible = false;
  975. },
  976. getTableValue(fn) {
  977. // 第二个参数告诉审批组件:用户在表格里是否手动改过单价(用于决定是否需要落库)
  978. fn(
  979. this.$refs.bziRef.getTableValue(),
  980. this.$refs.bziRef.isSinglePriceChanged?.()
  981. );
  982. }
  983. }
  984. };
  985. </script>
  986. <style lang="scss">
  987. .my-process-designer {
  988. height: calc(100vh - 200px);
  989. }
  990. .box-card {
  991. width: 100%;
  992. margin-bottom: 20px;
  993. }
  994. </style>