ApprovalProcess.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React, { useEffect, useMemo, useState } from 'react';
  2. import { queryUserListByRoleID, queryLeader } from '@/services/boom';
  3. import { connect } from 'umi';
  4. import { PlusOutlined } from '@ant-design/icons';
  5. import { Popover, Radio, RadioChangeEvent, Spin, Steps } from 'antd';
  6. import { useModel, useRequest } from '@umijs/max';
  7. const { Step } = Steps;
  8. enum TYPE {
  9. ROLE = 'role',
  10. USER = 'user',
  11. LEADER = 'leader',
  12. }
  13. const ApprovalProcess = (props: any) => {
  14. const {
  15. approvalProcess,
  16. leaderData,
  17. dispatch,
  18. onChange,
  19. roleList = [],
  20. } = props;
  21. const [selectUserList, setSelectUserList] = useState([]);
  22. const [curNodeIdx, setCurNodeIdx] = useState(-1);
  23. const [loading, setLoading] = useState(false);
  24. const { userList, run } = useModel('userList');
  25. const list = useMemo(() => {
  26. approvalProcess?.forEach((item: any) => {
  27. if (item.length > 1 && item[0].type == TYPE.USER) {
  28. item.forEach((curUser: any) => {
  29. curUser.name =
  30. userList.find((user: any) => user.ID == curUser.value)?.CName ||
  31. '-';
  32. });
  33. } else if (item.length == 1 && item[0].type == TYPE.USER) {
  34. item[0].name =
  35. userList.find((user: any) => user.ID == item[0].value)?.CName || '-';
  36. } else if (item.length == 1 && item[0].nowType == TYPE.USER) {
  37. item[0].name =
  38. userList.find((user: any) => user.ID == item[0].nowValue)?.CName ||
  39. '-';
  40. } else {
  41. item[0].name = null;
  42. }
  43. });
  44. return approvalProcess;
  45. }, [approvalProcess]);
  46. const onStepsChange = async (current: any, list: any) => {
  47. setLoading(true);
  48. const itemNode = list[current][0];
  49. if (itemNode.type !== 'role') return;
  50. const data = await queryUserListByRoleID({ role_id: itemNode.value });
  51. setCurNodeIdx(current);
  52. setSelectUserList(data);
  53. setLoading(false);
  54. };
  55. const selectedUserId = ({ target: { value } }: RadioChangeEvent) => {
  56. //userId
  57. const name = userList.find((user: any) => user.ID == value)?.CName || '-';
  58. const data = { nowType: TYPE.USER, nowValue: Number(value), name }; //type: TYPE.USER, value: Number(value)
  59. list[curNodeIdx][0] = { ...list[curNodeIdx][0], ...data };
  60. console.log([...list]);
  61. onChange?.([...list]);
  62. };
  63. const content = (
  64. <Spin spinning={loading}>
  65. <Radio.Group onChange={selectedUserId}>
  66. {selectUserList.map((item: any) => (
  67. // <Button onClick={() => selectedUserId(item.user_id)}>{item.c_name}</Button>
  68. <Radio.Button value={item.user_id}>{item.c_name}</Radio.Button>
  69. ))}
  70. </Radio.Group>
  71. </Spin>
  72. );
  73. const getLeaderContent = (length: any) => (
  74. <Steps
  75. progressDot
  76. current={-1}
  77. direction="vertical"
  78. items={leaderData
  79. ?.slice(0, length || 0)
  80. .map((leader: any) => ({ title: leader.CName }))}
  81. ></Steps>
  82. );
  83. useEffect(() => {
  84. dispatch({
  85. type: 'user/getRoleList',
  86. });
  87. run();
  88. }, []);
  89. return (
  90. <>
  91. <Steps
  92. current={-1}
  93. direction="vertical"
  94. onChange={(value) => onStepsChange(value, list)}
  95. >
  96. {list?.map((item: any, index: Number) =>
  97. item[0]?.type == TYPE.LEADER ? (
  98. <Step
  99. key={String(index)}
  100. icon={
  101. <Popover
  102. placement="bottomLeft"
  103. title="查看审批人"
  104. content={getLeaderContent(item[0]?.value)}
  105. overlayStyle={{ width: '300px' }}
  106. >
  107. <PlusOutlined />
  108. </Popover>
  109. }
  110. title={`${Math.min(
  111. item[0]?.value,
  112. leaderData?.length,
  113. )}级主管审批`}
  114. />
  115. ) : (
  116. <Step
  117. key={String(index)}
  118. icon={
  119. <Popover
  120. placement="bottomLeft"
  121. title={'选择审批人'}
  122. content={content}
  123. trigger="click"
  124. overlayStyle={{ width: '300px' }}
  125. >
  126. <PlusOutlined />
  127. </Popover>
  128. }
  129. title={
  130. item[0]?.name ||
  131. `从${
  132. roleList?.find((cur: any) => cur.ID == item[0]?.value)
  133. ?.Name || '-'
  134. }选择`
  135. }
  136. />
  137. ),
  138. )}
  139. </Steps>
  140. </>
  141. );
  142. };
  143. export default connect(({ user }: any) => ({
  144. roleList: user.roleList,
  145. }))(ApprovalProcess);