index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 { getAdqTargetingList, putAdqTargetingSyncAll } from '@/services/launchAdq/adq'
  5. import TableData from '../../components/TableData'
  6. import tableConfig from './tableConfig'
  7. function Targeting(props: { adAccountId: any, userId: string, accountId: any, tableIdClick: any }) {
  8. let { accountId, adAccountId, userId, tableIdClick } = props
  9. const listAjax = useAjax((params) => getAdqTargetingList(params), { formatResult: true })
  10. const syncAjax = useAjax((adAccountId) => putAdqTargetingSyncAll(adAccountId))
  11. const [selectedRows, setSelectedRows] = useState<any[]>([])
  12. const [queryFrom,set_queryFrom]=useState<{
  13. pageNum: number;
  14. pageSize: number;
  15. accountId?: string;
  16. targetingName?: string;
  17. }>({pageNum:1,pageSize:20})
  18. console.log('定向=====》')
  19. useEffect(() => {
  20. getList({ pageNum: 1, pageSize: 20 })
  21. }, [userId, accountId])
  22. // 获取列表
  23. const getList = useCallback((params: {
  24. pageNum: number;
  25. pageSize: number;
  26. accountId?: string;
  27. targetingName?: string;
  28. }) => {
  29. listAjax.run({ ...params, userId })
  30. }, [listAjax, userId])
  31. // 同步
  32. const sync = useCallback(() => {
  33. if (selectedRows?.length === 0) {
  34. message.error('请先勾选要同步的广点通账号!')
  35. return
  36. }
  37. let arr = [...new Set(selectedRows?.map(item=>item.accountId))]
  38. syncAjax.run({ accountIdList:arr }).then(res => {
  39. res && listAjax.refresh()
  40. res ? message.success('同步成功!') : message.error('同步失败!')
  41. })
  42. }, [listAjax,selectedRows])
  43. return <div>
  44. <TableData
  45. isCard={false}
  46. columns={() => tableConfig(tableIdClick)}
  47. ajax={listAjax}
  48. syncAjax={sync}
  49. dataSource={listAjax?.data?.data?.records}
  50. loading={listAjax?.loading || syncAjax?.loading}
  51. scroll={{ x: 2000, y: 550 }}
  52. total={listAjax?.data?.data?.total}
  53. page={listAjax?.data?.data?.current}
  54. pageSize={listAjax?.data?.data?.size}
  55. myKey={'targetingId'}
  56. leftChild={<>
  57. <Row gutter={[10, 10]}>
  58. <Col>
  59. <Input
  60. placeholder='广告账号'
  61. allowClear
  62. style={{ width: 150 }}
  63. onChange={(e) => {
  64. let value = e.target.value
  65. set_queryFrom({...queryFrom, accountId: value})
  66. }}
  67. />
  68. </Col>
  69. <Col>
  70. <Input
  71. placeholder='定向名称'
  72. allowClear
  73. style={{ width: 150 }}
  74. onChange={(e) => {
  75. let value = e.target.value
  76. set_queryFrom({...queryFrom, targetingName: value})
  77. }}
  78. />
  79. </Col>
  80. <Col>
  81. <Button type='primary' onClick={()=>{getList({...queryFrom,pageNum:1})}}>搜索</Button>
  82. </Col>
  83. </Row>
  84. </>}
  85. onChange={(props: any) => {
  86. let { sortData, pagination } = props
  87. let { current, pageSize } = pagination
  88. set_queryFrom({...queryFrom,pageNum:current,pageSize})
  89. getList({...queryFrom, pageNum: current, pageSize })
  90. }}
  91. rowSelection={{
  92. selectedRowKeys: selectedRows?.map(item => item?.targetingId?.toString()),
  93. onChange: (selectedRowKeys: any, selectedRows: any) => {
  94. setSelectedRows(selectedRows)
  95. }
  96. }}
  97. />
  98. </div>
  99. }
  100. export default Targeting