index.tsx 4.5 KB

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