|
@@ -1,96 +1,74 @@
|
|
|
|
|
|
-import { FnAjax, useAjax } from '@/Hook/useAjax'
|
|
|
-import { ListData, } from '@/services/launchAdq'
|
|
|
+import { useAjax } from '@/Hook/useAjax'
|
|
|
import { PromotedObjectType } from '@/services/launchAdq/enum'
|
|
|
-import { Col, Row, Input, Select, Button } from 'antd'
|
|
|
+import { Col, Row, Input, Select, Button, message } from 'antd'
|
|
|
import React, { useEffect, useState, useCallback } from 'react'
|
|
|
import TableData from '../../components/TableData'
|
|
|
import tableConfig from './tableConfig'
|
|
|
-import { getAdqAdcreativeList } from '@/services/launchAdq/adq'
|
|
|
+import { getAdqAdcreativeList, putAdqTargetingSyncAll } from '@/services/launchAdq/adq'
|
|
|
|
|
|
-export interface ModalConfig {
|
|
|
- visible: boolean;
|
|
|
- type?:'add'|'look'|'edit',
|
|
|
- dataInfo?:null
|
|
|
-}
|
|
|
-
|
|
|
-function Creative(props:{accountId:string}) {
|
|
|
- const {accountId} = props
|
|
|
- // 变量
|
|
|
- const [modalConfig, setModalConfig] = useState<ModalConfig>({
|
|
|
- visible: false,
|
|
|
- type:'add'
|
|
|
- })
|
|
|
- const [oldsearchData, setOldsearchData] = useState<any>(null)
|
|
|
+function Creative(props: { accountId: string, adAccountId: string }) {
|
|
|
+ let { accountId, adAccountId } = props
|
|
|
// api方法
|
|
|
- const sysAdcreativeList: FnAjax<ListData<any> | any> = useAjax((params) => getAdqAdcreativeList(params), { formatResult: true })
|
|
|
- // 初始获取列表
|
|
|
+ const listAjax = useAjax((params) => getAdqAdcreativeList(params), { formatResult: true })
|
|
|
+ const syncAjax = useAjax((adAccountId) => putAdqTargetingSyncAll(adAccountId))
|
|
|
useEffect(() => {
|
|
|
- if(accountId){
|
|
|
- getList({ pageSize: 20, pageNum: 1,accountId })
|
|
|
- }
|
|
|
+ getList({ pageNum: 1, pageSize: 20 })
|
|
|
}, [accountId])
|
|
|
// 获取列表
|
|
|
- const getList = useCallback((arg: { pageSize: number, pageNum: number, accountId: string }) => {
|
|
|
- Object.keys(arg).forEach(key => {
|
|
|
- !arg[key] && delete arg[key]
|
|
|
- })
|
|
|
- if (JSON.stringify(arg) !== JSON.stringify(oldsearchData)) {
|
|
|
- setOldsearchData(arg)
|
|
|
- sysAdcreativeList.run(arg)
|
|
|
+ const getList = useCallback((params: {
|
|
|
+ pageNum: number;
|
|
|
+ pageSize: number;
|
|
|
+ accountId?: string;
|
|
|
+ adcreativeName?: string;
|
|
|
+ }) => {
|
|
|
+ if (!params.adcreativeName || params.adcreativeName !== listAjax?.params[0]?.adcreativeName) {
|
|
|
+ !params.adcreativeName && delete params.adcreativeName
|
|
|
+ accountId && listAjax.run({ ...params, accountId })
|
|
|
}
|
|
|
- }, [oldsearchData])
|
|
|
-
|
|
|
- // 设置变量
|
|
|
- const handleModalConfig = useCallback((arg: ModalConfig) => {
|
|
|
- setModalConfig({ ...modalConfig, ...arg })
|
|
|
- }, [modalConfig])
|
|
|
- // submit
|
|
|
- // 获取详情
|
|
|
- const getInfo = useCallback((adgroupsId, type) => {
|
|
|
- // targetingInfo.run(adgroupsId).then((res: any) => {
|
|
|
- // setModalConfig({ ...modalConfig, visible: true, type, dataInfo: res.data })
|
|
|
- // })
|
|
|
- }, [modalConfig])
|
|
|
- // 回调
|
|
|
- const callback = useCallback((data, type) => {
|
|
|
- // getInfo(data.id, type)
|
|
|
+ }, [accountId])
|
|
|
+ // 同步
|
|
|
+ const sync = useCallback(() => {
|
|
|
+ syncAjax.run(adAccountId).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ res && listAjax.refresh()
|
|
|
+ res ? message.success('同步成功!') : message.error('同步失败!')
|
|
|
|
|
|
- }, [])
|
|
|
+ })
|
|
|
+ }, [adAccountId, listAjax])
|
|
|
return <div>
|
|
|
<TableData
|
|
|
- columns={()=>tableConfig(callback)}
|
|
|
- ajax={sysAdcreativeList}
|
|
|
- dataSource={sysAdcreativeList?.data?.data?.records}
|
|
|
- loading={sysAdcreativeList?.loading}
|
|
|
- scroll={{ y: 600 }}
|
|
|
- total={sysAdcreativeList?.data?.data?.total}
|
|
|
- page={sysAdcreativeList?.data?.data?.current}
|
|
|
- pageSize={sysAdcreativeList?.data?.data?.size}
|
|
|
+ columns={tableConfig}
|
|
|
+ ajax={listAjax}
|
|
|
+ syncAjax={sync}
|
|
|
+ dataSource={listAjax?.data?.data?.records}
|
|
|
+ loading={listAjax?.loading || syncAjax?.loading}
|
|
|
+ scroll={{ x: 2000 }}
|
|
|
+ total={listAjax?.data?.data?.total}
|
|
|
+ page={listAjax?.data?.data?.current}
|
|
|
+ pageSize={listAjax?.data?.data?.size}
|
|
|
+ myKey={'adcreativeId'}
|
|
|
leftChild={<>
|
|
|
<Row gutter={[10, 10]}>
|
|
|
- <Col span={24}><Button type='primary' onClick={() => {
|
|
|
- handleModalConfig({ visible: true })
|
|
|
- }}>新建创意模板</Button></Col>
|
|
|
<Col>
|
|
|
<Input
|
|
|
placeholder='创意名称'
|
|
|
allowClear
|
|
|
onBlur={(e) => {
|
|
|
let value = e.target.value
|
|
|
- getList({ pageNum: 1, pageSize: 20, accountId })
|
|
|
+ getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
|
|
|
}}
|
|
|
onKeyDownCapture={(e: any) => {
|
|
|
let key = e.key
|
|
|
if (key === 'Enter') {
|
|
|
let value = e.target.value
|
|
|
- getList({ pageNum: 1, pageSize: 20, accountId })
|
|
|
+ getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
|
|
|
}
|
|
|
}}
|
|
|
onChange={(e) => {
|
|
|
let value = e.target.value
|
|
|
if (!value) {
|
|
|
- getList({ pageNum: 1, pageSize: 20, accountId })
|
|
|
+ getList({ pageNum: 1, pageSize: 20, adcreativeName: value })
|
|
|
}
|
|
|
}}
|
|
|
/>
|
|
@@ -99,7 +77,7 @@ function Creative(props:{accountId:string}) {
|
|
|
<Select placeholder='推广目标选择' style={{ minWidth: 200 }} showSearch filterOption={(input: any, option: any) =>
|
|
|
(option!.children as unknown as string).toLowerCase().includes(input.toLowerCase())
|
|
|
} allowClear onChange={(value: any) => {
|
|
|
- getList({ pageNum: 1, pageSize: 20, accountId})
|
|
|
+ getList({ pageNum: 1, pageSize: 20, accountId })
|
|
|
}}>
|
|
|
{
|
|
|
Object.keys(PromotedObjectType).map(key => {
|