import { useAjax } from '@/Hook/useAjax' import { PromotedObjectType } from '@/services/launchAdq/enum' import { Col, Row, Input, Select, message, Button } from 'antd' import React, { useEffect, useCallback, useState } from 'react' import TableData from '../../components/TableData' import tableConfig from './tableConfig' import { adcreativeSyncAll, getAdqAdcreativeList } from '@/services/launchAdq/adq' type Props = { accountId: string, adAccountId: string, userId: string, queryParmas: { accountId?: string,//账户ID campaignId?: string,//计划ID adgroupId?: string,//广告ID adcreativeId?: string,//创意ID pageId?: string,//落地页ID targetingId?: string,//定向ID} }, tableIdClick: (props: { activeKey: string, parma: { accountId?: string,//账户ID campaignId?: string,//计划ID adgroupId?: string,//广告ID adcreativeId?: string,//创意ID pageId?: string,//落地页ID targetingId?: string,//定向ID } }) => void } function Creative(props: Props) { let { accountId, adAccountId, userId, tableIdClick, queryParmas } = props // api方法 const listAjax = useAjax((params) => getAdqAdcreativeList(params), { formatResult: true }) const syncAjax = useAjax((adAccountId) => adcreativeSyncAll(adAccountId)) const [selectedRows, setSelectedRows] = useState([]) const [queryFrom,set_queryFrom]=useState<{ pageNum: number; pageSize: number; accountId?: string; adcreativeName?: string; adcreativeId?: string; promotedObjectType?:string }>({pageNum:1,pageSize:20}) console.log('创意=====》') useEffect(() => { getList({ pageNum: 1, pageSize: 20 }) }, []) // 获取列表 const getList = useCallback((params: { pageNum: number; pageSize: number; accountId?: string; adcreativeName?: string; adcreativeId?: string; }) => { listAjax.run({ ...params, userId }) }, [userId, listAjax]) // 同步 const sync = useCallback(() => { // if (selectedRows?.length === 0) { // message.error('请先勾选要同步的广点通账号!') // return // } let arr = [...new Set(selectedRows?.map(item=>item.accountId))] syncAjax.run({ accountIdList:arr }).then(res => { res && listAjax.refresh() res ? message.success('同步成功!') : message.error('同步失败!') }) }, [listAjax,selectedRows]) return
tableConfig(tableIdClick)} ajax={listAjax} syncAjax={sync} dataSource={listAjax?.data?.data?.records} loading={listAjax?.loading || syncAjax?.loading} scroll={{ x: 1200, y: 550 }} total={listAjax?.data?.data?.total} page={listAjax?.data?.data?.current} pageSize={listAjax?.data?.data?.size} myKey={'adcreativeId'} leftChild={<> { let value = e.target.value set_queryFrom({...queryFrom,accountId: value }) }} /> { let value = e.target.value set_queryFrom({...queryFrom,adcreativeName: value }) }} /> { let value = e.target.value set_queryFrom({...queryFrom,adcreativeId: value }) }} /> } onChange={(props: any) => { let { sortData, pagination } = props let { current, pageSize } = pagination set_queryFrom({...queryFrom,pageNum:current,pageSize}) getList({...queryFrom, pageNum: current, pageSize }) }} rowSelection={{ selectedRowKeys: selectedRows?.map(item => item?.adcreativeId?.toString()), onChange: (selectedRowKeys: any, selectedRows: any) => { setSelectedRows(selectedRows) } }} />
} export default Creative