OaDetail.js 4.4 KB

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