index.tsx 3.6 KB

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