index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import Header from '@/components/Header'
  2. import Slot from '@/components/Header/slot'
  3. import SvgIcon from '@/components/SvgIcon'
  4. import { ContractTree } from '@/types/contract'
  5. import consts from '@/utils/consts'
  6. import { CaretDownOutlined } from '@ant-design/icons'
  7. import { Button, Dropdown, Menu, message, Table } from 'antd'
  8. import { ColumnsType } from 'antd/lib/table'
  9. import React, { useEffect, useState } from 'react'
  10. import { useActivate } from 'react-activation'
  11. import { RouteComponentProps } from 'react-router'
  12. import { Link } from 'react-router-dom'
  13. import { apiContractList } from './api'
  14. import styles from './index.module.scss'
  15. import './index.scss'
  16. const List: React.FC<RouteComponentProps> = () => {
  17. const [ tree, setTree ] = useState({
  18. bidsectionId: '',
  19. children: [],
  20. childsTotal: 0,
  21. contracts: 0,
  22. contractsIncome: '',
  23. contractsIncomeProgress: '',
  24. contractsPaid: '',
  25. contractsPay: '',
  26. contractsPayProgress: '',
  27. contractsReturned: '',
  28. csrf: '',
  29. hasFolder: false,
  30. id: '',
  31. isBid: false,
  32. isEnd: false,
  33. isfolder: 0,
  34. name: '',
  35. parentId: '',
  36. projectId: ''
  37. })
  38. const getTree = async () => {
  39. const { data = {}, code = -1 } = await apiContractList()
  40. if (code === consts.RET_CODE.SUCCESS) {
  41. setTree(data)
  42. }
  43. }
  44. const columns:ColumnsType<ContractTree> = [
  45. {
  46. title: '名称',
  47. dataIndex: 'name',
  48. key: 'name',
  49. width: '25%',
  50. render: (text: string, record: ContractTree) => {
  51. if (record.isfolder) {
  52. return <div style={{ verticalAlign: "baseline" }}><SvgIcon iconClass="folder" fontSize="12" /><span className="pi-mg-left-2">{text}</span></div>
  53. } else {
  54. return <div><span style={{ color: '#6c757d', marginRight: '.5rem' }}>{record.isEnd ? '└' : '├'}</span>
  55. <Link to={{ pathname: '/console/contract/content/summary', state: { id: record.bidsectionId } }}>{text}</Link>
  56. </div>
  57. }
  58. }
  59. },
  60. {
  61. title: '合同总数',
  62. dataIndex: 'contracts',
  63. key: 'contracts',
  64. width: '12%',
  65. align: 'right'
  66. },
  67. {
  68. title: '收入合同金额',
  69. dataIndex: 'contractsIncome',
  70. key: 'contractsIncome',
  71. width: '18%',
  72. align: 'right'
  73. },
  74. {
  75. title: '回款进度',
  76. dataIndex: 'contractsIncomeProgress',
  77. key: 'contractsIncomeProgress',
  78. width: '12%',
  79. align: 'center'
  80. },
  81. {
  82. title: '支出合同金额',
  83. dataIndex: 'contractsPay',
  84. key: 'contractsPay',
  85. width: '18%',
  86. align: 'right'
  87. },
  88. {
  89. title: '支付进度',
  90. dataIndex: 'contractsPayProgress',
  91. key: 'contractsPayProgress',
  92. width: '12%',
  93. align: 'center'
  94. }
  95. ]
  96. const handleMenuClick = ({ key }: any) => {
  97. message.info(`Click on item ${key}`)
  98. }
  99. const menu = (
  100. <Menu onClick={handleMenuClick}>
  101. <Menu.Item key="1">展开所有</Menu.Item>
  102. <Menu.Item key="2">收起所有</Menu.Item>
  103. </Menu>
  104. )
  105. useActivate(() => {
  106. getTree()
  107. })
  108. useEffect(() => {
  109. getTree()
  110. }, [])
  111. return (
  112. <div className="list-content">
  113. <Header>
  114. <Slot>
  115. <Dropdown overlay={menu}>
  116. <Button type="text" size="small" className={styles.textBtn}>展开/收起<CaretDownOutlined /></Button>
  117. </Dropdown>
  118. </Slot>
  119. </Header>
  120. <div className={styles.tableContent}>
  121. <Table<ContractTree>
  122. columns={columns}
  123. dataSource={tree.children}
  124. pagination={false}
  125. rowKey={record => record.id}
  126. indentSize={20}
  127. bordered
  128. >
  129. </Table>
  130. </div>
  131. </div>
  132. )
  133. }
  134. export default List