index.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, 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. }>({pageNum:1,pageSize:20})
  43. console.log('创意=====》')
  44. useEffect(() => {
  45. getList({ pageNum: 1, pageSize: 20, accountId, ...queryParmas })
  46. }, [accountId, userId, queryParmas])
  47. // 获取列表
  48. const getList = useCallback((params: {
  49. pageNum: number;
  50. pageSize: number;
  51. accountId?: string;
  52. adcreativeName?: string;
  53. adcreativeId?: string;
  54. }) => {
  55. if (!params.adcreativeName || params.adcreativeName !== listAjax?.params[0]?.adcreativeName) {
  56. !params.adcreativeName && delete params.adcreativeName
  57. }
  58. listAjax.run({ ...params, userId })
  59. }, [userId, listAjax])
  60. // 同步
  61. const sync = useCallback(() => {
  62. if (!adAccountId) {
  63. message.error('请先选择要同步的广点通账号!')
  64. return
  65. }
  66. syncAjax.run(adAccountId).then(res => {
  67. console.log(res)
  68. res && listAjax.refresh()
  69. res ? message.success('同步成功!') : message.error('同步失败!')
  70. })
  71. }, [adAccountId, listAjax])
  72. return <div>
  73. <TableData
  74. isCard={false}
  75. columns={() => tableConfig(tableIdClick)}
  76. ajax={listAjax}
  77. syncAjax={sync}
  78. dataSource={listAjax?.data?.data?.records}
  79. loading={listAjax?.loading || syncAjax?.loading}
  80. scroll={{ x: 1200, y: 550 }}
  81. total={listAjax?.data?.data?.total}
  82. page={listAjax?.data?.data?.current}
  83. pageSize={listAjax?.data?.data?.size}
  84. myKey={'adcreativeId'}
  85. leftChild={<>
  86. <Row gutter={[10, 10]}>
  87. <Col>
  88. <Input
  89. placeholder='广告账号'
  90. allowClear
  91. style={{ width: 150 }}
  92. onBlur={(e) => {
  93. let value = e.target.value
  94. set_queryFrom({...queryFrom,accountId: value })
  95. getList({...queryFrom, pageNum: 1, accountId: value })
  96. }}
  97. onKeyDownCapture={(e: any) => {
  98. let key = e.key
  99. if (key === 'Enter') {
  100. let value = e.target.value
  101. set_queryFrom({...queryFrom,accountId: value })
  102. getList({...queryFrom, pageNum: 1,accountId: value })
  103. }
  104. }}
  105. onChange={(e) => {
  106. let value = e.target.value
  107. if (!value) {
  108. set_queryFrom({...queryFrom,accountId: value })
  109. getList({ ...queryFrom,pageNum: 1, accountId: value })
  110. }
  111. }}
  112. />
  113. </Col>
  114. <Col>
  115. <Input
  116. placeholder='创意名称'
  117. allowClear
  118. style={{ width: 150 }}
  119. onBlur={(e) => {
  120. let value = e.target.value
  121. set_queryFrom({...queryFrom,adcreativeName: value })
  122. getList({...queryFrom, pageNum: 1, adcreativeName: value })
  123. }}
  124. onKeyDownCapture={(e: any) => {
  125. let key = e.key
  126. if (key === 'Enter') {
  127. let value = e.target.value
  128. set_queryFrom({...queryFrom,adcreativeName: value })
  129. getList({ ...queryFrom,pageNum: 1, adcreativeName: value })
  130. }
  131. }}
  132. onChange={(e) => {
  133. let value = e.target.value
  134. if (!value) {
  135. set_queryFrom({...queryFrom,adcreativeName: value })
  136. getList({ ...queryFrom,pageNum: 1, adcreativeName: value })
  137. }
  138. }}
  139. />
  140. </Col>
  141. <Col>
  142. <Input
  143. placeholder='创意ID'
  144. allowClear
  145. style={{ width: 150 }}
  146. onBlur={(e) => {
  147. let value = e.target.value
  148. set_queryFrom({...queryFrom,adcreativeId: value })
  149. getList({...queryFrom, pageNum: 1, adcreativeId: value })
  150. }}
  151. onKeyDownCapture={(e: any) => {
  152. let key = e.key
  153. if (key === 'Enter') {
  154. let value = e.target.value
  155. set_queryFrom({...queryFrom,adcreativeId: value })
  156. getList({...queryFrom, pageNum: 1, adcreativeId: value })
  157. }
  158. }}
  159. onChange={(e) => {
  160. let value = e.target.value
  161. if (!value) {
  162. set_queryFrom({...queryFrom,adcreativeId: value })
  163. getList({...queryFrom, pageNum: 1, adcreativeId: value })
  164. }
  165. }}
  166. />
  167. </Col>
  168. <Col>
  169. <Select placeholder='推广目标选择' style={{ minWidth: 150 }} showSearch filterOption={(input: any, option: any) =>
  170. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  171. } allowClear onChange={(value: any) => {
  172. set_queryFrom({...queryFrom,accountId: value })
  173. getList({...queryFrom, pageNum: 1, accountId:value })
  174. }}>
  175. {
  176. Object.keys(PromotedObjectType).map(key => {
  177. // let obj = JSON.parse(PromotedObjectType[key])
  178. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  179. })
  180. }
  181. </Select>
  182. </Col>
  183. </Row>
  184. </>}
  185. onChange={(props: any) => {
  186. let { sortData, pagination } = props
  187. let { current, pageSize } = pagination
  188. set_queryFrom({...queryFrom,pageNum:current,pageSize})
  189. getList({...queryFrom, pageNum: current, pageSize })
  190. }}
  191. />
  192. </div>
  193. }
  194. export default Creative