ApprovalProcess.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React, { useEffect, useMemo, useState } from 'react';
  2. import { queryUserListByRoleID } 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 } from '@umijs/max';
  7. const { Step } = Steps;
  8. enum TYPR {
  9. ROLE = 'role',
  10. USER = 'user',
  11. }
  12. const ApprovalProcess = (props: any) => {
  13. const { approvalProcess, dispatch, onChange, roleList = [] } = props;
  14. const [selectUserList, setSelectUserList] = useState([]);
  15. const [curNodeIdx, setCurNodeIdx] = useState(-1);
  16. const [loading, setLoading] = useState(false);
  17. const { userList, run } = useModel('userList');
  18. const list = useMemo(() => {
  19. approvalProcess?.forEach((item: any) => {
  20. if (item.length > 1 && item[0].type == TYPR.USER) {
  21. item.forEach((curUser: any) => {
  22. curUser.name =
  23. userList.find((user: any) => user.ID == curUser.value)?.CName ||
  24. '-';
  25. });
  26. } else if (item.length == 1 && item[0].type == TYPR.USER) {
  27. item[0].name =
  28. userList.find((user: any) => user.ID == item[0].value)?.CName || '-';
  29. } else if (item.length == 1 && item[0].nowType == TYPR.USER) {
  30. item[0].name =
  31. userList.find((user: any) => user.ID == item[0].nowValue)?.CName ||
  32. '-';
  33. } else {
  34. item[0].name = null;
  35. }
  36. });
  37. return approvalProcess;
  38. }, [approvalProcess]);
  39. const onStepsChange = async (current: any, list: any) => {
  40. setLoading(true);
  41. const itemNode = list[current][0];
  42. if (itemNode.type !== 'role') return;
  43. const data = await queryUserListByRoleID({ role_id: itemNode.value });
  44. setCurNodeIdx(current);
  45. setSelectUserList(data);
  46. setLoading(false);
  47. };
  48. const selectedUserId = ({ target: { value } }: RadioChangeEvent) => {
  49. //userId
  50. const name = userList.find((user: any) => user.ID == value)?.CName || '-';
  51. const data = { nowType: TYPR.USER, nowValue: Number(value), name }; //type: TYPR.USER, value: Number(value)
  52. list[curNodeIdx][0] = { ...list[curNodeIdx][0], ...data };
  53. console.log([...list]);
  54. onChange?.([...list]);
  55. };
  56. const content = (
  57. <Spin spinning={loading}>
  58. <Radio.Group onChange={selectedUserId}>
  59. {selectUserList.map((item: any) => (
  60. // <Button onClick={() => selectedUserId(item.user_id)}>{item.c_name}</Button>
  61. <Radio.Button value={item.user_id}>{item.c_name}</Radio.Button>
  62. ))}
  63. </Radio.Group>
  64. </Spin>
  65. );
  66. useEffect(() => {
  67. dispatch({
  68. type: 'user/getRoleList',
  69. });
  70. run();
  71. }, []);
  72. return (
  73. <>
  74. <Steps
  75. current={-1}
  76. direction="vertical"
  77. onChange={(value) => onStepsChange(value, list)}
  78. >
  79. {list?.map((item: any) => (
  80. <Step
  81. key={item[0]?.value}
  82. icon={
  83. <Popover
  84. placement="bottomLeft"
  85. title={'选择审批人'}
  86. content={content}
  87. trigger="click"
  88. overlayStyle={{ width: '300px' }}
  89. >
  90. <PlusOutlined />
  91. </Popover>
  92. }
  93. title={
  94. item[0]?.name ||
  95. `从${
  96. roleList?.find((cur: any) => cur.ID == item[0]?.value)?.Name ||
  97. '-'
  98. }选择`
  99. }
  100. />
  101. ))}
  102. </Steps>
  103. </>
  104. );
  105. };
  106. export default connect(({ user }: any) => ({
  107. roleList: user.roleList,
  108. }))(ApprovalProcess);