123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- import { useAjax } from '@/Hook/useAjax'
- import { Col, Row, message, Space, Button, Switch, notification, Modal, Tooltip, Dropdown, Menu } from 'antd'
- import React, { useEffect, useCallback, useState, useRef } from 'react'
- import TableData from '../../components/TableData'
- import { putAdqAdgroupsSync, delListAdqAdgroupsApi, newEditAdqAdgroupsDataApi, editAdqAdgroupsDataApi, putAdqAdgroupsSyncBatch, putModifyCustomAudienceApi, getPutUserApi, delUserTagApi } from '@/services/launchAdq/adq'
- import { CopyOutlined, DeleteOutlined, DownOutlined, ExclamationCircleOutlined, FieldTimeOutlined, FormOutlined, PauseCircleOutlined, PlayCircleOutlined, QuestionCircleOutlined, SyncOutlined, TransactionOutlined } from '@ant-design/icons'
- import UpdateAd from './updateAd'
- import Copy from './copy'
- import { planAdConfig } from '../config'
- import Log from '../log'
- import SetEarlyWarning from '@/components/EarlyWarning/setEarlyWarning'
- import CrowdPackModal from '../../components/crowdPackModal'
- import './index.less'
- import tablePlanConfig from './tablePlanListConfig'
- import { AdListProps, getAdListApi } from '@/services/adMonitor/adMonitor'
- import FilterQuery from './FilterQuery'
- import Details from '@/pages/adMonitor/adMonitorList/components/Details'
- import AdExpandedRowRender from './adExpandedRowRender'
- import { useSize } from 'ahooks'
- import RuleAccountLog from '@/components/EarlyWarning/ruleAccountLog'
- import PlanTag from './planTag'
- const AdPlanList: React.FC<{ userId: string }> = (props) => {
- /***********************/
- const { userId } = props
- const [selectedRows, setSelectedRows] = useState<any[]>([])
- const [update, setUpdate] = useState<{ visible: boolean, title: string }>({ visible: false, title: '' })
- const [model, setModel] = useState(true)
- const [copyData, setCopyData] = useState<{ visible: boolean }>({ visible: false })
- const [detailShow, setDetailShow] = useState<boolean>(false)
- const [detailData, setDetailData] = useState<any>({})
- const [czjlShow, setCzjlShow] = useState(false)
- const [cpVisible, setCpVisible] = useState(false)
- const [accountCreateLogs, setAccountCreateLogs] = useState<{ adAccountId: number, id: number, customAudienceList?: any[], excludedCustomAudienceList?: any[] }[]>([])
- const [queryForm, setQueryForm] = useState<AdListProps>({ pageNum: 1, pageSize: 20, columns: [], isDeleted: false })
- const [filterForm, setFilterForm] = useState<AdListProps>()
- const getAdList = useAjax((params) => getAdListApi(params), { formatResult: true })
- const syncAjax = useAjax((adAccountId) => putAdqAdgroupsSync(adAccountId))
- const delListAdqAdgroups = useAjax((params) => delListAdqAdgroupsApi(params))
- const editAdqAdgroupsData = useAjax((params) => newEditAdqAdgroupsDataApi(params))
- const editAdqAdgroups = useAjax((params) => editAdqAdgroupsDataApi(params))
- const putModifyCustomAudience = useAjax((params) => putModifyCustomAudienceApi(params))
- const putAdqAdgroupsSyncBatchApi = useAjax((params) => putAdqAdgroupsSyncBatch(params))
- const getPutUser = useAjax((params) => getPutUserApi(params))
- const delUserTag = useAjax((params) => delUserTagApi(params))
- const [logVisible, setLogVisible] = useState<boolean>(false)
- const [adgroupId, setAdgroupId] = useState<string>('')
- const [adgroupName, setAdgroupName] = useState<string>('')
- const [accountIdRule, setAccountIdRule] = useState<string>('')
- const [tagVisible, setTagVisible] = useState<boolean>(false)
- const [tagData, setTagData] = useState<any>({})
- const configName = '广告列表New'
- const ref = useRef(null)
- const size = useSize(ref)
- const [scrollLeft, setScrollLeft] = useState<number>(0)
- /************************/
- useEffect(() => {
- getList()
- }, [filterForm, queryForm])
- const getList = () => {
- let message = localStorage.getItem(`myAdMonitorConfig1.0.0_${configName}`)
- if (message) {
- message = JSON.parse(message)
- }
- let columns: string[] = []
- if (message && Array.isArray(message)) {
- message.forEach((item: { serverIndex: any; dataIndex: string; }) => {
- if (!['cz', 'cost_speed'].includes(item.dataIndex)) {
- columns.push(item?.serverIndex || 'adgroup_data.' + item.dataIndex)
- }
- })
- } else {
- planAdConfig.forEach((item: any) => {
- item?.data?.forEach((d: { default: any, serverIndex: string, dataIndex: string }) => {
- if (d.default && !['cz', 'cost_speed'].includes(d.dataIndex)) {
- columns.push(d?.serverIndex || 'adgroup_data.' + d.dataIndex)
- }
- })
- })
- }
- getAdList.run({ ...queryForm, ...filterForm, columns })
- }
- useEffect(() => {
- getPutUser.run({ userId })
- }, [userId])
- // 同步
- const sync = useCallback(() => {
- let arr = [...new Set(selectedRows?.map(item => item.accountId))]
- syncAjax.run({ accountIdList: arr }).then(res => {
- res && getAdList.refresh()
- res ? message.success('同步成功!') : message.error('同步失败!')
- })
- }, [getAdList, selectedRows])
- /** 删除 */
- const deleteHandle = (type: 0 | 1, adgroupId?: number) => {
- const hide = message.loading('删除中。。。', 0)
- delListAdqAdgroups.run({ adgroupIds: type === 1 ? selectedRows.map(item => item.adgroup_id) : [adgroupId] }).then(res => {
- hide()
- message.success('删除成功')
- setSelectedRows([])
- getAdList.refresh()
- }).catch(() => hide())
- }
- /** 修改排期出价 */
- const editScheduling = () => {
- setUpdate({ visible: true, title: '批量修改' })
- }
- /** 修改排期出价 */
- const editDeepConversion = () => {
- setUpdate({ visible: true, title: '批量修改深度优化' })
- }
- // 单个启停
- const onChange = () => {
- getAdList.refresh()
- setSelectedRows([])
- }
- // 批量启停
- const adStatus = (type: 'play' | 'suspend') => {
- let params: any = {}
- if (type === 'play') {
- params.configuredStatus = 'AD_STATUS_NORMAL'
- params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, adgroup_id: number }) => item.configuredStatus === 'AD_STATUS_SUSPEND').map(item => item.adgroup_id)
- } else {
- params.configuredStatus = 'AD_STATUS_SUSPEND'
- params.adgroupIds = selectedRows.filter((item: { configuredStatus: string, adgroup_id: number }) => item.configuredStatus === 'AD_STATUS_NORMAL').map(item => item.adgroup_id)
- }
- if (params.adgroupIds.length === 0) {
- message.warn(`所以账号都是${type === 'play' ? '启动' : '暂停'}状态,无需${type === 'play' ? '启动' : '暂停'}操作`)
- return
- }
- editAdqAdgroupsData.run(params).then(res => {
- message.success(`${type === 'play' ? '启动' : '暂停'}成功: ${res.success},失败: ${res.fail}`)//
- if (res?.fail) {
- notification.error({
- message: `${type === 'play' ? '启动' : '暂停'}失败`,
- description: `成功: ${res.success},修改失败${res.fail}条,失败的请到任务列表查看`,
- duration: 0
- });
- }
- getAdList.refresh()
- setSelectedRows([])
- })
- }
- //同步广告
- const syncAd = useCallback(() => {
- const hide = message.loading('同步中。。。', 0)
- putAdqAdgroupsSyncBatchApi.run({ adgroupIds: selectedRows?.map(item => item.adgroup_id) }).then(res => {
- hide()
- if (res) {
- message.success('同步成功!')
- getAdList.refresh()
- }
- }).catch(() => hide())
- }, [selectedRows])
- // 批量复制
- const copyHandle = () => {
- setCopyData({ visible: true })
- }
- const handleSave = (row: any) => {
- const hide = message.loading(`广告“${row.adgroup_id}”广告名称修改成<${row.adgroup_name}>,修改中`, 0, () => {
- message.success('修改成功');
- });
- editAdqAdgroups.run({ adgroupIds: [row.adgroup_id], adgroupName: row.adgroup_name }).then(res => {
- message.success('修改广告名称成功')
- getAdList.refresh()
- hide()
- })
- }
- const handleSaveDaily = (row: any) => {
- console.log('row--->', row)
- const hide = message.loading(`广告“${row.adgroup_id}”广告预算修改成<${row.daily_budget}元>,修改中`, 0, () => {
- message.success('修改成功');
- });
- editAdqAdgroups.run({ adgroupIds: [row.adgroup_id], dailyBudget: row.daily_budget * 100 }).then(res => {
- message.success('修改广告预算成功')
- getAdList.refresh()
- hide()
- })
- }
- const details = (data: any) => {
- setDetailData(data)
- setDetailShow(true)
- }
- // 设置人群包
- const setRqb = () => {
- const { accountId } = selectedRows[0]
- setAccountCreateLogs([{ id: accountId, adAccountId: accountId }])
- setCpVisible(true)
- }
- // 确认提交人群包
- const handleRqb = (value: any[]) => {
- if ((value[0]?.customAudienceList && value[0]?.customAudienceList?.length > 0) || (value[0]?.excludedCustomAudienceList && value[0]?.excludedCustomAudienceList?.length > 0)) {
- let { adAccountId, customAudienceList = [], excludedCustomAudienceList = [] } = value[0]
- let adgroupIds = selectedRows.map((item: { adgroup_id: number }) => item.adgroup_id)
- let customAudienceIds = customAudienceList.map((item: { id: number }) => item.id)
- let excludedCustomAudienceIds = excludedCustomAudienceList.map((item: { id: number }) => item.id)
- const hide = message.loading('正在修改。。。', 0)
- setAccountCreateLogs([])
- setCpVisible(false)
- let params: any = { adAccountId, adgroupIds };
- if (excludedCustomAudienceIds.length > 0) {
- params['excludedCustomAudienceIds'] = excludedCustomAudienceIds
- }
- if (customAudienceIds?.length > 0) {
- params['customAudienceIds'] = customAudienceIds
- }
- putModifyCustomAudience.run(params).then(res => {
- hide()
- setSelectedRows([])
- message.success('修改成功,请到腾讯广告平台查看')
- }).catch(err => hide())
- } else {
- message.error('请选择用户群')
- }
- }
- useEffect(() => {
- const headerBodyScroll = (e: any) => {
- let el = document.querySelector(`.expandClassname .expendTable .ant-table-body`);
- if (el) {
- setScrollLeft(e.target.scrollLeft)
- }
- }
- document.querySelector(`.expandClassname .expendTable .ant-table-body`)?.addEventListener('scroll', headerBodyScroll);
- () => {
- document.querySelector(`.expandClassname .expendTable .ant-table-body`)?.removeEventListener('scroll', headerBodyScroll);
- }
- }, [])
- const log = (value: any) => {
- setAccountIdRule(value.account_id)
- setAdgroupId(value.adgroup_id)
- setAdgroupName(value.adgroup_name)
- setLogVisible(true)
- }
- const handleTag = (value: any) => {
- setTagData(value)
- setTagVisible(true)
- }
- const delTag = (value: any) => {
- delUserTag.run({ accountId: value.account_id, adgroupId: value.adgroup_id }).then(res => {
- if (res) {
- message.success('删除成功')
- getAdList.refresh()
- }
- })
- }
- return <div>
- {/* 打标签 */}
- {tagVisible && <PlanTag
- visible={tagVisible}
- data={tagData}
- onClose={() => setTagVisible(false)}
- onChange={() => {
- getAdList.refresh()
- setTagVisible(false)
- }}
- />}
- {/* 修改广告 */}
- {update.visible && <UpdateAd
- {...update}
- selectedRows={selectedRows}
- onChange={() => {
- setUpdate({ visible: false, title: '' })
- getAdList.refresh()
- setSelectedRows([])
- }}
- onClose={() => { setUpdate({ visible: false, title: '' }) }}
- />}
- {/* 复制广告 */}
- {copyData.visible && <Copy selectedRows={selectedRows} {...copyData} onClose={() => setCopyData({ visible: false })} onChange={() => { setCopyData({ visible: false }); getAdList.refresh(); setSelectedRows([]) }} />}
- <Row gutter={[6, 6]} align='middle' style={{ marginBottom: 10 }}>
- <FilterQuery
- queryForm={queryForm}
- setQueryForm={setQueryForm}
- onChange={(value) => {
- setFilterForm({ ...value, pageNum: 1 })
- }}
- />
- </Row>
- <div ref={ref} className='expandClassname'>
- <TableData
- refreshData={getList}
- isCard={false}
- className='expendTable'
- columns={() => tablePlanConfig(onChange, details, handleSave, handleSaveDaily, log, handleTag, delTag)}
- ajax={getAdList}
- syncAjax={sync}
- fixed={{ left: 2, right: 4 }}
- dataSource={getAdList?.data?.data?.records}
- loading={getAdList?.loading || syncAjax?.loading}
- scroll={{ y: 560 }}
- total={getAdList?.data?.data?.total}
- page={getAdList?.data?.data?.current}
- pageSize={getAdList?.data?.data?.size}
- myKey={'adgroup_id'}
- gutter={[0, 10]}
- config={planAdConfig}
- configName={configName}
- rowClassName={(record) => {
- if (record?.tag_value === 100) {
- return 'row_error'
- }else if (record?.tag_value === 90) {
- return 'row_warning'
- } else {
- return ''
- }
- }}
- leftChild={<Space direction='vertical'>
- <Row gutter={[10, 10]} align='middle'>
- <Col>
- <Switch checkedChildren="普通" unCheckedChildren="ROI" checked={model} onChange={(checked) => { setModel(checked); setSelectedRows([]) }} style={model ? {} : { background: '#67c23a' }} />
- </Col>
- {!model && <Col><Button type='primary' icon={<TransactionOutlined />} disabled={selectedRows.length === 0} onClick={editDeepConversion}>修改深度优化ROI</Button></Col>}
- <Col><Button type='primary' style={{ background: '#1890ff' }} icon={<CopyOutlined />} disabled={selectedRows.length === 0} onClick={copyHandle}>复制</Button></Col>
- <Col><Button type='primary' style={{ background: '#67c23a', borderColor: '#67c23a' }} loading={editAdqAdgroupsData.loading} icon={<PlayCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('play')}>启动</Button></Col>
- <Col><Button type='primary' style={{ background: '#e6a23c', borderColor: '#e6a23c' }} loading={editAdqAdgroupsData.loading} icon={<PauseCircleOutlined />} disabled={selectedRows.length === 0} onClick={() => adStatus('suspend')}>暂停</Button></Col>
- <Col><SetEarlyWarning selectedRows={selectedRows} onChange={() => getAdList.refresh()} /></Col>
- <Col>
- <Dropdown overlay={<Menu
- onClick={(e) => {
- switch (e.key) {
- case '1':
- editScheduling()
- break
- case '2':
- setRqb()
- break
- case '3':
- syncAd()
- break
- case '4':
- Modal.confirm({
- title: '删除',
- content: '确定删除?',
- icon: <ExclamationCircleOutlined />,
- okType: 'danger',
- onOk() {
- deleteHandle(1)
- }
- });
- break
- }
- }}
- items={[
- {
- key: '1',
- disabled: selectedRows.length === 0,
- label: <Button type="link" size='small' style={{ padding: 0 }} icon={<FieldTimeOutlined />} disabled={selectedRows.length === 0}>修改排期出价名称</Button>,
- },
- {
- key: '2',
- disabled: selectedRows.length > 0 ? !selectedRows.every((item: { accountId: number }) => item.accountId === selectedRows[0].accountId) : true,
- label: <Button type="link" size='small' style={{ padding: 0 }} icon={<FormOutlined />} loading={putModifyCustomAudience.loading} disabled={selectedRows.length > 0 ? !selectedRows.every((item: { accountId: number }) => item.accountId === selectedRows[0].accountId) : true}>
- 修改人群包
- <Tooltip title="2023/4/20 16:20:00刷新页面后平台创建的广告可修改,或者其它平台使用定向包创建广告可用">
- <QuestionCircleOutlined />
- </Tooltip>
- </Button>,
- },
- {
- key: '3',
- disabled: selectedRows.length === 0,
- label: <Button type="link" size='small' style={{ padding: 0 }} loading={putAdqAdgroupsSyncBatchApi.loading} icon={<SyncOutlined />} disabled={selectedRows.length === 0}>同步广告</Button>,
- },
- {
- key: '4',
- disabled: selectedRows.length === 0,
- label: <Button danger type="link" size='small' style={{ padding: 0 }} loading={delListAdqAdgroups.loading} icon={<DeleteOutlined />} disabled={selectedRows.length === 0}>删除</Button>,
- },
- ]} />}>
- <a onClick={(e) => e.preventDefault()}>
- <Space>
- 更多
- <DownOutlined />
- </Space>
- </a>
- </Dropdown>
- </Col>
- <Col>
- <Button type='dashed' onClick={() => { setCzjlShow(true) }}>操作记录</Button>
- </Col>
- </Row>
- </Space>}
- rowSelection={{
- selectedRowKeys: selectedRows.map(item => item.adgroup_id.toString()),
- getCheckboxProps: (record: any) => ({
- disabled: model ?
- record.status === 'STATUS_DELETED' :
- record.status === 'STATUS_DELETED' ||
- !(!model &&
- JSON.parse(record?.deep_conversion_spec_json)?.deepConversionWorthSpec?.goal === 'GOAL_1DAY_PURCHASE_ROAS'
- )
- }),
- onSelect: (record: { adgroup_id: number, mpName: string }, selected: boolean) => {
- if (selected) {
- selectedRows.push({ ...record })
- setSelectedRows([...selectedRows])
- } else {
- let newSelectAccData = selectedRows.filter((item: { adgroup_id: number }) => item.adgroup_id !== record.adgroup_id)
- setSelectedRows([...newSelectAccData])
- }
- },
- onSelectAll: (selected: boolean, selectedRowss: { adgroup_id: number }[], changeRows: { adgroup_id: number }[]) => {
- if (selected) {
- let newSelectAccData = [...selectedRows]
- changeRows.forEach((item: { adgroup_id: number }) => {
- let index = newSelectAccData.findIndex((ite: { adgroup_id: number }) => ite.adgroup_id === item.adgroup_id)
- if (index === -1) {
- newSelectAccData.push({ ...item })
- }
- })
- setSelectedRows([...newSelectAccData])
- } else {
- let newSelectAccData = selectedRows.filter((item: { adgroup_id: number }) => {
- let index = changeRows.findIndex((ite: { adgroup_id: number }) => ite.adgroup_id === item.adgroup_id)
- if (index !== -1) {
- return false
- } else {
- return true
- }
- })
- setSelectedRows([...newSelectAccData])
- }
- }
- }}
- onChange={(props: any) => {
- let { sortData, pagination } = props
- let { current, pageSize } = pagination
- let newQueryForm = JSON.parse(JSON.stringify(queryForm))
- newQueryForm.pageNum = current
- newQueryForm.pageSize = pageSize
- if (sortData && JSON.stringify('sortData') !== '{}') {
- let { field, order } = sortData // descend 降序 大到小 ascend 升序 小到大
- if (order) {
- newQueryForm.sortColumn = field
- newQueryForm.sortAsc = order === 'ascend'
- } else {
- Object.keys(newQueryForm).forEach(key => {
- if (key === 'sortColumn' || key === 'sortAsc') {
- delete newQueryForm[key]
- }
- })
- }
- } else {
- Object.keys(newQueryForm).forEach(key => {
- if (key === 'sortField' || key === 'sort') {
- delete newQueryForm[key]
- }
- })
- }
- setQueryForm({ ...newQueryForm })
- }}
- expandedRowRender={(data) => <AdExpandedRowRender data={data} scrollLeft={scrollLeft} width={size?.width} />}
- />
- </div>
- {detailShow && <Details visible={detailShow} onClose={() => { setDetailShow(false) }} data={detailData} />}
- {czjlShow && <Modal
- visible={czjlShow}
- onCancel={() => { setCzjlShow(false) }}
- onOk={() => { setCzjlShow(false) }}
- width={1200}
- footer={null}
- title={"广告操作记录"}
- >
- <Log {...props} />
- </Modal>}
- {cpVisible && <CrowdPackModal visible={cpVisible} data={accountCreateLogs} onClose={() => setCpVisible(false)} onChange={(e) => { handleRqb(e) }} />}
- {logVisible && <RuleAccountLog accountId={accountIdRule} adgroupName={adgroupName} adgroupId={adgroupId} visible={logVisible} onClose={() => setLogVisible(false)} />}
- </div>
- }
- export default AdPlanList
|