index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { useAjax } from '@/Hook/useAjax'
  2. import { Row, message, Input, Space, Button } from 'antd'
  3. import React, { useEffect, useState, useCallback } from 'react'
  4. import TableData from '../../components/TableData'
  5. import tableConfig from './tableConfig'
  6. import { putAdqAdAccountSyncByIds, getAdqAdAccountList } from '@/services/launchAdq/adq'
  7. import { getAdAccountListApi } from '@/services/launchAdq/adAuthorize'
  8. type Props = {
  9. accountId: string,
  10. adAccountId: string,
  11. userId: string,
  12. queryParmas: {
  13. accountId?: string,//账户ID
  14. campaignId?: string,//计划ID
  15. adgroupId?: string,//广告ID
  16. adcreativeId?: string,//创意ID
  17. pageId?: string,//落地页ID
  18. targetingId?: string,//定向ID}
  19. },
  20. tableIdClick: (props: {
  21. activeKey: string, parma: {
  22. accountId?: string,//账户ID
  23. campaignId?: string,//计划ID
  24. adgroupId?: string,//广告ID
  25. adcreativeId?: string,//创意ID
  26. pageId?: string,//落地页ID
  27. targetingId?: string,//定向ID
  28. }
  29. }) => void
  30. }
  31. function AdAccount(props: Props) {
  32. let { adAccountId, accountId, userId, tableIdClick, queryParmas } = props
  33. let [selectedRowKeys, setSelectedRowKeys] = useState<any[]>([])
  34. const [queryForm, setQueryForm] = useState<{
  35. pageNum: number;
  36. pageSize: number;
  37. accountIds: any[];
  38. adcreativeName?: string;
  39. }>({ pageNum: 1, pageSize: 20, accountIds: [] })
  40. // api方法
  41. const listAjax = useAjax((params) => getAdAccountListApi(params), { formatResult: true })
  42. const syncAjax = useAjax((params) => putAdqAdAccountSyncByIds(params))
  43. useEffect(() => {
  44. getList(queryForm)
  45. }, [accountId])
  46. // 获取列表
  47. const getList = useCallback((params?: any) => {
  48. listAjax.run({ ...params, putUserId: userId })
  49. }, [userId, listAjax])
  50. // 同步
  51. const sync = useCallback(() => {
  52. if (selectedRowKeys?.length === 0) {
  53. message.error('请勾选要同步的广点通账号!')
  54. return
  55. }
  56. syncAjax.run(selectedRowKeys).then(res => {
  57. res && listAjax.refresh()
  58. res ? message.success('同步成功!') : message.error('同步失败!')
  59. })
  60. }, [adAccountId, listAjax, selectedRowKeys])
  61. return <div>
  62. <TableData
  63. isCard={false}
  64. columns={() => tableConfig(tableIdClick)}
  65. ajax={listAjax}
  66. syncAjax={sync}
  67. dataSource={listAjax?.data?.data?.records}
  68. loading={listAjax?.loading || syncAjax?.loading}
  69. scroll={{ y: 550 }}
  70. total={listAjax?.data?.data?.total}
  71. page={listAjax?.data?.data?.current}
  72. pageSize={listAjax?.data?.data?.size}
  73. leftChild={<>
  74. <Space>
  75. <Input
  76. placeholder='广告账号'
  77. allowClear
  78. style={{ width: 150 }}
  79. onChange={(e) => {
  80. let value = e.target.value
  81. let arr: any = []
  82. if (value) {
  83. value = value.replace(/[,,\s]/g, ',')
  84. arr = value.split(',').filter((a: any) => a)
  85. }
  86. setQueryForm({ ...queryForm, accountIds: arr })
  87. }}
  88. />
  89. <Button type='primary' onClick={() => { getList({ ...queryForm, pageNum: 1 }) }}>搜索</Button>
  90. </Space>
  91. </>}
  92. rowSelection={{
  93. onChange: (selectedRowKeys: React.Key[], selectedRows: any[]) => {
  94. setSelectedRowKeys(selectedRowKeys)
  95. }
  96. }}
  97. onChange={(props: any) => {
  98. let { sortData, pagination } = props
  99. let { current, pageSize } = pagination
  100. setQueryForm({ ...queryForm, pageNum: current, pageSize })
  101. getList({ ...queryForm, pageNum: current, pageSize })
  102. }}
  103. />
  104. </div>
  105. }
  106. export default AdAccount