index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import Header from '@/components/Header'
  2. import { useAutoTable, useContractTree, useTableExpand } from '@/utils/common/customHooks'
  3. import Slot from '@/components/Header/slot'
  4. import SvgIcon from '@/components/SvgIcon'
  5. import { tenderStore } from '@/store/mobx'
  6. import { ContractListTree } from '@/types/contract'
  7. import consts from '@/utils/consts'
  8. import { CaretDownOutlined } from '@ant-design/icons'
  9. import { Button, Dropdown, Menu, Table } from 'antd'
  10. import { ColumnsType } from 'antd/lib/table'
  11. import React, { useEffect, useState } from 'react'
  12. import { RouteComponentProps, withRouter } from 'react-router-dom'
  13. import styles from './index.module.scss'
  14. import { apiContractList } from '@/utils/common/api'
  15. import { handleIntoBidsection } from '@/utils/util'
  16. const List: React.FC<RouteComponentProps> = () => {
  17. const [ y ] = useAutoTable(66)
  18. const [ loading, setLoading ] = useState<boolean>(false)
  19. useEffect(() => {
  20. // 清除所有的缓存页面
  21. getTree()
  22. }, [])
  23. const getTree = async () => {
  24. setLoading(true)
  25. const { data, code = -1 } = await apiContractList(consts.BIDSECTION_TYPE.SAFE)
  26. if (code === consts.RET_CODE.SUCCESS) {
  27. setTree(data)
  28. setLoading(false)
  29. }
  30. }
  31. const [ tree, setTree ] = useContractTree()
  32. const [ expandedRowKeys, setRowKeys ] = useTableExpand(tree.children)
  33. const handleLinkClick = (id: string, name: string) => {
  34. tenderStore.saveTenderInfo({ bidsectionId: id, name })
  35. handleIntoBidsection("safe", id, name)
  36. }
  37. const columns: ColumnsType<ContractListTree> = [
  38. {
  39. title: '名称',
  40. dataIndex: 'name',
  41. key: 'name',
  42. width: '40%',
  43. render: (text: string, record: ContractListTree) => {
  44. if (record.isfolder) {
  45. return (
  46. <div className="pi-vertical-baseline">
  47. <SvgIcon type={record.hasFolder ? 'xxh-folder-open' : 'xxh-folder'} />
  48. <span className="pi-mg-left-2">{text}</span>
  49. </div>
  50. )
  51. } else {
  52. return (
  53. <div>
  54. <span className="expandIcon">{record.isEnd ? '└' : '├'}</span>
  55. <span className="pi-link-blue" onClick={() => handleLinkClick(record.bidsectionId, record.name)}>
  56. {text}
  57. </span>
  58. </div>
  59. )
  60. }
  61. }
  62. },
  63. {
  64. title: '总数',
  65. dataIndex: 'safeTotal',
  66. key: 'safeTotal'
  67. },
  68. {
  69. title: '待整改',
  70. dataIndex: 'safeRectification',
  71. key: 'safeRectification'
  72. },
  73. {
  74. title: '整改中',
  75. dataIndex: 'safeRectificationIn',
  76. key: 'safeRectificationIn'
  77. },
  78. {
  79. title: '已整改',
  80. dataIndex: 'safeRectificationFinish',
  81. key: 'safeRectificationFinish'
  82. }
  83. ]
  84. const handleMenuClick = ({ key }: any) => {
  85. if (key === 'expanded') {
  86. setRowKeys(true)
  87. } else {
  88. setRowKeys(false)
  89. }
  90. }
  91. const menu = (
  92. <Menu onClick={handleMenuClick}>
  93. <Menu.Item key="expanded">展开所有</Menu.Item>
  94. <Menu.Item key="collapsed">收起所有</Menu.Item>
  95. </Menu>
  96. )
  97. return (
  98. <div className="wrap-contaniner hide-menu pi-bg-white">
  99. <Header>
  100. <Slot>
  101. <Dropdown overlay={menu}>
  102. <Button type="text" size="small" className={styles.textBtn}>
  103. 展开/收起
  104. <CaretDownOutlined />
  105. </Button>
  106. </Dropdown>
  107. </Slot>
  108. </Header>
  109. <div className={[ styles.tableContent, 'wrap-content' ].join(' ')}>
  110. <Table<ContractListTree>
  111. columns={columns}
  112. loading={loading}
  113. dataSource={tree.children}
  114. pagination={false}
  115. rowKey={record => record.id}
  116. indentSize={20}
  117. scroll={{ y }}
  118. expandable={{ expandedRowKeys, onExpand: setRowKeys }}
  119. bordered />
  120. </div>
  121. </div>
  122. )
  123. }
  124. export default withRouter(List)