index.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React, { useEffect, useCallback, useState } from 'react'
  2. import { 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 [queryFrom,set_queryFrom]=useState<{
  12. pageNum: number;
  13. pageSize: number;
  14. accountId?: string;
  15. targetingName?: string;
  16. }>({pageNum:1,pageSize:20})
  17. console.log('定向=====》')
  18. useEffect(() => {
  19. getList({ pageNum: 1, pageSize: 20, accountId })
  20. }, [userId, accountId])
  21. // 获取列表
  22. const getList = useCallback((params: {
  23. pageNum: number;
  24. pageSize: number;
  25. accountId?: string;
  26. targetingName?: string;
  27. }) => {
  28. console.log(accountId)
  29. if (!params.targetingName || params.targetingName !== listAjax?.params[0]?.targetingName) {
  30. !params.targetingName && delete params.targetingName
  31. }
  32. listAjax.run({ ...params, userId })
  33. }, [listAjax, userId])
  34. // 同步
  35. const sync = useCallback(() => {
  36. if (!adAccountId) {
  37. message.error('请先选择要同步的广点通账号!')
  38. return
  39. }
  40. syncAjax.run(adAccountId).then(res => {
  41. console.log(res)
  42. res && listAjax.refresh()
  43. res ? message.success('同步成功!') : message.error('同步失败!')
  44. })
  45. }, [adAccountId, listAjax])
  46. return <div>
  47. <TableData
  48. isCard={false}
  49. columns={() => tableConfig(tableIdClick)}
  50. ajax={listAjax}
  51. syncAjax={sync}
  52. dataSource={listAjax?.data?.data?.records}
  53. loading={listAjax?.loading || syncAjax?.loading}
  54. scroll={{ x: 2000, y: 550 }}
  55. total={listAjax?.data?.data?.total}
  56. page={listAjax?.data?.data?.current}
  57. pageSize={listAjax?.data?.data?.size}
  58. myKey={'targetingId'}
  59. leftChild={<>
  60. <Row gutter={[10, 10]}>
  61. <Col>
  62. <Input
  63. placeholder='广告账号'
  64. allowClear
  65. style={{ width: 150 }}
  66. onBlur={(e) => {
  67. let value = e.target.value
  68. set_queryFrom({...queryFrom, accountId: value})
  69. getList({...queryFrom, pageNum: 1, accountId: value })
  70. }}
  71. onKeyDownCapture={(e: any) => {
  72. let key = e.key
  73. if (key === 'Enter') {
  74. let value = e.target.value
  75. set_queryFrom({...queryFrom, accountId: value})
  76. getList({ ...queryFrom,pageNum: 1, accountId: value })
  77. }
  78. }}
  79. onChange={(e) => {
  80. let value = e.target.value
  81. if (!value) {
  82. set_queryFrom({...queryFrom, accountId: value})
  83. getList({ ...queryFrom,pageNum: 1, accountId: value })
  84. }
  85. }}
  86. />
  87. </Col>
  88. <Col>
  89. <Input
  90. placeholder='定向名称'
  91. allowClear
  92. style={{ width: 150 }}
  93. onBlur={(e) => {
  94. let value = e.target.value
  95. set_queryFrom({...queryFrom, targetingName: value})
  96. getList({...queryFrom, pageNum: 1, targetingName: value })
  97. }}
  98. onKeyDownCapture={(e: any) => {
  99. let key = e.key
  100. if (key === 'Enter') {
  101. let value = e.target.value
  102. set_queryFrom({...queryFrom, targetingName: value})
  103. getList({ ...queryFrom,pageNum: 1, targetingName: value })
  104. }
  105. }}
  106. onChange={(e) => {
  107. let value = e.target.value
  108. if (!value) {
  109. set_queryFrom({...queryFrom, targetingName: value})
  110. getList({...queryFrom, pageNum: 1, targetingName: value })
  111. }
  112. }}
  113. />
  114. </Col>
  115. </Row>
  116. </>}
  117. onChange={(props: any) => {
  118. let { sortData, pagination } = props
  119. let { current, pageSize } = pagination
  120. set_queryFrom({...queryFrom,pageNum:current,pageSize})
  121. getList({...queryFrom, pageNum: current, pageSize })
  122. }}
  123. />
  124. </div>
  125. }
  126. export default Targeting