apply.js 9.9 KB

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