index.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import QueryForm from "@/components/QueryForm";
  2. import TablePro from "@/components/TablePro";
  3. import React, { useEffect, useState } from "react"
  4. import moment from "moment";
  5. import { useModel } from "umi";
  6. import { useAjax } from "@/Hook/useAjax";
  7. import columns12 from "./tableConfig";
  8. import { GetByteAppTrendRoiListApi, getByteAppTrendRoiListApi, getByteAppTrendRoiTotalApi } from "@/services/iaaData";
  9. /**
  10. * 应用变现趋势-ROI
  11. * @returns
  12. */
  13. const AppCashTrendRoi: React.FC = () => {
  14. /****************************************/
  15. const { initialState } = useModel('@@initialState');
  16. const [queryForm, setQueryForm] = useState<GetByteAppTrendRoiListApi>({
  17. pageNum: 1,
  18. pageSize: 30,
  19. costDayBegin: moment().format('YYYY-MM-DD'),
  20. costDayEnd: moment().format('YYYY-MM-DD'),
  21. })
  22. const [totalData, setTotalData] = useState<any[]>([])
  23. const getByteAppTrendRoiList = useAjax((params) => getByteAppTrendRoiListApi(params))
  24. const getByteAppTrendRoiTotal = useAjax((params) => getByteAppTrendRoiTotalApi(params))
  25. /****************************************/
  26. useEffect(() => {
  27. if (initialState?.iaaApp?.length && initialState?.productType) {
  28. getByteAppTrendRoiList.run({ ...queryForm, appId: initialState.iaaApp, productType: initialState.productType })
  29. getByteAppTrendRoiTotal.run({ ...queryForm, appId: initialState.iaaApp, productType: initialState.productType }).then((res: { data: { id: number; appName: string, costDayBegin: string } }) => {
  30. if (res?.data) {
  31. let data = res?.data
  32. data.id = 1
  33. data.costDayBegin = queryForm.costDayBegin || moment().format('YYYY-MM-DD')
  34. data.appName = '总计'
  35. setTotalData([data])
  36. } else {
  37. setTotalData([{ id: 1, appName: '总计' }])
  38. }
  39. })
  40. } else {
  41. setTotalData([{ id: 1, appName: '总计' }])
  42. getByteAppTrendRoiList.mutate({ data: undefined })
  43. }
  44. }, [queryForm, initialState?.iaaApp, initialState?.productType])
  45. return <div>
  46. <TablePro
  47. leftChild={<QueryForm
  48. initialValues={{ day1: [moment(), moment()] }}
  49. day1={{ placeholder: ['消耗日期开始', '消耗日期结束'] }}
  50. onChange={(data: any) => {
  51. console.log(data)
  52. const { day1, ...params } = data
  53. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  54. newQueryForm.pageNum = 1
  55. if (day1 && day1?.length === 2) {
  56. newQueryForm['costDayBegin'] = moment(day1[0]).format('YYYY-MM-DD')
  57. newQueryForm['costDayEnd'] = moment(day1[1]).format('YYYY-MM-DD')
  58. } else {
  59. delete newQueryForm['costDayBegin']
  60. delete newQueryForm['costDayEnd']
  61. }
  62. setQueryForm({ ...newQueryForm, ...params })
  63. }}
  64. />}
  65. isZj
  66. totalData={totalData}
  67. config={columns12()}
  68. configName={'头条应用变现趋势ROI'}
  69. fixed={{ left: 4, right: 0 }}
  70. scroll={{ x: 1000, y: 620 }}
  71. title='应用变现趋势-ROI'
  72. loading={getByteAppTrendRoiList.loading}
  73. ajax={getByteAppTrendRoiList}
  74. page={getByteAppTrendRoiList?.data?.data?.current || 1}
  75. pageSize={getByteAppTrendRoiList?.data?.data?.size || 20}
  76. total={getByteAppTrendRoiList?.data?.data?.total || 0}
  77. dataSource={getByteAppTrendRoiList?.data?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + (index + '')) }))}
  78. onChange={(pagination: any, _: any, sortData: any) => {
  79. let { current, pageSize } = pagination
  80. let newQueryForm = JSON.parse(JSON.stringify(queryForm))
  81. if (sortData && sortData?.order) {
  82. newQueryForm['sortAsc'] = sortData?.order === 'ascend' ? true : false
  83. newQueryForm['sortFiled'] = sortData?.field
  84. } else {
  85. delete newQueryForm['sortAsc']
  86. delete newQueryForm['sortFiled']
  87. }
  88. newQueryForm.pageNum = current || newQueryForm.pageNum
  89. newQueryForm.pageSize = pageSize || newQueryForm.pageSize
  90. setQueryForm({ ...newQueryForm })
  91. }}
  92. />
  93. </div>
  94. }
  95. export default AppCashTrendRoi