index.tsx 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { GameRechargeListType, getRechargeGameListApi } from "@/services/gameData/rankingList"
  3. import React, { useEffect, useState } from "react"
  4. import TableData from "../../components/TableData"
  5. import columns12 from "./tableConfig"
  6. import moment from "moment"
  7. import QueryForm from "@/components/QueryForm"
  8. import { getPresetsRanking } from "@/components/QueryForm/const"
  9. import { getGameChoiceParentListType1Api } from "@/services/gameData"
  10. const Game: React.FC = () => {
  11. /************************/
  12. const [queryForm, setQueryForm] = useState<GameRechargeListType>({ pageNum: 1, pageSize: 100, sourceSystem: 'ZX_ONE', beginDay: moment().format('YYYY-MM-DD'), endDay: moment().format('YYYY-MM-DD') })
  13. const [gameType, setGameType] = useState<any>({})
  14. const getRechargeGameList = useAjax((params) => getRechargeGameListApi(params))
  15. const getGameChoiceParentListType1 = useAjax(() => getGameChoiceParentListType1Api())
  16. /************************/
  17. useEffect(() => {
  18. getRechargeGameList.run(queryForm)
  19. }, [queryForm])
  20. useEffect(() => {
  21. getGameChoiceParentListType1.run().then((res: { id: number; name: string }[]) => {
  22. let newType: any = {}
  23. res.forEach((item: { id: number, name: string }) => {
  24. newType[item.id] = item.name
  25. })
  26. setGameType(newType)
  27. })
  28. }, [])
  29. return <div>
  30. <TableData
  31. leftChild={<QueryForm
  32. initialValues={{ sourceSystem: 'ZX_ONE', rechargeDay: [moment(), moment()] }}
  33. onChange={(data: any) => {
  34. console.log(data)
  35. const { rechargeDay, beginDay, endDay, ...par } = data
  36. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  37. newQueryForm.pageNum = 1
  38. if (rechargeDay && rechargeDay?.length === 2) {
  39. newQueryForm['beginDay'] = moment(rechargeDay[0]).format('YYYY-MM-DD')
  40. newQueryForm['endDay'] = moment(rechargeDay[1]).format('YYYY-MM-DD')
  41. } else {
  42. if (beginDay && endDay) {
  43. newQueryForm['beginDay'] = beginDay
  44. newQueryForm['endDay'] = endDay
  45. } else {
  46. delete newQueryForm['beginDay']
  47. delete newQueryForm['endDay']
  48. }
  49. }
  50. setQueryForm({ ...newQueryForm, ...par })
  51. }}
  52. isSource
  53. rechargeDay={{ ranges: getPresetsRanking() }}
  54. />}
  55. scroll={{ x: 1200, y: 600 }}
  56. ajax={getRechargeGameList}
  57. fixed={{ left: 1, right: 0 }}
  58. dataSource={getRechargeGameList?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + index.toString()) }))}
  59. page={getRechargeGameList?.data?.current || 1}
  60. pageSize={getRechargeGameList?.data?.size || 20}
  61. total={getRechargeGameList?.data?.total || 0}
  62. title='游戏充值排行榜(T+1)'
  63. onChange={(props: any) => {
  64. console.log('props--->', props)
  65. let { pagination, sortData } = props
  66. let { current, pageSize } = pagination
  67. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  68. if (sortData && sortData?.order) {
  69. newQueryForm['sortType'] = sortData?.order === 'ascend' ? 'asc' : 'desc'
  70. newQueryForm['sortFiled'] = sortData?.field
  71. } else {
  72. delete newQueryForm['sortType']
  73. delete newQueryForm['sortFiled']
  74. }
  75. newQueryForm.pageNum = current
  76. newQueryForm.pageSize = pageSize
  77. setQueryForm({ ...newQueryForm })
  78. }}
  79. config={columns12(gameType)}
  80. configName={'游戏充值排行榜'}
  81. />
  82. </div>
  83. }
  84. export default Game