index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 { useContractTree, useTableExpand } from '@/utils/common/customHooks'
  9. import { Button, Dropdown, Menu, Table } from 'antd'
  10. import { ColumnsType } from 'antd/lib/table'
  11. import React, { useState, useEffect } from 'react'
  12. import { useAliveController } from 'react-activation'
  13. import { RouteComponentProps, withRouter } from 'react-router-dom'
  14. import styles from './index.module.scss'
  15. import { apiContractList } from '@/utils/common/api'
  16. import { handleIntoBidsection } from '@/utils/util'
  17. const List: React.FC<RouteComponentProps> = props => {
  18. const { clear } = useAliveController()
  19. const [ loading, setLoading ] = useState<boolean>(false)
  20. useEffect(() => {
  21. // 清除所有的缓存页面
  22. clear()
  23. getTree()
  24. }, [])
  25. const getTree = async () => {
  26. setLoading(true)
  27. const { data, code = -1 } = await apiContractList(consts.BIDSECTION_TYPE.CONTRACT)
  28. if (code === consts.RET_CODE.SUCCESS) {
  29. setTree(data)
  30. setLoading(false)
  31. }
  32. }
  33. const [ tree, setTree ] = useContractTree()
  34. const [ expandedRowKeys, setRowKeys ] = useTableExpand(tree)
  35. const handleLinkClick = (id: string, name: string) => {
  36. tenderStore.saveTenderInfo({ bidsectionId: id, name })
  37. const hasPermission = handleIntoBidsection("contract")
  38. if (hasPermission) {
  39. props.history.push('/console/contract/content/summary')
  40. }
  41. }
  42. const columns: ColumnsType<ContractTree> = [
  43. {
  44. title: '名称',
  45. dataIndex: 'name',
  46. key: 'name',
  47. width: '25%',
  48. render: (text: string, record: ContractTree) => {
  49. if (record.isfolder) {
  50. return (
  51. <div className="pi-vertical-baseline">
  52. <SvgIcon type={record.hasFolder ? 'xxh-folder-open' : 'xxh-folder'} />
  53. <span className="pi-mg-left-2">{text}</span>
  54. </div>
  55. )
  56. } else {
  57. return (
  58. <div>
  59. <span className="expandIcon">{record.isEnd ? '└' : '├'}</span>
  60. <span className="pi-link-blue" onClick={() => handleLinkClick(record.bidsectionId, record.name)}>
  61. {text}
  62. </span>
  63. </div>
  64. )
  65. }
  66. }
  67. },
  68. {
  69. title: '合同总数',
  70. dataIndex: 'contracts',
  71. key: 'contracts',
  72. width: '12%',
  73. align: 'right'
  74. },
  75. {
  76. title: '收入合同金额',
  77. dataIndex: 'contractsIncome',
  78. key: 'contractsIncome',
  79. width: '18%',
  80. align: 'right'
  81. },
  82. {
  83. title: '回款进度',
  84. dataIndex: 'contractsIncomeProgress',
  85. key: 'contractsIncomeProgress',
  86. width: '12%',
  87. align: 'center'
  88. },
  89. {
  90. title: '支出合同金额',
  91. dataIndex: 'contractsPay',
  92. key: 'contractsPay',
  93. width: '18%',
  94. align: 'right'
  95. },
  96. {
  97. title: '支付进度',
  98. dataIndex: 'contractsPayProgress',
  99. key: 'contractsPayProgress',
  100. width: '12%',
  101. align: 'center'
  102. }
  103. ]
  104. const handleMenuClick = ({ key }: any) => {
  105. if (key === 'expanded') {
  106. setRowKeys(true)
  107. } else {
  108. setRowKeys(false)
  109. }
  110. }
  111. const menu = (
  112. <Menu onClick={handleMenuClick}>
  113. <Menu.Item key="expanded">展开所有</Menu.Item>
  114. <Menu.Item key="collapsed">收起所有</Menu.Item>
  115. </Menu>
  116. )
  117. return (
  118. <div className="wrap-contaniner hide-menu pi-bg-white">
  119. <Header>
  120. <Slot>
  121. <Dropdown overlay={menu}>
  122. <Button type="text" size="small" className={styles.textBtn}>
  123. 展开/收起
  124. <CaretDownOutlined />
  125. </Button>
  126. </Dropdown>
  127. </Slot>
  128. </Header>
  129. <div className={styles.tableContent}>
  130. <Table<ContractTree>
  131. columns={columns}
  132. loading={loading}
  133. dataSource={tree.children}
  134. pagination={false}
  135. rowKey={record => record.id}
  136. indentSize={20}
  137. expandable={{ expandedRowKeys, onExpand: setRowKeys }}
  138. bordered></Table>
  139. </div>
  140. </div>
  141. )
  142. }
  143. export default withRouter(List)