approve.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. import React, { Fragment, useState, useEffect, useMemo, useRef } from 'react';
  2. import { useNavigate } from 'umi';
  3. import {
  4. Card,
  5. Table,
  6. Empty,
  7. Button,
  8. Modal,
  9. message,
  10. Form,
  11. DatePicker,
  12. Row,
  13. Col,
  14. Select,
  15. } from 'antd';
  16. import { PageContainer } from '@ant-design/pro-components';
  17. const { RangePicker } = DatePicker;
  18. import { useRequest, useModel } from '@umijs/max';
  19. import { queryProfileList, queryApplyList, audit } from '@/services/boom';
  20. import dayjs from 'dayjs';
  21. import {
  22. queryContractCancelCheck,
  23. queryContractCheck,
  24. queryGetContractList,
  25. } from '@/services/contract';
  26. import ContractModal, {
  27. Status,
  28. StatusText,
  29. Type,
  30. } from '../ContractManager/component/Modal';
  31. import PageContent from '@/components/PageContent';
  32. const TYPE = {
  33. Contract: 1,
  34. OA: 2,
  35. };
  36. function Approve(props) {
  37. const {
  38. initialState: { user },
  39. } = useModel('@@initialState');
  40. const [tabActive, setTabActive] = useState('1');
  41. const [detail, setDetail] = useState({});
  42. const [conVisible, setConVisible] = useState(false);
  43. const approveFormRef = useRef();
  44. const applyFormRef = useRef();
  45. let navigate = useNavigate();
  46. const contractResult = (res) => {
  47. let data = res.data?.list?.map((item) => {
  48. return {
  49. ...item,
  50. table_name: `${item.created_name}提交的合同审批`,
  51. table_desc: [
  52. `合同名称:${item.name}`,
  53. `合同编号:${item.code}`,
  54. `合同金额:${item.amount}万元`,
  55. ],
  56. CName: user.CName,
  57. create_time: item.cancel_on || item.created_on,
  58. type: TYPE.Contract,
  59. statusText: StatusText[item.status],
  60. showBtn:
  61. item.status == Status.Checking || item.status == Status.CalChecking,
  62. // key: `${TYPE.Contract}_${item.id}`,
  63. };
  64. });
  65. return { data, pagination: res.data?.pagination };
  66. };
  67. //OA我的审批和待审批列表
  68. const {
  69. data: OAAuditData,
  70. run: OAAuditRun,
  71. loading: OAAuditLoading,
  72. } = useRequest(queryProfileList, {
  73. formatResult: (res) => {
  74. return {
  75. data: res.data?.list?.map((item) => {
  76. return {
  77. ...item,
  78. CName: item.AuthorInfo.CName,
  79. table_desc: [item.table_desc],
  80. statusText: item.status,
  81. // key: `${TYPE.Contract}_${item.id}`,
  82. showBtn: true,
  83. type: TYPE.OA,
  84. };
  85. }),
  86. pagination: res.data?.pagination,
  87. };
  88. },
  89. });
  90. //合同 我的待审批列表
  91. const {
  92. data: conAuditData,
  93. run: conAuditRun,
  94. loading: conAduitLoading,
  95. } = useRequest(
  96. (data) => queryGetContractList({ ...data, is_parent: -1, page_size: 999 }),
  97. {
  98. // manual: true,
  99. formatResult: contractResult,
  100. },
  101. );
  102. // //审核合同
  103. // const { run: runCheck, loading: checkLoading } = useRequest(
  104. // (data) => queryContractCheck(data),
  105. // {
  106. // manual: true,
  107. // onSuccess: () => {
  108. // conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  109. // // conAuditedRun({ check_by: user.CName });
  110. // setConVisible(false);
  111. // message.success('审核成功');
  112. // },
  113. // onErroe: () => {
  114. // message.error('审核失败');
  115. // },
  116. // },
  117. // );
  118. // //作废审核
  119. // const { run: calCheckRun } = useRequest(
  120. // (data) => queryContractCancelCheck(data),
  121. // {
  122. // manual: true,
  123. // onSuccess: () => {
  124. // message.success('审核成功');
  125. // setConVisible(false);
  126. // conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  127. // },
  128. // onError: () => {
  129. // message.success('审核失败');
  130. // },
  131. // },
  132. // );
  133. // //审核合同
  134. // const { run: runCheck, loading: checkLoading } = useRequest(
  135. // (data) => queryContractCheck(data),
  136. // {
  137. // manual: true,
  138. // onSuccess: () => {
  139. // conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  140. // // conAuditedRun({ check_by: user.CName });
  141. // setConVisible(false);
  142. // message.success('审核成功');
  143. // },
  144. // onErroe: () => {
  145. // message.error('审核失败');
  146. // },
  147. // },
  148. // );
  149. // //作废审核
  150. // const { run: calCheckRun } = useRequest(
  151. // (data) => queryContractCancelCheck(data),
  152. // {
  153. // manual: true,
  154. // onSuccess: () => {
  155. // message.success('审核成功');
  156. // setConVisible(false);
  157. // conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  158. // },
  159. // onError: () => {
  160. // message.success('审核失败');
  161. // },
  162. // },
  163. // );
  164. //审核合同
  165. const { run: runOACheck } = useRequest(audit, {
  166. manual: true,
  167. onSuccess: (data) => {
  168. if (data?.Code) {
  169. message.error(data?.Msg || '审核失败');
  170. return;
  171. }
  172. setTimeout(() => {
  173. conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  174. }, 1000);
  175. // conAuditedRun({ check_by: user.CName });
  176. setConVisible(false);
  177. message.success('审核成功');
  178. },
  179. onErroe: () => {
  180. message.error('审核失败');
  181. },
  182. });
  183. const applyData = useMemo(() => {
  184. let result = [];
  185. if (OAAuditData?.data && OAAuditData?.data.length > 0)
  186. result = [...OAAuditData?.data];
  187. return result;
  188. }, [OAAuditData]);
  189. const onTabChange = (activeKey) => {
  190. if (activeKey == '1') {
  191. OAAuditRun({ current: 1, page_size: 10 });
  192. } else {
  193. if (user?.Permission['menu-001-audit'])
  194. conAuditRun({ multi_status: '1,4', current: 1, page_size: 10 });
  195. }
  196. setTabActive(activeKey);
  197. };
  198. const handleApplySubmit = (values) => {
  199. console.log(values);
  200. OAApplyRun(values);
  201. };
  202. const handleProfilePaginationChange = (pagination) => {
  203. conAuditRun({
  204. multi_status: user?.Permission['menu-001-audit'] ? '1,4' : undefined,
  205. current: pagination.current,
  206. page_size: 10,
  207. });
  208. };
  209. const handleApplyPaginationChange = (pagination) => {
  210. OAAuditRun({
  211. current: pagination.current,
  212. pageSize: pagination.pageSize,
  213. });
  214. };
  215. const columns = [
  216. {
  217. title: '标题',
  218. dataIndex: 'table_name',
  219. width: '30%',
  220. },
  221. {
  222. title: '摘要',
  223. dataIndex: 'table_desc',
  224. render: (descList) => {
  225. return (
  226. <ul>
  227. {descList?.map((item) => (
  228. <li>{item}</li>
  229. ))}
  230. </ul>
  231. );
  232. },
  233. },
  234. {
  235. title: '发起人',
  236. dataIndex: 'CName',
  237. width: '20%',
  238. },
  239. {
  240. title: '发起时间',
  241. render: (record) => {
  242. return dayjs(record.create_time).format('YYYY-MM-DD HH:mm:ss');
  243. },
  244. width: '20%',
  245. },
  246. {
  247. title: '流程状态',
  248. dataIndex: 'status',
  249. // render: (record) => {
  250. // switch (record.audit_status) {
  251. // case 0: return '审核中'
  252. // case 1: return '通过'
  253. // case 2: return '拒绝'
  254. // case 3: return '终审通过'
  255. // }
  256. // },
  257. // width: '20%'
  258. },
  259. {
  260. title: '操作',
  261. render: (text, record) => (
  262. <Fragment>
  263. <>
  264. <a
  265. style={{ color: '#4096ff' }}
  266. onClick={() => {
  267. navigate(`/profile/${record.id}`);
  268. }}
  269. >
  270. 详情
  271. </a>
  272. </>
  273. </Fragment>
  274. ),
  275. width: '10%',
  276. },
  277. ];
  278. const agreementColumns = [
  279. {
  280. title: '标题',
  281. dataIndex: 'table_name',
  282. },
  283. {
  284. title: '摘要',
  285. dataIndex: 'table_desc',
  286. render: (descList) => {
  287. return (
  288. <ul>
  289. {descList?.map((item) => (
  290. <li>{item}</li>
  291. ))}
  292. </ul>
  293. );
  294. },
  295. },
  296. {
  297. title: '发起人',
  298. dataIndex: 'CName',
  299. },
  300. {
  301. title: '发起时间',
  302. render: (record) => {
  303. return dayjs(record.create_time).format('YYYY-MM-DD HH:mm:ss');
  304. },
  305. },
  306. {
  307. title: '流程状态',
  308. dataIndex: 'statusText',
  309. },
  310. {
  311. title: '操作',
  312. dataIndex: 'showBtn',
  313. render: (text, record) => (
  314. <>
  315. {text ? (
  316. <a
  317. style={{ color: '#4096ff' }}
  318. onClick={() => {
  319. if (record.type == TYPE.Contract) {
  320. setDetail(record);
  321. setConVisible(true);
  322. } else {
  323. navigate(`/oa/detail/${record.flow_id}/${record.id}`);
  324. }
  325. }}
  326. >
  327. 审批
  328. </a>
  329. ) : (
  330. <div>已审批</div>
  331. )}
  332. </>
  333. ),
  334. },
  335. ];
  336. const renderPage = (activeKey) => {
  337. if (activeKey == '1')
  338. return (
  339. <>
  340. {' '}
  341. <Form
  342. name="basic"
  343. // labelCol={{ span: 0 }}
  344. // wrapperCol={{ span: 24 }}
  345. onFinish={handleApplySubmit}
  346. ref={applyFormRef}
  347. >
  348. {/* <div style={{ display: 'flex' }}>
  349. <Form.Item name="range-picker" label="申请时间:">
  350. <RangePicker />
  351. </Form.Item>
  352. <Form.Item>
  353. <Button
  354. type="primary"
  355. htmlType="submit"
  356. style={{ marginLeft: 10 }}
  357. >
  358. 查询
  359. </Button>
  360. </Form.Item>
  361. </div> */}
  362. </Form>
  363. <Table
  364. rowKey="id"
  365. columns={columns}
  366. dataSource={applyData}
  367. loading={OAAuditLoading}
  368. pagination={OAAuditData?.pagination}
  369. onChange={handleApplyPaginationChange}
  370. />
  371. </>
  372. );
  373. else if (activeKey == '2')
  374. return (
  375. <>
  376. {' '}
  377. <Form
  378. name="basic"
  379. // labelCol={{ span: 0 }}
  380. // wrapperCol={{ span: 24 }}
  381. // onFinish={handleApproveSubmit}
  382. ref={approveFormRef}
  383. >
  384. {/* <div style={{ display: 'flex' }}>
  385. <Form.Item name="range-picker" label="审批时间:">
  386. <RangePicker />
  387. </Form.Item>
  388. <Form.Item name="audit_status" label="状态:" initialValue="">
  389. <Select
  390. style={{ width: 120 }}
  391. options={[
  392. { value: '', label: '全部' },
  393. { value: '0', label: '审核中' },
  394. { value: '1', label: '通过' },
  395. { value: '2', label: '拒绝' },
  396. { value: '3', label: '终审通过' },
  397. ]}
  398. />
  399. </Form.Item>
  400. <Form.Item>
  401. <Button
  402. type="primary"
  403. htmlType="submit"
  404. style={{ marginLeft: 10 }}
  405. >
  406. 查询
  407. </Button>
  408. </Form.Item>
  409. </div> */}
  410. </Form>
  411. <Table
  412. columns={agreementColumns}
  413. dataSource={conAuditData?.data}
  414. loading={conAduitLoading}
  415. pagination={conAuditData?.pagination}
  416. onChange={handleProfilePaginationChange}
  417. />
  418. </>
  419. );
  420. };
  421. return (
  422. <PageContent
  423. tabList={[
  424. {
  425. tab: `OA审批(${OAAuditData?.pagination?.total || 0})`,
  426. key: '1',
  427. },
  428. {
  429. tab: `合同管理(${conAuditData?.pagination?.total || 0})`,
  430. key: '2',
  431. },
  432. ]}
  433. onTabChange={onTabChange}
  434. >
  435. <div>{renderPage(tabActive)}</div>
  436. <ContractModal
  437. detail={detail}
  438. type={Type.check}
  439. // projectList={projectData?.list}
  440. visible={conVisible}
  441. handleOk={
  442. (data) => runOACheck(data)
  443. // detail.status == Status.Checking
  444. // ? runOACheck(data)
  445. // : detail.status == Status.CalChecking
  446. // ? calCheckRun(data)
  447. // : null
  448. }
  449. handleCancel={() => setConVisible(false)}
  450. />
  451. </PageContent>
  452. );
  453. }
  454. export default Approve;