index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import Header from '@/components/Header'
  2. import Slot from '@/components/Header/slot'
  3. import SvgIcon from '@/components/SvgIcon'
  4. import { tenderStore } from '@/store/mobx'
  5. import { ContractTree } from '@/types/contract'
  6. import consts from '@/utils/consts'
  7. import { CaretDownOutlined } from '@ant-design/icons'
  8. import { Button, Dropdown, Menu, message, Table } from 'antd'
  9. import { ColumnsType } from 'antd/lib/table'
  10. import React, { useEffect, useState } from 'react'
  11. import { useAliveController } from 'react-activation'
  12. import { RouteComponentProps, withRouter } 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> = (props) => {
  17. const { clear } = useAliveController()
  18. useEffect(() => {
  19. // 清除所有的缓存页面
  20. clear()
  21. getTree()
  22. }, [])
  23. const [ tree, setTree ] = useState({
  24. bidsectionId: '',
  25. children: [],
  26. childsTotal: 0,
  27. contracts: 0,
  28. contractsIncome: '',
  29. contractsIncomeProgress: '',
  30. contractsPaid: '',
  31. contractsPay: '',
  32. contractsPayProgress: '',
  33. contractsReturned: '',
  34. csrf: '',
  35. hasFolder: false,
  36. id: '',
  37. isBid: false,
  38. isEnd: false,
  39. isfolder: 0,
  40. name: '',
  41. parentId: '',
  42. projectId: '',
  43. qualityRectificationIn: 0,
  44. qualityTotal: 0,
  45. safeRectification: 0,
  46. safeRectificationIn: 0,
  47. safeTotal: 0,
  48. qualityRectification: 0
  49. })
  50. const getTree = async () => {
  51. const { data, code = -1 } = await apiContractList()
  52. if (code === consts.RET_CODE.SUCCESS) {
  53. setTree(data)
  54. }
  55. }
  56. const linkHandler = (id: string, name: string) => {
  57. tenderStore.saveTenderInfo({ bidsectionId: id, name })
  58. props.history.push('/console/safe/content/summary')
  59. }
  60. const columns:ColumnsType<ContractTree> = [
  61. {
  62. title: '名称',
  63. dataIndex: 'name',
  64. key: 'name',
  65. width: '40%',
  66. render: (text: string, record: ContractTree) => {
  67. if (record.isfolder) {
  68. return <div style={{ verticalAlign: "baseline" }}><SvgIcon type={record.hasFolder ? "xxh-folder-open" : "xxh-folder"} /><span className="pi-mg-left-2">{text}</span></div>
  69. } else {
  70. return <div><span style={{ color: '#6c757d', marginRight: '.5rem' }}>{record.isEnd ? '└' : '├'}</span>
  71. {/* <Link to={{ pathname: '/console/safe/content/summary', search: `?bid=${record.id}` }}>{text}</Link> */}
  72. <span className="pi-link-blue" onClick={() => linkHandler(record.bidsectionId, record.name)}>{text}</span>
  73. </div>
  74. }
  75. }
  76. },
  77. {
  78. title: '总数',
  79. dataIndex: 'safeTotal',
  80. key: 'safeTotal'
  81. },
  82. {
  83. title: '待整改',
  84. dataIndex: 'safe_rectification',
  85. key: 'safe_rectification'
  86. },
  87. {
  88. title: '整改中',
  89. dataIndex: 'safe_rectification_in',
  90. key: 'safe_rectification_in'
  91. },
  92. {
  93. title: '已整改',
  94. dataIndex: 'safe_rectification_finish',
  95. key: 'safe_rectification_finish'
  96. }
  97. ]
  98. const handleMenuClick = ({ key }: any) => {
  99. message.info(`Click on item ${key}`)
  100. }
  101. const menu = (
  102. <Menu onClick={handleMenuClick}>
  103. <Menu.Item key="1">展开所有</Menu.Item>
  104. <Menu.Item key="2">收起所有</Menu.Item>
  105. </Menu>
  106. )
  107. return (
  108. <div className="list-content">
  109. <Header>
  110. <Slot>
  111. <Dropdown overlay={menu}>
  112. <Button type="text" size="small" className={styles.textBtn}>展开/收起<CaretDownOutlined /></Button>
  113. </Dropdown>
  114. </Slot>
  115. </Header>
  116. <div className={styles.tableContent}>
  117. <Table<ContractTree>
  118. columns={columns}
  119. dataSource={tree.children}
  120. pagination={false}
  121. rowKey={record => record.id}
  122. indentSize={20}
  123. bordered
  124. >
  125. </Table>
  126. </div>
  127. </div>
  128. )
  129. }
  130. export default withRouter(List)