OaDetail.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, { useRef, useState } from 'react';
  2. import { PageContainer, ProCard } from '@ant-design/pro-components';
  3. import { Button, Col, Empty, Row, message } from 'antd';
  4. import ApprovalProcess from './components/ApprovalProcess';
  5. import AuditDetailed from './components/AuditDetailed';
  6. import AliyunOSSUpload from '@/components/OssUpload/AliyunOssUploader';
  7. import {
  8. queryProcessFlows,
  9. createAduit,
  10. advanceSubmitNextNode,
  11. queryOSSData,
  12. } from '@/services/boom';
  13. import { useParams, useRequest, useNavigate } from 'umi';
  14. const OaDetail = () => {
  15. const [approvalProcess, setApprovalProcess] = useState([]);
  16. const { oaId } = useParams();
  17. const formValueRef = useRef({
  18. form: '',
  19. });
  20. const uploadList = useRef([]);
  21. const navigate = useNavigate();
  22. const { data, loading } = useRequest(queryProcessFlows, {
  23. defaultParams: [{ ids: oaId }],
  24. });
  25. const { data: OSSData } = useRequest(queryOSSData, {
  26. defaultParams: [{ ids: oaId }],
  27. });
  28. console.log(OSSData);
  29. const { loading: createLoadin, run: createRun } = useRequest(createAduit, {
  30. manual: true,
  31. onSuccess() {
  32. message.success('申请审批成功');
  33. navigate(-1);
  34. },
  35. });
  36. const { run } = useRequest(advanceSubmitNextNode, {
  37. debounceInterval: 500,
  38. manual: true,
  39. formatResult(res) {
  40. setApprovalProcess(res.data[0]);
  41. },
  42. });
  43. //填写表单实时计算审批流程
  44. const advanceSubmit = async (changedFields, allValues) => {
  45. console.log(changedFields, allValues);
  46. let formValues = data.formData
  47. .map((item) => {
  48. const itemProps = item.props;
  49. let val = allValues[itemProps.id];
  50. if (!itemProps.label) return;
  51. if (!val && val !== 0) return;
  52. if (val instanceof Object) {
  53. return {
  54. name: itemProps.label,
  55. id: itemProps.id,
  56. value: [...val],
  57. };
  58. } else if (allValues[itemProps.id]) {
  59. return {
  60. name: itemProps.label,
  61. id: itemProps.id,
  62. value: [allValues[itemProps.id]] || undefined,
  63. };
  64. }
  65. })
  66. .filter((item) => item);
  67. let params = {
  68. flow_id: Number(oaId),
  69. template_node_id: 0,
  70. formComponentValues: formValues,
  71. audit_list: [],
  72. };
  73. formValueRef.current.form = formValues;
  74. run(params);
  75. };
  76. const submit = () => {
  77. const { form } = formValueRef.current;
  78. const audit_list = approvalProcess?.map((item) => {
  79. if (item[0].type == 'role') return item[0].nowValue;
  80. return item[0].value;
  81. });
  82. createRun({
  83. flow_id: Number(oaId),
  84. form: JSON.stringify(form),
  85. audit_list,
  86. files: uploadList.current.join(','),
  87. });
  88. };
  89. const OnModelFileDone = (file) => {
  90. var path = OSSData.host + '/' + file.url;
  91. uploadList.current = [...uploadList.current, path];
  92. // const files = form.getFieldsValue('files');
  93. // form.setFieldValue('files', files.concat(path));
  94. // console.log(uploadList.current);
  95. // setThumbnail(path);
  96. };
  97. return (
  98. <PageContainer
  99. loading={loading}
  100. footer={[
  101. <Button onClick={submit} type="primary" loading={createLoadin}>
  102. 提交审批
  103. </Button>,
  104. ]}
  105. >
  106. <ProCard style={{ minHeight: '80vh' }}>
  107. <Row gutter={24}>
  108. <Col span={12}>
  109. {OSSData && (
  110. <AliyunOSSUpload
  111. OSSData={OSSData}
  112. onDone={OnModelFileDone}
  113. directory={false}
  114. noStyle={false}
  115. label="上传文件"
  116. />
  117. )}
  118. <AuditDetailed
  119. items={data?.formData}
  120. onValuesChange={advanceSubmit}
  121. />
  122. </Col>
  123. <Col span={12}>
  124. {approvalProcess.length == 0 ? (
  125. <Empty description="请先填写表单" />
  126. ) : (
  127. <ApprovalProcess
  128. approvalProcess={approvalProcess}
  129. onChange={setApprovalProcess}
  130. />
  131. )}
  132. </Col>
  133. </Row>
  134. </ProCard>
  135. </PageContainer>
  136. );
  137. };
  138. export default OaDetail;