approve.js 10 KB

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