index.tsx 5.8 KB

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