index.jsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import React, { useState, useRef, useEffect } from 'react';
  2. import { Button, DatePicker, Input, Select, Space, Table, message } from 'antd';
  3. import styles from './index.less';
  4. import ContractModal, { Type } from './component/Modal';
  5. import { PageContainer } from '@ant-design/pro-components';
  6. import { useRequest, useModel } from '@umijs/max';
  7. import { connect } from 'umi';
  8. import {
  9. queryApproval,
  10. queryContract,
  11. queryContractCancel,
  12. queryGetContractList,
  13. } from '../../services/contract';
  14. import dayjs from 'dayjs';
  15. import useModal from 'antd/es/modal/useModal';
  16. const ConteactManager = (props) => {
  17. const { dispatch } = props;
  18. const [searchData, setSearchData] = useState({
  19. effect_on: '',
  20. project_name: '',
  21. status: '',
  22. page_size: 10,
  23. current: 0,
  24. name: '',
  25. });
  26. const { user } = useModel('userInfo');
  27. const [visible, setVisible] = useState(false);
  28. const [detail, setDetail] = useState({});
  29. const [data, setData] = useState([]);
  30. const [pagination, setPagination] = useState({ current: 0 });
  31. const typeRef = useRef();
  32. const parentIdRef = useRef(0);
  33. const showBtn = (record, type) => {
  34. let bool = false;
  35. switch (type) {
  36. case 'download':
  37. if (user?.Permission['menu-001-audit'] || record.created_by == user.ID)
  38. bool = true;
  39. break;
  40. case 'addOrCal':
  41. if (record.created_by == user.ID) bool = true;
  42. break;
  43. }
  44. return bool;
  45. };
  46. const columns = [
  47. {
  48. title: '合同编号',
  49. dataIndex: 'code',
  50. key: 'code',
  51. align: 'center',
  52. width: '12%',
  53. },
  54. {
  55. title: '合同生效时间',
  56. dataIndex: 'effect_on',
  57. key: 'effect_on',
  58. align: 'center',
  59. },
  60. {
  61. title: '合同名称',
  62. dataIndex: 'name',
  63. key: 'name',
  64. align: 'center',
  65. },
  66. {
  67. title: '甲方',
  68. dataIndex: 'party_a',
  69. key: 'party_a',
  70. align: 'center',
  71. },
  72. {
  73. title: '丙方',
  74. dataIndex: 'party_c',
  75. key: 'party_c',
  76. align: 'center',
  77. },
  78. {
  79. title: '所属部门/子公司',
  80. dataIndex: 'dep_name',
  81. key: 'dep_name',
  82. align: 'center',
  83. },
  84. {
  85. title: '项目名称',
  86. dataIndex: 'project_name',
  87. key: 'project_name',
  88. align: 'center',
  89. },
  90. {
  91. title: '合同总价(万元)',
  92. dataIndex: 'amount',
  93. key: 'amount',
  94. align: 'center',
  95. },
  96. {
  97. title: '经办人',
  98. dataIndex: 'deal_by',
  99. key: 'deal_by',
  100. align: 'center',
  101. },
  102. {
  103. title: '状态',
  104. dataIndex: 'status',
  105. key: 'status',
  106. align: 'center',
  107. render: (status) => {
  108. let str = '';
  109. switch (status) {
  110. case 1:
  111. str = '待审核';
  112. break;
  113. case 2:
  114. str = '审核拒绝';
  115. break;
  116. case 3:
  117. str = '已存档';
  118. break;
  119. case 4:
  120. str = '作废待审核';
  121. break;
  122. case 5:
  123. str = '作废拒绝';
  124. break;
  125. case 6:
  126. str = '已作废';
  127. break;
  128. }
  129. return <div>{str}</div>;
  130. },
  131. },
  132. {
  133. title: '操作',
  134. width: '210px',
  135. align: 'center',
  136. render: (record) => {
  137. return (
  138. <Space>
  139. <a
  140. onClick={() => {
  141. typeRef.current = Type.detail;
  142. parentIdRef.current = 0;
  143. setDetail(record);
  144. setVisible(true);
  145. }}
  146. >
  147. 详情
  148. </a>
  149. <a onClick={handlePreView}>预览</a>
  150. {showBtn(record, 'download') && <a onClick={handleUpload}>下载</a>}
  151. {showBtn(record, 'addOrCal') && !record.parent_id && (
  152. <a
  153. onClick={() => {
  154. typeRef.current = Type.add;
  155. parentIdRef.current = record.id;
  156. setDetail({});
  157. setVisible(true);
  158. }}
  159. >
  160. 增补
  161. </a>
  162. )}
  163. <a
  164. onClick={() => {
  165. typeRef.current = Type.cancel;
  166. setDetail(record);
  167. setVisible(true);
  168. }}
  169. >
  170. 作废
  171. </a>
  172. </Space>
  173. );
  174. },
  175. },
  176. ];
  177. useEffect(() => {
  178. dispatch({
  179. type: 'user/fetch',
  180. });
  181. }, []);
  182. //请求列表
  183. const { run, loading } = useRequest((data) => queryGetContractList(data), {
  184. defaultParams: [searchData],
  185. onSuccess: (data) => {
  186. let resultData = data?.list?.map((item) => {
  187. return item.sub_num > 0 ? { ...item, children: [] } : item;
  188. });
  189. setData(resultData);
  190. setPagination(data?.pagination);
  191. // setData({ list: resultData, pagination: data?.pagination });
  192. console.log(data);
  193. },
  194. });
  195. //编辑新增接口
  196. const { run: editRun } = useRequest((data) => queryContract(data), {
  197. manual: true,
  198. onSuccess: () => {
  199. message.success('添加成功');
  200. setVisible(false);
  201. run(searchData);
  202. },
  203. onError: () => {
  204. message.success('添加失败');
  205. },
  206. });
  207. //作废发起
  208. const { run: calRun } = useRequest((data) => queryContractCancel(data), {
  209. manual: true,
  210. onSuccess: () => {
  211. message.success('发起作废成功');
  212. setVisible(false);
  213. run(searchData);
  214. },
  215. onError: () => {
  216. message.success('发起作废失败');
  217. },
  218. });
  219. //请求项目列表
  220. const { data: projectData } = useRequest(queryApproval, {
  221. defaultParams: [{ pageSize: 99999 }],
  222. });
  223. const handlePreView = () => {
  224. // originFileObj 是读取的文件对象,如上传组件读取到的
  225. // const fileURL = URL.createObjectURL(originFileObj);
  226. // window.open(fileURL);
  227. };
  228. const handleUpload = () => {};
  229. const handleSearch = () => {
  230. run(searchData);
  231. };
  232. const handleExport = () => {};
  233. const handleQueryChildren = async (req) => {
  234. const res = await queryGetContractList(req);
  235. if (res?.data?.list) {
  236. let resultData = [...data];
  237. let idx = data.findIndex((item) => item.id == req.is_parent);
  238. if (idx > -1) {
  239. resultData[idx].children = res?.data?.list;
  240. setData(resultData);
  241. setPagination(res.data?.pagination);
  242. // setData({ list: resultData, pagination: res.data?.pagination });
  243. }
  244. }
  245. };
  246. const handleOk = (data) => {
  247. if (typeRef.current == Type.add) {
  248. editRun(data);
  249. } else if (typeRef.current == Type.cancel) {
  250. calRun(data);
  251. }
  252. };
  253. const onPageChange = (page) => {
  254. run({ ...searchData, current: page });
  255. };
  256. return (
  257. <PageContainer>
  258. <div className={styles.searchContent}>
  259. <div className={styles.itemFlex}>
  260. <div>合同生效日期:</div>
  261. <DatePicker
  262. onChange={(e) => {
  263. setSearchData({
  264. ...searchData,
  265. effect_on: e ? dayjs(e).format('YYYY-MM-DD') : null,
  266. });
  267. }}
  268. />
  269. </div>
  270. <div className={styles.itemFlex}>
  271. <div>项目名称:</div>
  272. <Select
  273. style={{ width: 200 }}
  274. placeholder="请选择"
  275. onChange={(e) => {
  276. setSearchData({
  277. ...searchData,
  278. project_name: e,
  279. });
  280. }}
  281. options={projectData?.list?.map((item) => {
  282. return {
  283. value: item.project_name,
  284. label: item.project_name,
  285. };
  286. })}
  287. />
  288. </div>
  289. <div className={styles.itemFlex}>
  290. <div>状态:</div>
  291. <Select
  292. style={{ width: 150 }}
  293. placeholder="请选择"
  294. allowClear
  295. onChange={(e) => {
  296. setSearchData({
  297. ...searchData,
  298. status: e,
  299. });
  300. }}
  301. options={[
  302. { value: 3, label: '已归档' },
  303. { value: 1, label: '归档审核中' },
  304. { value: 4, label: '作废审核中' },
  305. { value: 6, label: '已作废' },
  306. { value: 2, label: '归档拒绝' },
  307. { value: 5, label: '作废拒绝' },
  308. ]}
  309. />
  310. </div>
  311. <Input
  312. className={styles.inputSty}
  313. placeholder="请输入合同名称/编号"
  314. allowClear
  315. onChange={(e) => {
  316. setSearchData({
  317. ...searchData,
  318. name: e.target.value,
  319. });
  320. }}
  321. />
  322. <Button
  323. type="primary"
  324. className={styles.searchBtnSty}
  325. onClick={handleSearch}
  326. >
  327. 查询
  328. </Button>
  329. <Button
  330. type="primary"
  331. onClick={() => {
  332. typeRef.current = Type.add;
  333. setDetail({});
  334. setVisible(true);
  335. }}
  336. >
  337. 新增
  338. </Button>
  339. <Button
  340. type="primary"
  341. className={styles.exportBtnSty}
  342. onClick={handleExport}
  343. >
  344. 导出
  345. </Button>
  346. </div>
  347. <Table
  348. rowKey="code"
  349. loading={loading}
  350. columns={columns}
  351. dataSource={data}
  352. indentSize={70}
  353. onExpand={(expanded, record) => {
  354. console.log(expanded, record);
  355. if (expanded) handleQueryChildren({ is_parent: record.id });
  356. }}
  357. pagination={{ ...pagination, onChange: onPageChange }}
  358. />
  359. <ContractModal
  360. detail={detail}
  361. type={typeRef.current}
  362. parent_id={parentIdRef.current}
  363. projectList={projectData?.list}
  364. visible={visible}
  365. handleOk={handleOk}
  366. handleCancel={() => setVisible(false)}
  367. />
  368. </PageContainer>
  369. );
  370. };
  371. export default connect(({ user, loading }) => ({
  372. userList: user.list,
  373. }))(ConteactManager);