OaAuditDetail.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // 审批详情
  2. import React, { useState, useMemo, useEffect } from 'react';
  3. import { Steps, Button, Tooltip, message, Spin, Upload } from 'antd';
  4. import { useRequest, useModel, useLocation } from 'umi';
  5. import AuditModal from './components/AuditModal';
  6. import AddCCModal from './components/AddCCModal';
  7. import FormAndFilesNode from './components/FormAndFilesNode';
  8. import {
  9. queryAuditDetail,
  10. updateAuditList,
  11. updateCCList,
  12. uploadAttachment,
  13. } from '@/services/boom';
  14. import { queryGetContractList } from '@/services/contract';
  15. import PageContent from '@/components/PageContent';
  16. import SignModal from './components/SignModal';
  17. import ContractDetail from '../ContractManager/detail';
  18. import { Type } from '../Profile';
  19. import { queryContractDetail } from '../../services/contract';
  20. import { queryCadInfo } from '../../services/cad';
  21. import CadOADetail from '../Cad/components/CadOADetail';
  22. function OaAuditDetail(props) {
  23. const { initialState } = useModel('@@initialState');
  24. const user = initialState?.user || {};
  25. const { userList, run: runUserList } = useModel('userList');
  26. const [auditVisible, setAuditVisible] = useState(false);
  27. const [visible, setVisible] = useState(false);
  28. const [ccVisible, setCCVisible] = useState(false);
  29. const location = useLocation();
  30. const queryParams = new URLSearchParams(location.search);
  31. // 使用queryParams来获取特定查询参数
  32. const id = queryParams.get('id');
  33. const code = queryParams.get('code');
  34. const type = queryParams.get('type') * 1 || Type.OA;
  35. const token = queryParams.get('JWT-TOKEN');
  36. if (!localStorage['JWT-TOKEN']) {
  37. localStorage['JWT-TOKEN'] = token;
  38. }
  39. // const type = code ? Type.CON : Type.OA;
  40. useEffect(() => {
  41. runUserList();
  42. }, []);
  43. useEffect(() => {
  44. if (type == Type.CON) {
  45. runCon({ code });
  46. } else if (type == Type.CAD) {
  47. runCad({ cad_id: code * 1 });
  48. }
  49. }, [type]);
  50. const { data, loading, refresh } = useRequest(queryAuditDetail, {
  51. defaultParams: [{ id }],
  52. });
  53. const {
  54. current_seq,
  55. form,
  56. OaAuditList,
  57. OaCcs,
  58. Files = [],
  59. audit_status,
  60. AuditorInfo,
  61. } = data || {};
  62. // if (OaAuditList) console.log(JSON.stringify(OaAuditList));
  63. const {
  64. data: conData,
  65. run: runCon,
  66. loading: conLoading,
  67. } = useRequest((data) => queryContractDetail(data), {
  68. manual: true,
  69. formatResult: (res) => {
  70. return res?.data?.detail;
  71. },
  72. });
  73. const {
  74. data: cadData,
  75. run: runCad,
  76. loading: loadingCad,
  77. } = useRequest(queryCadInfo, {
  78. manual: true,
  79. formatResult: (res) => {
  80. console.log(res);
  81. return res?.data?.info;
  82. },
  83. });
  84. const getDescription = (node, idx) => {
  85. let str = node?.AuditRoleInfo
  86. ? `审批人:${node?.AuditRoleInfo.Name || '-'}`
  87. : `审批人:${node?.AuditorUser.CName || '-'}`;
  88. //最后一个审批节点显示抄送人信息
  89. const showCCList = idx == OaAuditList?.length - 1 && OaCcs.length > 0;
  90. return (
  91. <div>
  92. {str}
  93. {node.desc && (
  94. <div>
  95. <Tooltip title={node.desc}>
  96. <span style={{ color: '#1A73E8', textDecoration: 'undeline' }}>
  97. 审批意见
  98. </span>
  99. </Tooltip>
  100. </div>
  101. )}
  102. {showCCList && (
  103. <div>
  104. 抄送人:
  105. {OaCcs?.map((item) => item.User?.CName).join(',')}
  106. </div>
  107. )}
  108. </div>
  109. );
  110. };
  111. const updateRes = useRequest(
  112. (values) => {
  113. let list = OaAuditList.map((item) => item.auditor);
  114. if (values.type == 'before') {
  115. list.splice(current_seq - 1, 0, values.approver);
  116. } else {
  117. list.splice(current_seq, 0, values.approver);
  118. }
  119. return updateAuditList(
  120. {
  121. oa_id: Number(id),
  122. audit_list: list,
  123. },
  124. values.type == 'after',
  125. );
  126. },
  127. {
  128. manual: true,
  129. onSuccess() {
  130. message.success('加签成功');
  131. setVisible(false);
  132. refresh();
  133. },
  134. },
  135. );
  136. //加抄送人
  137. const { run: runCC, loading: loadingCC } = useRequest(
  138. (ids) =>
  139. updateCCList({
  140. oa_id: Number(id),
  141. audit_list: ids,
  142. }),
  143. {
  144. manual: true,
  145. onSuccess() {
  146. message.success('添加抄送人成功');
  147. setCCVisible(false);
  148. refresh();
  149. },
  150. },
  151. );
  152. //上传附件
  153. const { run: runAttach, loading: loadingAttach } = useRequest(
  154. uploadAttachment,
  155. {
  156. manual: true,
  157. onSuccess() {
  158. message.success('上传成功');
  159. },
  160. },
  161. );
  162. const handleUploadClick = () => {};
  163. const UploadProps = {
  164. showUploadList: false,
  165. action: `/api/v1/oa/attachment/${id}`,
  166. headers: {
  167. 'JWT-TOKEN': localStorage.getItem('JWT-TOKEN'),
  168. },
  169. onChange({ file, fileList }) {
  170. if (file.status !== 'uploading') {
  171. console.log(fileList);
  172. message.success('上传成功');
  173. }
  174. },
  175. };
  176. const btns = useMemo(() => {
  177. if (!user || !data) return;
  178. if (
  179. user.ID == AuditorInfo?.ID &&
  180. // 0 待审核; 1 上级审批通过
  181. (audit_status === 0 || audit_status === 1)
  182. ) {
  183. return [
  184. <Button
  185. key={1}
  186. style={{ marginRight: 10 }}
  187. type="primary"
  188. onClick={() => setAuditVisible(1)}
  189. >
  190. 审批通过
  191. </Button>,
  192. <Button key={2} onClick={() => setAuditVisible(2)} danger>
  193. 审批拒绝
  194. </Button>,
  195. <Button key={3} onClick={() => setVisible(true)}>
  196. 加签
  197. </Button>,
  198. <Button key={4} onClick={() => setCCVisible(true)}>
  199. 加抄送人
  200. </Button>,
  201. <Upload {...UploadProps}>
  202. <Button>上传附件</Button>
  203. </Upload>,
  204. // <Button key={5} onClick={handleUploadClick}>
  205. // 上传附件
  206. // </Button>,
  207. ];
  208. }
  209. return [];
  210. }, [user, data]);
  211. const renderDetail = () => {
  212. let content = '';
  213. switch (type) {
  214. case Type.CAD:
  215. content = <CadOADetail data={cadData} fileList={Files} />;
  216. break;
  217. case Type.CON:
  218. content = <ContractDetail data={conData} />;
  219. break;
  220. default:
  221. content = <FormAndFilesNode formData={form} fileList={Files} />;
  222. }
  223. return content;
  224. };
  225. return (
  226. <PageContent extra={btns} loading={loading && conLoading}>
  227. <Steps
  228. style={{ marginBottom: 20 }}
  229. current={audit_status == 3 ? OaAuditList?.length : current_seq - 1}
  230. status={audit_status == 2 ? 'error' : 'process'}
  231. items={OaAuditList?.map((item, idx) => ({
  232. title: item.seq_name,
  233. description: getDescription(item, idx),
  234. }))}
  235. ></Steps>
  236. {renderDetail()}
  237. <AddCCModal
  238. userList={userList}
  239. visible={ccVisible}
  240. onCancel={() => setCCVisible(false)}
  241. onCreate={runCC}
  242. loading={loadingCC}
  243. />
  244. <AuditModal
  245. id={id}
  246. visible={auditVisible}
  247. onClose={() => setAuditVisible(false)}
  248. onOk={refresh}
  249. />
  250. <SignModal
  251. userList={userList}
  252. visible={visible}
  253. onCancel={() => setVisible(false)}
  254. onCreate={(values) => updateRes.run(values)}
  255. loading={updateRes.loading}
  256. />
  257. </PageContent>
  258. );
  259. }
  260. export default OaAuditDetail;