index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, { useState, useEffect, useRef } from 'react';
  2. import { Button, Space, Table, message } from 'antd';
  3. import { connect, useNavigate } from 'umi';
  4. import AuditModal from './AuditModal';
  5. import PageContent from '@/components/PageContent';
  6. import { queryProcessFlows, saveAuditFlowInfo } from '@/services/boom';
  7. function Audit(props) {
  8. const { list = [], classify = [], dispatch, loading } = props;
  9. let navigate = useNavigate();
  10. const [data, setData] = useState();
  11. const [visible, setVisible] = useState({
  12. audit: false,
  13. auditNode: false,
  14. });
  15. const detailRef = useRef();
  16. const columns = [
  17. {
  18. title: '审批流名称',
  19. dataIndex: 'name',
  20. },
  21. {
  22. title: '分类',
  23. dataIndex: 'classify_id',
  24. render: (id) => classify?.find((item) => item.id == id)?.name || '-',
  25. },
  26. {
  27. title: '操作',
  28. render: (item, index) => (
  29. <Space>
  30. <a
  31. onClick={() => {
  32. setCurrentNode(item);
  33. }}
  34. >
  35. 编辑
  36. </a>
  37. <a
  38. onClick={() => {
  39. setData(item);
  40. changeVisible('audit', true);
  41. queryDetail(item);
  42. }}
  43. >
  44. 复制
  45. </a>
  46. </Space>
  47. ),
  48. },
  49. ];
  50. const queryDetail = async (item) => {
  51. const res = await queryProcessFlows({ ids: Number(item.id) });
  52. if (res?.data) {
  53. detailRef.current = res.data;
  54. }
  55. };
  56. const handleCopy = async (values) => {
  57. dispatch({
  58. type: 'flow/addAudit',
  59. payload: {
  60. ...values,
  61. flow_type: 1,
  62. },
  63. callback: async (res) => {
  64. if (res?.data && detailRef.current) {
  65. let param = {
  66. id: Number(res.data?.id),
  67. form_json: detailRef.current.form_json,
  68. process_json: detailRef.current.process_json,
  69. process_simple_json: detailRef.current.process_simple_json,
  70. };
  71. saveAuditFlowInfo(param).then((res) => message.success('添加成功'));
  72. }
  73. changeVisible('audit', false);
  74. },
  75. });
  76. };
  77. const handleAuditOk = (values) => {
  78. dispatch({
  79. type: 'flow/addAudit',
  80. payload: {
  81. ...values,
  82. flow_type: 1,
  83. },
  84. callback: () => {
  85. message.success('新增成功');
  86. changeVisible('audit', false);
  87. },
  88. });
  89. };
  90. const changeVisible = (type, visible) => {
  91. setVisible({
  92. ...visible,
  93. [type]: visible,
  94. });
  95. };
  96. const setCurrentNode = (item) => {
  97. localStorage.setItem('currentAudit', JSON.stringify(item));
  98. dispatch({
  99. type: 'flow/save',
  100. payload: {
  101. current: item.list,
  102. },
  103. });
  104. navigate('/flow/audit');
  105. };
  106. useEffect(() => {
  107. dispatch({
  108. type: 'flow/queryAuditList',
  109. payload: {
  110. flow_type: 1,
  111. },
  112. });
  113. dispatch({
  114. type: 'flow/queryClassify',
  115. payload: {
  116. c_type: 1,
  117. },
  118. });
  119. }, []);
  120. return (
  121. <PageContent>
  122. <Button
  123. key={1}
  124. onClick={() => {
  125. setData(null);
  126. changeVisible('audit', true);
  127. }}
  128. type="primary"
  129. >
  130. 新建流程
  131. </Button>
  132. <Table
  133. style={{ marginTop: 20 }}
  134. loading={loading['flow/queryAuditList']}
  135. rowKey="id"
  136. dataSource={list}
  137. columns={columns}
  138. />
  139. <AuditModal
  140. data={data}
  141. loading={loading['flow/addAudit']}
  142. visible={visible.audit}
  143. onOk={data ? handleCopy : handleAuditOk}
  144. onCancel={() => changeVisible('audit', false)}
  145. classify={classify}
  146. />
  147. </PageContent>
  148. );
  149. }
  150. export default connect(({ flow, loading }) => ({
  151. list: flow.auditList,
  152. classify: flow.classify,
  153. loading: loading.effects,
  154. }))(Audit);