index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { MediaPromotionDayProps, getMediaPitcherDayListApi, getMediaPitcherTotalApi } from "@/services/gameData/medium"
  3. import React, { useEffect, useState } from "react"
  4. import moment from 'moment'
  5. import columns12 from "./tableConfig"
  6. import { getPresets } from "@/components/QueryForm/const"
  7. import QueryForm from "@/components/QueryForm"
  8. import TableData from "../../components/TableData"
  9. /**
  10. * 投手推广每日数据
  11. * @returns
  12. */
  13. const PitcherEvery: React.FC = () => {
  14. /*****************************/
  15. const [queryForm, setQueryForm] = useState<MediaPromotionDayProps>({
  16. pageNum: 1, pageSize: 50,
  17. sourceSystem: 'ZX_ONE',
  18. beginDate: moment().format('YYYY-MM-DD'), //subtract(30, 'd').
  19. endDate: moment().format('YYYY-MM-DD')
  20. })
  21. const [totalData, setTotalData] = useState<any[]>([])
  22. const getMediaPitcherDayList = useAjax((params) => getMediaPitcherDayListApi(params))
  23. const getMediaPitcherTotal = useAjax((params) => getMediaPitcherTotalApi(params))
  24. /*****************************/
  25. useEffect(() => {
  26. getMediaPitcherDayList.run(queryForm)
  27. getMediaPitcherTotal.run(queryForm).then((res: { id: number; pitcher: string, beginDay?: string }) => {
  28. res.id = 1
  29. res.pitcher = '总计'
  30. res.beginDay = queryForm.beginDate
  31. setTotalData([res])
  32. })
  33. }, [queryForm])
  34. return <div>
  35. <TableData
  36. leftChild={<QueryForm
  37. initialValues={{ consumeDay: [moment(), moment()], sourceSystem: 'ZX_ONE' }}
  38. onChange={(data: any) => {
  39. console.log(data)
  40. const { costBeginDay, costEndDay, type, ...params } = data
  41. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  42. newQueryForm.pageNum = 1
  43. newQueryForm.accountType = type
  44. if (costBeginDay && costEndDay) {
  45. newQueryForm.beginDate = costBeginDay
  46. newQueryForm.endDate = costEndDay
  47. } else {
  48. delete newQueryForm.beginDate
  49. delete newQueryForm.endDate
  50. }
  51. setQueryForm({ ...newQueryForm, ...params })
  52. }}
  53. isSource
  54. isConsumeDay={{ ranges: getPresets() }}
  55. isSysUserId
  56. isType
  57. />}
  58. isZj
  59. totalData={totalData}
  60. scroll={{ x: 1000, y: 600 }}
  61. ajax={getMediaPitcherDayList}
  62. fixed={{ left: 2, right: 1 }}
  63. dataSource={getMediaPitcherDayList?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + index.toString()) }))}
  64. total={getMediaPitcherDayList?.data?.total}
  65. page={queryForm.pageNum}
  66. pageSize={queryForm.pageSize}
  67. sortData={{
  68. field: queryForm?.sortFiled,
  69. order: queryForm?.sortType === 'asc' ? 'ascend' : 'descend'
  70. }}
  71. title={`投手推广每日数据`}
  72. onChange={(props: any) => {
  73. let { pagination, sortData } = props
  74. let { current, pageSize } = pagination
  75. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  76. if (sortData && sortData?.order) {
  77. newQueryForm['sortType'] = sortData?.order === 'ascend' ? 'asc' : 'desc'
  78. newQueryForm['sortFiled'] = sortData?.field
  79. } else {
  80. delete newQueryForm['sortType']
  81. delete newQueryForm['sortFiled']
  82. }
  83. newQueryForm.pageNum = current
  84. newQueryForm.pageSize = pageSize
  85. setQueryForm({ ...newQueryForm })
  86. }}
  87. config={columns12()}
  88. configName={'投手推广每日数据'}
  89. />
  90. </div>
  91. }
  92. export default PitcherEvery