index.tsx 6.2 KB

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