apply.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. Divider,
  16. } from 'antd';
  17. import { ExclamationCircleOutlined } from '@ant-design/icons';
  18. import { PageContainer } from '@ant-design/pro-components';
  19. const { RangePicker } = DatePicker;
  20. import { useRequest, useModel } from '@umijs/max';
  21. import { queryProfileList, queryApplyList, applyRepeal } from '@/services/boom';
  22. import dayjs from 'dayjs';
  23. import { queryContractCheck, queryGetContractList } from '@/services/contract';
  24. import ContractModal, {
  25. Status,
  26. StatusText,
  27. Type,
  28. } from '../ContractManager/component/Modal';
  29. import PageContent from '@/components/PageContent';
  30. const TYPE = {
  31. Contract: 1,
  32. OA: 2,
  33. };
  34. function Apply(props) {
  35. const {
  36. initialState: { user },
  37. } = 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] = Form.useForm();
  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: OAApplyData,
  68. run: OAApplyRun,
  69. loading: OAApplyLoading,
  70. } = useRequest(queryApplyList, {
  71. // manual: true,
  72. formatResult: (res) => {
  73. return {
  74. data: res.data?.list?.map((item) => {
  75. return {
  76. ...item,
  77. CName: item.AuthorInfo.CName,
  78. table_desc: [item.table_desc],
  79. table_name: item.name,
  80. };
  81. }),
  82. pagination: res.data?.pagination,
  83. };
  84. },
  85. });
  86. //合同管理相关数据
  87. //请求我的申请列表
  88. const {
  89. data: conApplyData,
  90. run: conApplyRun,
  91. loading: conApplyLoading,
  92. } = useRequest(
  93. (data) =>
  94. queryGetContractList({ created_by: user?.ID, pageSize: 10, ...data }),
  95. {
  96. // manual: true,
  97. // defaultParams: [{ created_by: user?.ID, pageSize: 10 }],
  98. formatResult: contractResult,
  99. },
  100. );
  101. //撤回申请
  102. const { run: runRepeal, loading: repealLoading } = useRequest(
  103. (id) => applyRepeal({ id: id }),
  104. {
  105. manual: true,
  106. onSuccess: () => {
  107. OAApplyRun();
  108. },
  109. },
  110. );
  111. const applyData = useMemo(() => {
  112. let result = [];
  113. if (OAApplyData?.data && OAApplyData?.data.length > 0)
  114. result = [...OAApplyData?.data];
  115. return result;
  116. }, [OAApplyData]);
  117. const onTabChange = (activeKey) => {
  118. if (activeKey == '1') {
  119. OAApplyRun();
  120. } else {
  121. conApplyRun({ current: 1 });
  122. }
  123. setTabActive(activeKey);
  124. };
  125. const onRepeal = (record) => {
  126. Modal.confirm({
  127. title: '撤回',
  128. icon: <ExclamationCircleOutlined />,
  129. content: `确定撤回申请`,
  130. okText: '确认',
  131. cancelText: '取消',
  132. onOk: () => {
  133. runRepeal(record.id);
  134. },
  135. });
  136. };
  137. const handleApplySubmit = (values) => {
  138. console.log(values);
  139. OAApplyRun(values);
  140. };
  141. const handleApplyPaginationChange = (pagination) => {
  142. applyFormRef.validateFields().then((values) => {
  143. OAApplyRun({
  144. ...values,
  145. currentPage: pagination.current,
  146. pageSize: pagination.pageSize,
  147. });
  148. });
  149. };
  150. const handleProfilePaginationChange = (pagination) => {
  151. conApplyRun({
  152. current: pagination.current,
  153. });
  154. };
  155. const columns = [
  156. {
  157. title: '标题',
  158. dataIndex: 'table_name',
  159. width: '30%',
  160. },
  161. // {
  162. // title: '摘要',
  163. // dataIndex: 'table_desc',
  164. // render: (descList) => {
  165. // return (
  166. // <ul>
  167. // {descList?.map((item) => (
  168. // <li>{item}</li>
  169. // ))}
  170. // </ul>
  171. // );
  172. // },
  173. // },
  174. {
  175. title: '发起人',
  176. dataIndex: 'CName',
  177. width: '20%',
  178. },
  179. {
  180. title: '发起时间',
  181. render: (record) => {
  182. return dayjs(record.create_time).format('YYYY-MM-DD HH:mm:ss');
  183. },
  184. width: '20%',
  185. },
  186. {
  187. title: '流程状态',
  188. // dataIndex: 'status',
  189. render: (record) => {
  190. if (record.is_repeal) return '已撤回';
  191. switch (record.audit_status) {
  192. case 0:
  193. return '审核中';
  194. case 1:
  195. return '通过';
  196. case 2:
  197. return '拒绝';
  198. case 3:
  199. return '终审通过';
  200. }
  201. },
  202. width: '20%',
  203. },
  204. {
  205. title: '操作',
  206. render: (text, record) => {
  207. return (
  208. !record.is_repeal && (
  209. <Fragment>
  210. <>
  211. <a
  212. style={{ color: '#4096ff' }}
  213. onClick={() => {
  214. navigate(`/profile/${record.id}`);
  215. }}
  216. >
  217. 详情
  218. </a>
  219. {tabActive == '1' && record?.audit_status == 0 && (
  220. <>
  221. <Divider type="vertical" />
  222. <a
  223. style={{ color: '#4096ff' }}
  224. onClick={() => onRepeal(record)}
  225. >
  226. 撤回
  227. </a>
  228. </>
  229. )}
  230. </>
  231. </Fragment>
  232. )
  233. );
  234. },
  235. width: '10%',
  236. },
  237. ];
  238. const agreementColumns = [
  239. {
  240. title: '标题',
  241. dataIndex: 'table_name',
  242. width: '30%',
  243. },
  244. {
  245. title: '摘要',
  246. dataIndex: 'table_desc',
  247. render: (descList) => {
  248. return (
  249. <ul>
  250. {descList?.map((item) => (
  251. <li>{item}</li>
  252. ))}
  253. </ul>
  254. );
  255. },
  256. },
  257. {
  258. title: '发起人',
  259. dataIndex: 'CName',
  260. width: '20%',
  261. },
  262. {
  263. title: '发起时间',
  264. render: (record) => {
  265. return dayjs(record.create_time).format('YYYY-MM-DD HH:mm:ss');
  266. },
  267. width: '20%',
  268. },
  269. {
  270. title: '流程状态',
  271. dataIndex: 'statusText',
  272. // render: (record) => {
  273. // switch (record.audit_status) {
  274. // case 0: return '审核中'
  275. // case 1: return '通过'
  276. // case 2: return '拒绝'
  277. // case 3: return '终审通过'
  278. // }
  279. // },
  280. // width: '20%'
  281. },
  282. {
  283. title: '操作',
  284. render: (text, record) => (
  285. <Fragment>
  286. <>
  287. <a
  288. style={{ color: '#4096ff' }}
  289. onClick={() => {
  290. navigate(`/profile/${record.id}`);
  291. }}
  292. >
  293. 详情
  294. </a>
  295. </>
  296. </Fragment>
  297. ),
  298. width: '10%',
  299. },
  300. ];
  301. const renderPage = (activeKey) => {
  302. if (activeKey == '1')
  303. return (
  304. <>
  305. {' '}
  306. <Form
  307. name="basic"
  308. // labelCol={{ span: 0 }}
  309. // wrapperCol={{ span: 24 }}
  310. onFinish={handleApplySubmit}
  311. form={applyFormRef}
  312. >
  313. <div style={{ display: 'flex' }}>
  314. {/* <Form.Item name="range-picker" label="申请时间:">
  315. <RangePicker />
  316. </Form.Item> */}
  317. <Form.Item name="audit_status" label="状态:" initialValue="">
  318. <Select
  319. style={{ width: 120 }}
  320. options={[
  321. { value: '', label: '全部' },
  322. { value: '0', label: '审核中' },
  323. { value: '1', label: '通过' },
  324. { value: '2', label: '拒绝' },
  325. { value: '3', label: '终审通过' },
  326. ]}
  327. />
  328. </Form.Item>
  329. <Form.Item>
  330. <Button
  331. type="primary"
  332. htmlType="submit"
  333. style={{ marginLeft: 10 }}
  334. >
  335. 查询
  336. </Button>
  337. </Form.Item>
  338. </div>
  339. </Form>
  340. <Table
  341. rowKey="id"
  342. columns={columns}
  343. dataSource={applyData}
  344. loading={OAApplyLoading}
  345. pagination={OAApplyData?.pagination}
  346. onChange={handleApplyPaginationChange}
  347. />
  348. </>
  349. );
  350. else if (activeKey == '2')
  351. return (
  352. <>
  353. {' '}
  354. <Form
  355. name="basic"
  356. // labelCol={{ span: 0 }}
  357. // wrapperCol={{ span: 24 }}
  358. // onFinish={handleApproveSubmit}
  359. ref={approveFormRef}
  360. >
  361. {/* <div style={{ display: 'flex' }}>
  362. <Form.Item name="range-picker" label="审批时间:">
  363. <RangePicker />
  364. </Form.Item>
  365. <Form.Item name="audit_status" label="状态:" initialValue="">
  366. <Select
  367. style={{ width: 120 }}
  368. options={[
  369. { value: '', label: '全部' },
  370. { value: '0', label: '审核中' },
  371. { value: '1', label: '通过' },
  372. { value: '2', label: '拒绝' },
  373. { value: '3', label: '终审通过' },
  374. ]}
  375. />
  376. </Form.Item>
  377. <Form.Item>
  378. <Button
  379. type="primary"
  380. htmlType="submit"
  381. style={{ marginLeft: 10 }}
  382. >
  383. 查询
  384. </Button>
  385. </Form.Item>
  386. </div> */}
  387. </Form>
  388. <Table
  389. columns={agreementColumns}
  390. dataSource={conApplyData?.data}
  391. loading={conApplyLoading}
  392. pagination={conApplyData?.pagination}
  393. onChange={handleProfilePaginationChange}
  394. />
  395. </>
  396. );
  397. };
  398. return (
  399. <PageContent
  400. tabList={[
  401. {
  402. tab: `OA审批(${OAApplyData?.pagination?.total || 0})`,
  403. key: '1',
  404. },
  405. {
  406. tab: `合同管理(${conApplyData?.pagination?.total || 0})`,
  407. key: '2',
  408. },
  409. ]}
  410. onTabChange={onTabChange}
  411. >
  412. <div>{renderPage(tabActive)}</div>
  413. <ContractModal
  414. detail={detail}
  415. type={Type.check}
  416. // projectList={projectData?.list}
  417. visible={conVisible}
  418. handleOk={(data) =>
  419. detail.status == Status.Checking ? runCheck(data) : null
  420. }
  421. handleCancel={() => setConVisible(false)}
  422. />
  423. </PageContent>
  424. );
  425. }
  426. export default Apply;