index.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. import { useAjax } from '@/Hook/useAjax'
  2. import { AdStatusEnum, PromotedObjectType } from '@/services/launchAdq/enum'
  3. import { Col, Row, Input, Select, message, Space, Button, Popconfirm, Switch, notification, Modal } from 'antd'
  4. import React, { useEffect, useCallback, useState } from 'react'
  5. import TableData from '../../components/TableData'
  6. import tableConfig from './tableConfig'
  7. import { putAdqAdgroupsSync, getAdqAdgroupsList, delListAdqAdgroupsApi, newEditAdqAdgroupsDataApi, editAdqAdgroupsDataApi, putAdqAdgroupsSyncBatch } from '@/services/launchAdq/adq'
  8. import { CopyOutlined, DeleteOutlined, FieldTimeOutlined, PauseCircleOutlined, PlayCircleOutlined, SyncOutlined, TransactionOutlined } from '@ant-design/icons'
  9. import UpdateAd from './updateAd'
  10. import Copy from './copy'
  11. import PlanDetail from '@/pages/adMonitor/adMonitorList/components/planDetail'
  12. import { txAdConfig } from '../config'
  13. import Log from '../log'
  14. import EarlyWarning from '@/components/EarlyWarning'
  15. import SetEarlyWarning from '@/components/EarlyWarning/setEarlyWarning'
  16. type Props = {
  17. accountId: string,
  18. adAccountId: string,
  19. userId: string,
  20. queryParmas: {
  21. accountId?: string,//账户ID
  22. campaignId?: string,//计划ID
  23. adgroupId?: string,//广告ID
  24. adcreativeId?: string,//创意ID
  25. pageId?: string,//落地页ID
  26. targetingId?: string,//定向ID}
  27. },
  28. tableIdClick: (props: {
  29. activeKey: string, parma: {
  30. accountId?: string,//账户ID
  31. campaignId?: string,//计划ID
  32. adgroupId?: string,//广告ID
  33. adcreativeId?: string,//创意ID
  34. pageId?: string,//落地页ID
  35. targetingId?: string,//定向ID
  36. }
  37. }) => void
  38. }
  39. const Ad: React.FC<Props> = (props) => {
  40. /***********************/
  41. let { accountId, adAccountId, userId, tableIdClick, queryParmas } = props
  42. const [selectedRows, setSelectedRows] = useState<any[]>([])
  43. const [update, setUpdate] = useState<{ visible: boolean, title: string }>({ visible: false, title: '' })
  44. const [model, setModel] = useState(true)
  45. const [copyData, setCopyData] = useState<{ visible: boolean }>({ visible: false })
  46. const [detailShow, setDetailShow] = useState<boolean>(false)
  47. const [detailData, setDetailData] = useState<any>({})
  48. const [czjlShow, setCzjlShow] = useState(false)
  49. const [queryFrom, set_queryFrom] = useState<{
  50. pageNum: number;
  51. pageSize: number;
  52. accountIdList?: any[];
  53. adgroupName?: string;
  54. adgroupIdList?: any[];
  55. promotedObjectType?: string;
  56. isDeleted?: boolean
  57. campaignIdList?: any[]
  58. statusList?: any[],
  59. memoList?: any[]
  60. remarkList?: any[]
  61. }>({ pageNum: 1, pageSize: 20 })
  62. const listAjax = useAjax((params) => getAdqAdgroupsList(params), { formatResult: true })
  63. const syncAjax = useAjax((adAccountId) => putAdqAdgroupsSync(adAccountId))
  64. const delListAdqAdgroups = useAjax((params) => delListAdqAdgroupsApi(params))
  65. const editAdqAdgroupsData = useAjax((params) => newEditAdqAdgroupsDataApi(params))
  66. const editAdqAdgroups = useAjax((params) => editAdqAdgroupsDataApi(params))
  67. const putAdqAdgroupsSyncBatchApi = useAjax((params) => putAdqAdgroupsSyncBatch(params))
  68. /************************/
  69. useEffect(() => {
  70. let { accountId, campaignId, adgroupId, ...obj } = queryParmas
  71. let new_queryParmas = {
  72. ...obj,
  73. accountIdList: accountId ? [accountId] : [],
  74. campaignIdList: campaignId ? [campaignId] : [],
  75. adgroupIdList: adgroupId ? [adgroupId] : []
  76. }
  77. getList({ pageNum: 1, pageSize: 20, ...new_queryParmas, accountIdList: accountId ? [accountId] : [] })
  78. }, [accountId, userId, queryParmas])
  79. // 获取列表
  80. const getList = useCallback((params: {
  81. pageNum: number;
  82. pageSize: number;
  83. accountIdList?: any[];
  84. adgroupName?: string;
  85. adgroupIdList?: any[];
  86. promotedObjectType?: string;
  87. isDeleted?: boolean
  88. campaignIdList?: any[]
  89. statusList?: any[],
  90. memoList?: any[]
  91. remarkList?: any[]
  92. }) => {
  93. listAjax.run({ ...params, userId })
  94. }, [userId, listAjax])
  95. // 同步
  96. const sync = useCallback(() => {
  97. if (selectedRows?.length === 0) {
  98. message.error('请先勾选要同步的广点通账号!')
  99. return
  100. }
  101. let arr = [...new Set(selectedRows?.map(item=>item.accountId))]
  102. syncAjax.run({ accountIdList:arr }).then(res => {
  103. res && listAjax.refresh()
  104. res ? message.success('同步成功!') : message.error('同步失败!')
  105. })
  106. }, [listAjax,selectedRows])
  107. /** 删除 */
  108. const deleteHandle = (type: 0 | 1, adgroupId?: number) => {
  109. delListAdqAdgroups.run({ adgroupIds: type === 1 ? selectedRows.map(item => item.adgroupId) : [adgroupId] }).then(res => {
  110. message.success('删除成功')
  111. setSelectedRows([])
  112. listAjax.refresh()
  113. })
  114. }
  115. /** 修改排期出价 */
  116. const editScheduling = () => {
  117. setUpdate({ visible: true, title: '批量修改' })
  118. }
  119. /** 修改排期出价 */
  120. const editDeepConversion = () => {
  121. setUpdate({ visible: true, title: '批量修改深度优化' })
  122. }
  123. // 单个启停
  124. const onChange = () => {
  125. listAjax.refresh()
  126. setSelectedRows([])
  127. }
  128. // 批量启停
  129. const adStatus = (type: 'play' | 'suspend') => {
  130. let params: any = {}
  131. if (type === 'play') {
  132. params.configuredStatus = 'AD_STATUS_NORMAL'
  133. params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_SUSPEND').map(item => item.adgroupId)
  134. } else {
  135. params.configuredStatus = 'AD_STATUS_SUSPEND'
  136. params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, adgroupId: number }) => item.configuredStatus === 'AD_STATUS_NORMAL').map(item => item.adgroupId)
  137. }
  138. if (params.adgroupIds.length === 0) {
  139. message.warn(`所以账号都是${type === 'play' ? '启动' : '暂停'}状态,无需${type === 'play' ? '启动' : '暂停'}操作`)
  140. return
  141. }
  142. editAdqAdgroupsData.run(params).then(res => {
  143. message.success(`${type === 'play' ? '启动' : '暂停'}成功: ${res.success},失败: ${res.fail}`)//
  144. if (res?.fail) {
  145. notification.error({
  146. message: `${type === 'play' ? '启动' : '暂停'}失败`,
  147. description: `成功: ${res.success},修改失败${res.fail}条,失败的请到任务列表查看`,
  148. duration: 0
  149. });
  150. }
  151. listAjax.refresh()
  152. setSelectedRows([])
  153. })
  154. }
  155. //同步广告
  156. const syncAd = useCallback(() => {
  157. putAdqAdgroupsSyncBatchApi.run({ adgroupIds: selectedRows?.map(item => item.adgroupId) }).then(res => {
  158. if (res) {
  159. message.success('同步成功!')
  160. }
  161. })
  162. }, [selectedRows])
  163. // 批量复制
  164. const copyHandle = () => {
  165. setCopyData({ visible: true })
  166. }
  167. const handleSave = (row: any) => {
  168. const hide = message.loading(`广告“${row.adgroupId}”广告名称修改成<${row.adgroupName}>,修改中`, 0, () => {
  169. message.success('修改成功');
  170. });
  171. editAdqAdgroups.run({ adgroupIds: [row.adgroupId], adgroupName: row.adgroupName }).then(res => {
  172. message.success('修改广告名称成功')
  173. listAjax.refresh()
  174. hide()
  175. })
  176. }
  177. const details = (data: any) => {
  178. setDetailData(data)
  179. setDetailShow(true)
  180. }
  181. return <div>
  182. {/* 修改广告 */}
  183. {update.visible && <UpdateAd
  184. {...update}
  185. selectedRows={selectedRows}
  186. onChange={() => {
  187. setUpdate({ visible: false, title: '' })
  188. listAjax.refresh()
  189. setSelectedRows([])
  190. }}
  191. onClose={() => { setUpdate({ visible: false, title: '' }) }}
  192. />}
  193. {/* 复制广告 */}
  194. {copyData.visible && <Copy selectedRows={selectedRows} {...copyData} onClose={() => setCopyData({ visible: false })} onChange={() => { setCopyData({ visible: false }); listAjax.refresh(); setSelectedRows([]) }} />}
  195. <Row gutter={[6, 6]} align='middle' style={{ marginBottom: 15 }}>
  196. <Col>
  197. <Input
  198. placeholder='广告账号'
  199. allowClear
  200. style={{ width: 120 }}
  201. onChange={(e) => {
  202. let value = e.target.value
  203. let arr: any = []
  204. if (value) {
  205. value = value.replace(/[,,\s]/g, ',')
  206. arr = value.split(',').filter((a: any) => a)
  207. }
  208. set_queryFrom({ ...queryFrom, accountIdList: arr })
  209. }}
  210. />
  211. </Col>
  212. <Col>
  213. <Input
  214. placeholder='广告名称'
  215. allowClear
  216. style={{ width: 120 }}
  217. onChange={(e) => {
  218. let value = e.target.value
  219. set_queryFrom({ ...queryFrom, adgroupName: value })
  220. }}
  221. />
  222. </Col>
  223. <Col>
  224. <Input
  225. placeholder='广告ID'
  226. allowClear
  227. style={{ width: 120 }}
  228. onChange={(e) => {
  229. let value = e.target.value
  230. let arr: any = []
  231. if (value) {
  232. value = value.replace(/[,,\s]/g, ',')
  233. arr = value.split(',').filter((a: any) => a)
  234. }
  235. set_queryFrom({ ...queryFrom, adgroupIdList: arr })
  236. }}
  237. />
  238. </Col>
  239. <Col>
  240. <Input
  241. placeholder='计划ID'
  242. allowClear
  243. style={{ width: 120 }}
  244. onChange={(e) => {
  245. let value = e.target.value
  246. let arr: any = []
  247. if (value) {
  248. value = value.replace(/[,,\s]/g, ',')
  249. arr = value.split(',').filter((a: any) => a)
  250. }
  251. set_queryFrom({ ...queryFrom, campaignIdList: arr })
  252. }}
  253. />
  254. </Col>
  255. <Col>
  256. <Select
  257. placeholder='推广目标选择'
  258. style={{ width: 120 }}
  259. showSearch
  260. filterOption={(input: any, option: any) =>
  261. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  262. }
  263. allowClear
  264. onChange={(value: any) => {
  265. set_queryFrom({ ...queryFrom, promotedObjectType: value })
  266. }}
  267. >
  268. {Object.keys(PromotedObjectType).map(key => {
  269. return <Select.Option value={key} key={key}>{PromotedObjectType[key]}</Select.Option>
  270. })}
  271. </Select>
  272. </Col>
  273. <Col>
  274. <Select
  275. placeholder='是否已删除'
  276. style={{ width: 120 }}
  277. showSearch
  278. filterOption={(input: any, option: any) =>
  279. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  280. }
  281. allowClear
  282. onChange={(value: any) => {
  283. set_queryFrom({ ...queryFrom, isDeleted: value })
  284. }}
  285. >
  286. <Select.Option value={true}>已删除</Select.Option>
  287. <Select.Option value={false}>未删除</Select.Option>
  288. </Select>
  289. </Col>
  290. <Col>
  291. <Select
  292. placeholder='广告状态'
  293. mode="multiple"
  294. style={{ width: 120 }}
  295. showSearch
  296. filterOption={(input: any, option: any) =>
  297. (option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
  298. }
  299. allowClear
  300. onChange={(value: any) => {
  301. set_queryFrom({ ...queryFrom, statusList: value })
  302. }}
  303. >
  304. {
  305. Object.keys(AdStatusEnum).map(key => {
  306. return <Select.Option value={key} key={key}>{AdStatusEnum[key]}</Select.Option>
  307. })
  308. }
  309. </Select>
  310. </Col>
  311. <Col>
  312. <Input
  313. placeholder='腾讯备注'
  314. allowClear
  315. style={{ width: 120 }}
  316. onChange={(e) => {
  317. let value = e.target.value
  318. let arr: any = []
  319. if (value) {
  320. value = value.replace(/[,,\s]/g, ',')
  321. arr = value.split(',').filter((a: any) => a)
  322. }
  323. set_queryFrom({ ...queryFrom, memoList: arr })
  324. }}
  325. />
  326. </Col>
  327. <Col>
  328. <Input
  329. placeholder='本地备注'
  330. allowClear
  331. style={{ width: 120 }}
  332. onChange={(e) => {
  333. let value = e.target.value
  334. let arr: any = []
  335. if (value) {
  336. value = value.replace(/[,,\s]/g, ',')
  337. arr = value.split(',').filter((a: any) => a)
  338. }
  339. set_queryFrom({ ...queryFrom, remarkList: arr })
  340. }}
  341. />
  342. </Col>
  343. <Col>
  344. <Button type='primary' onClick={() => getList({ ...queryFrom, pageNum: 1 })}> 搜索</Button>
  345. </Col>
  346. </Row>
  347. <TableData
  348. isCard={false}
  349. columns={() => tableConfig(onChange, details, handleSave, tableIdClick)}
  350. ajax={listAjax}
  351. syncAjax={sync}
  352. fixed={{ left: 2, right: 4 }}
  353. dataSource={listAjax?.data?.data?.records}
  354. loading={listAjax?.loading || syncAjax?.loading}
  355. scroll={{ y: 560 }}
  356. total={listAjax?.data?.data?.total}
  357. page={listAjax?.data?.data?.current}
  358. pageSize={listAjax?.data?.data?.size}
  359. myKey={'adgroupId'}
  360. gutter={[0, 10]}
  361. config={txAdConfig}
  362. configName="腾讯广告"
  363. leftChild={<Space direction='vertical'>
  364. <Row gutter={[10, 10]} align='middle'>
  365. <Col>
  366. <Switch checkedChildren="普通模式" unCheckedChildren="深度优化" checked={model} onChange={(checked) => { setModel(checked); setSelectedRows([]) }} style={model ? {} : { background: '#67c23a' }} />
  367. </Col>
  368. {model ? <>
  369. <Col><Button type='primary' style={{ background: '#1890ff' }} icon={<FieldTimeOutlined />} disabled={selectedRows.length === 0} onClick={editScheduling}>修改排期出价名称</Button></Col>
  370. <Col><Button type='primary' style={{ background: '#1890ff' }} icon={<CopyOutlined />} disabled={selectedRows.length === 0} onClick={copyHandle}>复制</Button></Col>
  371. <Col><Button type='primary' style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={editAdqAdgroupsData.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('play')}>启动广告</Button></Col>
  372. <Col><Button type='primary' style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={editAdqAdgroupsData.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('suspend')}>暂停广告</Button></Col>
  373. <Col><Button type='primary' style={{ background: '#00bcd4', borderColor: '#00bcd4' }} loading={putAdqAdgroupsSyncBatchApi.loading} icon={<SyncOutlined />} disabled={selectedRows.length === 0} onClick={syncAd}>同步广告</Button></Col>
  374. <Col><SetEarlyWarning selectedRows={selectedRows} onChange={() => listAjax.refresh()}/></Col>
  375. <Col>
  376. <Popconfirm
  377. title="确定删除?"
  378. onConfirm={() => deleteHandle(1)}
  379. okText="是"
  380. cancelText="否"
  381. disabled={selectedRows.length === 0}
  382. >
  383. <Button danger type='primary' loading={delListAdqAdgroups.loading} icon={<DeleteOutlined />} disabled={selectedRows.length === 0}>删除</Button>
  384. </Popconfirm>
  385. </Col>
  386. </> : <Col><Button type='primary' icon={<TransactionOutlined />} disabled={selectedRows.length === 0} onClick={editDeepConversion}>修改深度优化ROI</Button></Col>}
  387. <Col>
  388. <Button type='dashed' onClick={() => { setCzjlShow(true) }}>操作记录</Button>
  389. </Col>
  390. <Col>
  391. <EarlyWarning />
  392. </Col>
  393. </Row>
  394. </Space>}
  395. rowSelection={{
  396. selectedRowKeys: selectedRows.map(item => item.adgroupId.toString()),
  397. getCheckboxProps: (record: any) => ({
  398. disabled: model ?
  399. record.status === 'STATUS_DELETED' :
  400. record.status === 'STATUS_DELETED' ||
  401. !(!model &&
  402. record?.promotedObjectType === 'PROMOTED_OBJECT_TYPE_WECHAT_OFFICIAL_ACCOUNT' &&
  403. record?.optimizationGoal === 'OPTIMIZATIONGOAL_FOLLOW' &&
  404. record?.deepConversionSpec?.deepConversionWorthSpec?.goal === 'GOAL_1DAY_PURCHASE_ROAS'
  405. )
  406. }),
  407. onChange: (selectedRowKeys: any, selectedRows: any) => {
  408. setSelectedRows(selectedRows)
  409. }
  410. }}
  411. onChange={(props: any) => {
  412. let { sortData, pagination } = props
  413. let { current, pageSize } = pagination
  414. set_queryFrom({ ...queryFrom, pageNum: current, pageSize })
  415. getList({ ...queryFrom, pageNum: current, pageSize })
  416. }}
  417. />
  418. {detailShow && <PlanDetail visible={detailShow} onClose={() => { setDetailShow(false) }} data={detailData} />}
  419. {czjlShow && <Modal
  420. visible={czjlShow}
  421. onCancel={()=>{setCzjlShow(false)}}
  422. onOk={()=>{setCzjlShow(false)}}
  423. width={1200}
  424. footer={null}
  425. title={"广告操作记录"}
  426. >
  427. <Log {...props} />
  428. </Modal>}
  429. </div>
  430. }
  431. export default Ad