AuditFlow.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React, { useMemo, useEffect, useState, useRef } from 'react';
  2. import { Steps, Popover } from 'antd';
  3. import styles from './Index.less';
  4. import { queryDDProcessesForecast } from '@/services/boom';
  5. const { Step } = Steps;
  6. const ACTOR_TYPE = {
  7. approver: '审批人',
  8. notifier: '抄送人',
  9. audit: '办理人',
  10. };
  11. const APPROVAL_TYPE = {
  12. MANUAL: '人工审批',
  13. AUTO_AGREE: '自动通过',
  14. AUTO_REFUSE: '自动拒绝',
  15. };
  16. const APPROVAL_METHOD = {
  17. ONE_BY_ONE: '依次审批',
  18. AND: '会签审批',
  19. OR: '或签审批',
  20. };
  21. const ACTIVITY_TYPE = {
  22. target_select: '自选审批人',
  23. target_approval: '指定审批人',
  24. };
  25. function AuditFlow(props) {
  26. const {
  27. processCode,
  28. deptId = '14169890',
  29. userId = '16569001414345099',
  30. formComponentValues,
  31. activityId,
  32. direction,
  33. status,
  34. } = props;
  35. console.log('------------------------------', props);
  36. const [flow, setFlow] = useState({ workflowActivityRules: [] });
  37. const timerRef = useRef({
  38. id: '',
  39. status: false,
  40. });
  41. const current = useMemo(() => {
  42. if (!activityId) {
  43. return flow.workflowActivityRules.length;
  44. } else {
  45. return flow.workflowActivityRules.findIndex(item => item.activityId == activityId);
  46. }
  47. }, [activityId, flow]);
  48. const renderDesc = item => {
  49. return <></>;
  50. };
  51. const renderAlert = () => {
  52. // const audit_comment = history.list[0]?.audit_comment;
  53. let item = '';
  54. switch (status) {
  55. case 0:
  56. if (!flow.list || flow.list.FlowNodes?.length == 0) return;
  57. item = <Alert message="审批拒绝" type="error" />;
  58. break;
  59. case 1:
  60. item = <Alert message="等待审核中" type="info" />;
  61. break;
  62. case 2:
  63. item = <Alert message={`审批被拒绝`} type="error" />;
  64. break;
  65. case 3:
  66. item = <Alert message="审批通过" type="success" />;
  67. break;
  68. }
  69. return <div style={{ marginTop: 20 }}>{item}</div>;
  70. };
  71. const customDot = (dot, { status, index }) => {
  72. let item = flow.workflowActivityRules[index];
  73. return (
  74. <Popover
  75. content={
  76. <div>
  77. 节点类型:{ACTIVITY_TYPE[item.activityType]}
  78. <br />
  79. 操作人类型:{ACTOR_TYPE[item.workflowActor?.actorType]}
  80. <br />
  81. 审批类型:{APPROVAL_TYPE[item.workflowActor?.approvalType]}
  82. <br />
  83. 审批方式:{APPROVAL_METHOD[item.workflowActor?.approvalMethod]}
  84. </div>
  85. }
  86. >
  87. {dot}
  88. </Popover>
  89. );
  90. };
  91. const getDetail = async () => {
  92. if (!timerRef.current.status) {
  93. // 上锁
  94. timerRef.current.status = true;
  95. try {
  96. let flow = await queryDDProcessesForecast({
  97. processCode,
  98. deptId,
  99. userId,
  100. formComponentValues,
  101. });
  102. setFlow(flow);
  103. } catch (error) {}
  104. setTimeout(() => {
  105. // 延时解锁
  106. timerRef.current.status = false;
  107. }, 2000);
  108. } else {
  109. clearTimeout(timerRef.current.id);
  110. // 延迟调用
  111. timerRef.current.id = setTimeout(() => {
  112. getDetail();
  113. }, 2000);
  114. }
  115. };
  116. useEffect(() => {
  117. if (!processCode || !formComponentValues) return;
  118. getDetail();
  119. }, [processCode, formComponentValues]);
  120. return (
  121. <div className={styles.top}>
  122. <Steps current={current} progressDot={customDot} direction={direction}>
  123. {flow.workflowActivityRules.map(item => (
  124. <Step key={item.activityId} title={item?.activityName} />
  125. ))}
  126. {/* <Step key={item.activityId} title={item?.activityName} description={renderDesc(item)} /> */}
  127. </Steps>
  128. {status !== undefined && renderAlert()}
  129. </div>
  130. );
  131. }
  132. export default AuditFlow;