LeaderBoard.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import ProTable from '@ant-design/pro-table'
  2. import { Select, Card } from 'antd'
  3. import Iconfont from '@/components/SvgIcon'
  4. import React, { useState, useMemo } from 'react'
  5. const { Option } = Select
  6. const opMap = {
  7. customer: '新增单位',
  8. customerService: '单位服务',
  9. client: '新增客户',
  10. clientService: '客户服务',
  11. business: '新增商机',
  12. businessService: '商机服务'
  13. }
  14. const colorMap = {
  15. 1: 'text-hex-ffc241',
  16. 2: 'text-hex-1dc9b7',
  17. 3: 'text-hex-868e96'
  18. }
  19. const LeaderBoard = ({ loading = false, dataList = [] }) => {
  20. const [activeOp, setActiveOp] = useState('customer')
  21. const columns = useMemo(() => {
  22. const oColumns = [
  23. {
  24. title: '排名',
  25. dataIndex: 'rank',
  26. align: 'center',
  27. width: '30%',
  28. render: (_, record) =>
  29. record.rank <= 3 ? <Iconfont type="icon-trophy" className={colorMap[record.rank]} /> : ''
  30. },
  31. {
  32. title: '姓名',
  33. dataIndex: `${activeOp}Name`,
  34. align: 'center',
  35. width: '40%'
  36. },
  37. {
  38. title: '新增单位数',
  39. dataIndex: 'customer',
  40. align: 'center',
  41. width: '30%'
  42. },
  43. {
  44. title: '单位服务',
  45. dataIndex: 'customerService',
  46. align: 'center',
  47. width: '30%'
  48. },
  49. {
  50. title: '新增客户',
  51. dataIndex: 'client',
  52. align: 'center',
  53. width: '30%'
  54. },
  55. {
  56. title: '客户服务',
  57. dataIndex: 'clientService',
  58. align: 'center',
  59. width: '30%'
  60. },
  61. {
  62. title: '新增商机',
  63. dataIndex: 'business',
  64. align: 'center',
  65. width: '30%'
  66. },
  67. {
  68. title: '商机服务',
  69. dataIndex: 'businessService',
  70. align: 'center',
  71. width: '30%'
  72. }
  73. ]
  74. let stop = false
  75. const bColumns = oColumns.reduce((prev, curr, idx) => {
  76. if (idx < 2) {
  77. prev.push(curr)
  78. return prev
  79. }
  80. if (!stop && curr.dataIndex.startsWith(activeOp)) {
  81. stop = true
  82. prev.push(curr)
  83. return prev
  84. }
  85. return prev
  86. }, [])
  87. return bColumns
  88. }, [activeOp])
  89. return (
  90. <Card
  91. loading={loading}
  92. bodyStyle={{ padding: loading ? '24px' : 0 }}
  93. className="shadow-card"
  94. title={
  95. <div className="px-4 pt-2 pb-0 flex items-center justify-between">
  96. <span>排行榜</span>
  97. <Select defaultValue="client" onChange={e => setActiveOp(e)}>
  98. <Option value="client">新增客户</Option>
  99. <Option value="clientService">客户服务</Option>
  100. <Option value="customer">新增单位</Option>
  101. <Option value="customerService">单位服务</Option>
  102. <Option value="business">新增商机</Option>
  103. <Option value="businessService">商机服务</Option>
  104. {/* <Option value="开票金额">开票金额</Option>
  105. <Option value="回款金额">回款金额</Option> */}
  106. </Select>
  107. </div>
  108. }>
  109. <div className="text-center border border-x-0 p-2">{opMap[activeOp]}排行榜</div>
  110. <ProTable
  111. border={true}
  112. rowKey={record => record.rank}
  113. columns={columns}
  114. dataSource={dataList}
  115. search={false}
  116. size="small"
  117. toolBarRender={false}
  118. pagination={false}
  119. />
  120. </Card>
  121. )
  122. }
  123. export default LeaderBoard