tableConfig.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { Statistic } from 'antd'
  2. import { ColumnsType } from 'antd/lib/table'
  3. import React from 'react'
  4. import '../index.less'
  5. function columns() {
  6. let arr: ColumnsType<any> = Array(12).fill('').map((i: string, index: number) => {
  7. return {
  8. title: `${index + 1}月(总消耗)`,
  9. align: 'center',
  10. key: `${index + 1}`,
  11. dataIndex: `${index + 1}_ten`,
  12. children: [
  13. {
  14. title: '10:00',
  15. align: 'center',
  16. key: `${index + 1}_ten_01`,
  17. dataIndex: `${index + 1}_ten_01`,
  18. children: [
  19. {
  20. title: '充值',
  21. dataIndex: `${index + 1}_ten_amount`,
  22. key: `${index + 1}_ten_amount`,
  23. align: 'center',
  24. width: 85,
  25. render: (a: any) => {
  26. return <Statistic value={a ? (a as number).toFixed(2) : a === 0 ? 0 : '--'} />
  27. }
  28. },
  29. {
  30. title: '环比',
  31. dataIndex: `${index + 1}_ten_rate`,
  32. key: `${index + 1}_ten_rate`,
  33. width: 85,
  34. align: 'center',
  35. className: 'ringRatio',
  36. render: (a: any) => {
  37. return a === 999999999 ? <div>--</div> : a ?
  38. <div style={a <= 0.25 ? { backgroundColor: '#b9e19e' } : {}}>{(a * 100).toFixed(2) + '%'}</div>
  39. : a === 0 ?
  40. <div style={a <= 0.25 ? { backgroundColor: '#b9e19e' } : {}}>0</div>
  41. : <div>--</div>
  42. }
  43. },
  44. ]
  45. },
  46. {
  47. title: '14:00',
  48. align: 'center',
  49. key: `${index + 1}_ten_02`,
  50. dataIndex: `${index + 1}_ten_02`,
  51. children: [
  52. {
  53. title: '充值',
  54. dataIndex: `${index + 1}_fourteen_amount`,
  55. key: `${index + 1}_fourteen_amount`,
  56. align: 'center',
  57. width: 85,
  58. render: (a: any) => {
  59. return <Statistic value={a ? (a as number).toFixed(2) : a === 0 ? 0 : '--'} />
  60. }
  61. },
  62. {
  63. title: '环比',
  64. dataIndex: `${index + 1}_fourteen_rate`,
  65. key: `${index + 1}_fourteen_rate`,
  66. width: 85,
  67. align: 'center',
  68. className: 'ringRatio',
  69. render: (a: any) => {
  70. return a === 999999999 ? <div>--</div> : a ?
  71. <div style={a <= 0.45 ? { backgroundColor: '#b9e19e' } : {}}>{(a * 100).toFixed(2) + '%'}</div>
  72. : a === 0 ? <div style={a <= 0.45 ? { backgroundColor: '#b9e19e' } : {}}>0</div>
  73. : <div>--</div>
  74. }
  75. },
  76. ]
  77. },
  78. {
  79. title: '17:00',
  80. align: 'center',
  81. key: `${index + 1}_ten_03`,
  82. dataIndex: `${index + 1}_ten_03`,
  83. children: [
  84. {
  85. title: '充值',
  86. dataIndex: `${index + 1}_eighteen_amount`,
  87. key: `${index + 1}_eighteen_amount`,
  88. align: 'center',
  89. width: 85,
  90. render: (a: any) => {
  91. return <Statistic value={a ? (a as number).toFixed(2) : a === 0 ? 0 : '--'} />
  92. }
  93. },
  94. {
  95. title: '环比',
  96. dataIndex: `${index + 1}_eighteen_rate`,
  97. key: `${index + 1}_eighteen_rate`,
  98. width: 85,
  99. align: 'center',
  100. className: 'ringRatio',
  101. render: (a: any) => {
  102. return a === 999999999 ? <div>--</div> : a ?
  103. <div style={a <= 0.6 ? { backgroundColor: '#ffbfbf' } : {}}>{a ? (a * 100).toFixed(2) + '%' : a === 0 ? 0 : '--'}</div>
  104. : a === 0 ? <div style={a <= 0.6 ? { backgroundColor: '#ffbfbf' } : {}}>0</div>
  105. : <div>--</div>
  106. }
  107. },
  108. ]
  109. },
  110. {
  111. title: '24:00',
  112. align: 'center',
  113. key: `${index + 1}_ten_04`,
  114. dataIndex: `${index + 1}_ten_04`,
  115. children: [
  116. {
  117. title: '充值',
  118. dataIndex: `${index + 1}_twentyfour_amount`,
  119. key: `${index + 1}_twentyfour_amount`,
  120. align: 'center',
  121. width: 85,
  122. render: (a: any) => {
  123. return <Statistic value={a ? (a as number).toFixed(2) : a === 0 ? 0 : '--'} />
  124. }
  125. },
  126. {
  127. title: '环比',
  128. dataIndex: `${index + 1}_twentyfour_rate`,
  129. key: `${index + 1}_twentyfour_rate`,
  130. width: 85,
  131. align: 'center',
  132. className: 'ringRatio',
  133. render: (a: any) => {
  134. return a === 999999999 ? <div>--</div> : a ?
  135. <div style={a < 1 ? { backgroundColor: '#ffbfbf' } : {}}>{a ? (a * 100).toFixed(2) + '%' : a === 0 ? 0 : '--'}</div>
  136. : a === 0 ? <div style={a < 1 ? { backgroundColor: '#ffbfbf' } : {}}>0</div>
  137. : <div>--</div>
  138. }
  139. }
  140. ]
  141. }
  142. ]
  143. }
  144. })
  145. let newArr: ColumnsType<any> = [
  146. {
  147. title: '充值日期',
  148. dataIndex: 'time',
  149. key: 'time',
  150. align: 'center',
  151. width: 90,
  152. fixed: 'left'
  153. },
  154. ...arr
  155. ]
  156. return newArr
  157. }
  158. export { columns }