index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { useEffect, useCallback, useState } from 'react'
  2. import { Button, Col, Input, message, Row } from 'antd'
  3. import { useAjax } from '@/Hook/useAjax'
  4. import { getAdqLandingPageList, putAdqLandingPage } from '@/services/launchAdq/adq'
  5. import TableData from '../../components/TableData'
  6. import tableConfig from './tableConfig'
  7. function LandingPage(props: { accountId: string, adAccountId: string, userId: string, tableIdClick: any }) {
  8. let { accountId, adAccountId, userId, tableIdClick } = props
  9. const listAjax = useAjax((params) => getAdqLandingPageList(params), { formatResult: true })
  10. const syncAjax = useAjax((adAccountId) => putAdqLandingPage(adAccountId))
  11. const [queryFrom, set_queryFrom] = useState<{
  12. pageNum: number;
  13. pageSize: number;
  14. accountId?: string;
  15. pageName?: string;
  16. pageType?: string;
  17. pageTemplateId?: string;
  18. pageStatus?: string;
  19. }>({ pageNum: 1, pageSize: 20 })
  20. console.log('落地页=====》')
  21. useEffect(() => {
  22. getList({ pageNum: 1, pageSize: 20 })
  23. }, [accountId])
  24. // 获取列表
  25. const getList = useCallback((params: {
  26. pageNum: number;
  27. pageSize: number;
  28. accountId?: string;
  29. pageName?: string;
  30. pageType?: string;
  31. pageTemplateId?: string;
  32. pageStatus?: string;
  33. }) => {
  34. if (!params.pageName || params.pageName !== listAjax?.params[0]?.pageName) {
  35. !params.pageName && delete params.pageName
  36. }
  37. listAjax.run({ ...params, userId })
  38. }, [listAjax, userId])
  39. // 同步
  40. const sync = useCallback(() => {
  41. if (!adAccountId) {
  42. message.error('请先选择要同步的广点通账号!')
  43. return
  44. }
  45. syncAjax.run(adAccountId).then(res => {
  46. console.log(res)
  47. res && listAjax.refresh()
  48. res ? message.success('同步成功!') : message.error('同步失败!')
  49. })
  50. }, [adAccountId, listAjax])
  51. return <div>
  52. <TableData
  53. isCard={false}
  54. columns={() => tableConfig(tableIdClick)}
  55. ajax={listAjax}
  56. syncAjax={sync}
  57. dataSource={listAjax?.data?.data?.records}
  58. loading={listAjax?.loading || syncAjax?.loading}
  59. scroll={{ y: 550 }}
  60. total={listAjax?.data?.data?.total}
  61. page={listAjax?.data?.data?.current}
  62. pageSize={listAjax?.data?.data?.size}
  63. myKey={'pageId'}
  64. leftChild={<>
  65. <Row gutter={[10, 10]}>
  66. <Col>
  67. <Input
  68. placeholder='广告账号'
  69. allowClear
  70. style={{ width: 150 }}
  71. onChange={(e) => {
  72. let value = e.target.value
  73. set_queryFrom({ ...queryFrom, accountId: value })
  74. }}
  75. />
  76. </Col>
  77. <Col>
  78. <Input
  79. placeholder='落地页名称'
  80. allowClear
  81. style={{ width: 150 }}
  82. onChange={(e) => {
  83. let value = e.target.value
  84. set_queryFrom({ ...queryFrom, pageName: value })
  85. }}
  86. />
  87. </Col>
  88. {/* <Col>
  89. <Select placeholder='推广目标选择' style={{ minWidth: 200 }} showSearch filterOption={(input: any, option: any) =>
  90. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  91. } allowClear onChange={(value: any) => {
  92. getList({ pageNum: 1, pageSize: 20, accountId})
  93. }}>
  94. {
  95. Object.keys(PromotedObjectType).map(key => {
  96. // let obj = JSON.parse(PromotedObjectType[key])
  97. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  98. })
  99. }
  100. </Select>
  101. </Col> */}
  102. <Col>
  103. <Button type='primary' onClick={() => { getList({ ...queryFrom, pageNum: 1 }) }}>搜索</Button>
  104. </Col>
  105. </Row>
  106. </>}
  107. onChange={(props: any) => {
  108. let { sortData, pagination } = props
  109. let { current, pageSize } = pagination
  110. set_queryFrom({ ...queryFrom, pageNum: current, pageSize })
  111. getList({ ...queryFrom, pageNum: current, pageSize })
  112. }}
  113. />
  114. </div>
  115. }
  116. export default LandingPage