index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 { useAutoTable, 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 styles from './index.module.scss'
  14. import { apiContractList } from '@/utils/common/api'
  15. import { formatMoney, handleIntoBidsection } from '@/utils/util'
  16. const List: React.FC<{}> = () => {
  17. const needSubtractHeight = 34 + 32
  18. const [ y ] = useAutoTable(needSubtractHeight)
  19. const { clear } = useAliveController()
  20. const [ loading, setLoading ] = useState<boolean>(false)
  21. useEffect(() => {
  22. // 清除所有的缓存页面
  23. clear()
  24. getTree()
  25. }, [])
  26. const getTree = async () => {
  27. setLoading(true)
  28. const { data, code = -1 } = await apiContractList(consts.BIDSECTION_TYPE.CONTRACT)
  29. if (code === consts.RET_CODE.SUCCESS) {
  30. setTree(data)
  31. setLoading(false)
  32. }
  33. }
  34. const [ tree, setTree ] = useContractTree()
  35. const [ expandedRowKeys, setRowKeys ] = useTableExpand(tree)
  36. const handleLinkClick = (id: string, name: string) => {
  37. tenderStore.saveTenderInfo({ bidsectionId: id, name })
  38. handleIntoBidsection("contract", id)
  39. }
  40. const columns: ColumnsType<ContractTree> = [
  41. {
  42. title: '名称',
  43. dataIndex: 'name',
  44. key: 'name',
  45. width: '25%',
  46. render: (text: string, record: ContractTree) => {
  47. if (record.isfolder) {
  48. return (
  49. <div className="pi-vertical-baseline">
  50. <SvgIcon type={record.hasFolder ? 'xxh-folder-open' : 'xxh-folder'} />
  51. <span className="pi-mg-left-2">{text}</span>
  52. </div>
  53. )
  54. } else {
  55. return (
  56. <div>
  57. <span className="expandIcon">{record.isEnd ? '└' : '├'}</span>
  58. <span className="pi-link-blue" onClick={() => handleLinkClick(record.bidsectionId, record.name)}>
  59. {text}
  60. </span>
  61. </div>
  62. )
  63. }
  64. }
  65. },
  66. {
  67. title: '合同总数',
  68. dataIndex: 'contracts',
  69. key: 'contracts',
  70. width: '12%',
  71. align: 'right'
  72. },
  73. {
  74. title: '收入合同金额',
  75. dataIndex: 'contractsIncome',
  76. key: 'contractsIncome',
  77. width: '18%',
  78. align: 'right',
  79. // eslint-disable-next-line react/display-name
  80. render: (text: number) => <span>{formatMoney(text)}</span>
  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, 'wrap-content' ].join(' ')}>
  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. scroll={{ y }}
  138. expandable={{ expandedRowKeys, onExpand: setRowKeys }}
  139. bordered />
  140. </div>
  141. </div>
  142. )
  143. }
  144. export default List