index.tsx 4.7 KB

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