index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { useAjax } from '@/Hook/useAjax'
  2. import { PromotedObjectType } from '@/services/launchAdq/enum'
  3. import { Col, Row, Input, Select, message } from 'antd'
  4. import React, { useEffect, useCallback } from 'react'
  5. import TableData from '../../components/TableData'
  6. import tableConfig from './tableConfig'
  7. import { getAdqAdcreativeList, putAdqTargetingSyncAll } from '@/services/launchAdq/adq'
  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 Creative(props: Props) {
  32. let { accountId, adAccountId,userId,tableIdClick } = props
  33. // api方法
  34. const listAjax = useAjax((params) => getAdqAdcreativeList(params), { formatResult: true })
  35. const syncAjax = useAjax((adAccountId) => putAdqTargetingSyncAll(adAccountId))
  36. console.log('创意=====》')
  37. useEffect(() => {
  38. getList({ pageNum: 1, pageSize: 20 })
  39. }, [accountId,userId])
  40. // 获取列表
  41. const getList = useCallback((params: {
  42. pageNum: number;
  43. pageSize: number;
  44. accountId?: string;
  45. adcreativeName?: string;
  46. }) => {
  47. if (!params.adcreativeName || params.adcreativeName !== listAjax?.params[0]?.adcreativeName) {
  48. !params.adcreativeName && delete params.adcreativeName
  49. listAjax.run({ ...params,userId, accountId })
  50. }
  51. }, [accountId,userId,listAjax])
  52. // 同步
  53. const sync = useCallback(() => {
  54. if(!adAccountId){
  55. message.error('请先选择要同步的广点通账号!')
  56. return
  57. }
  58. syncAjax.run(adAccountId).then(res => {
  59. console.log(res)
  60. res && listAjax.refresh()
  61. res ? message.success('同步成功!') : message.error('同步失败!')
  62. })
  63. }, [adAccountId, listAjax])
  64. return <div>
  65. <TableData
  66. columns={()=>tableConfig(tableIdClick)}
  67. ajax={listAjax}
  68. syncAjax={sync}
  69. dataSource={listAjax?.data?.data?.records}
  70. loading={listAjax?.loading || syncAjax?.loading}
  71. scroll={{x:1200, y:550 }}
  72. total={listAjax?.data?.data?.total}
  73. page={listAjax?.data?.data?.current}
  74. pageSize={listAjax?.data?.data?.size}
  75. myKey={'adcreativeId'}
  76. leftChild={<>
  77. <Row gutter={[10, 10]}>
  78. <Col>
  79. <Input
  80. placeholder='创意名称'
  81. allowClear
  82. onBlur={(e) => {
  83. let value = e.target.value
  84. getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
  85. }}
  86. onKeyDownCapture={(e: any) => {
  87. let key = e.key
  88. if (key === 'Enter') {
  89. let value = e.target.value
  90. getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
  91. }
  92. }}
  93. onChange={(e) => {
  94. let value = e.target.value
  95. if (!value) {
  96. getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
  97. }
  98. }}
  99. />
  100. </Col>
  101. <Col>
  102. <Select placeholder='推广目标选择' style={{ minWidth: 200 }} showSearch filterOption={(input: any, option: any) =>
  103. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  104. } allowClear onChange={(value: any) => {
  105. getList({ pageNum: 1, pageSize: 20, accountId })
  106. }}>
  107. {
  108. Object.keys(PromotedObjectType).map(key => {
  109. // let obj = JSON.parse(PromotedObjectType[key])
  110. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  111. })
  112. }
  113. </Select>
  114. </Col>
  115. </Row>
  116. </>}
  117. onChange={(props: any) => {
  118. let { sortData, pagination } = props
  119. let { current, pageSize } = pagination
  120. getList({ pageNum: current, pageSize })
  121. }}
  122. />
  123. </div>
  124. }
  125. export default Creative