|
@@ -1,4 +1,4 @@
|
|
|
-import { Card, Drawer, Space, Spin, Typography } from "antd"
|
|
|
+import { Button, Card, Drawer, Empty, Space, Spin, Table, Tabs, Typography, message } from "antd"
|
|
|
import React, { useEffect, useState } from "react"
|
|
|
import '../index.less'
|
|
|
import style from './index.less'
|
|
@@ -7,7 +7,11 @@ import Material from "./Material";
|
|
|
import MaterialText from "./MaterialText";
|
|
|
import PageList from "./PageList";
|
|
|
import { DispatchAddelivery } from ".";
|
|
|
-const { Text } = Typography;
|
|
|
+import { CheckOutlined, SearchOutlined } from "@ant-design/icons";
|
|
|
+import WechatAccount from "../../components/WechatAccount";
|
|
|
+import { cartesianProduct } from "@/utils/utils";
|
|
|
+import { columnsAddDynamic } from "./tableConfig";
|
|
|
+const { Text, Title } = Typography;
|
|
|
|
|
|
/**
|
|
|
* 新增创意
|
|
@@ -17,19 +21,131 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
|
|
|
/****************************************/
|
|
|
const [addelivery, setAddelivery] = useState<PULLIN.AddeliveryProps>({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {} })
|
|
|
+ const { adgroups } = addelivery
|
|
|
const [wechatVisible, setWechatVisible] = useState<boolean>(false) // 选择微信公众号弹窗控制
|
|
|
const [materialData, setMaterialData] = useState<any>({}) // 素材数据
|
|
|
const [textData, setTextData] = useState<any>({})
|
|
|
const [accountCreateLogs, setAccountCreateLogs] = useState<PULLIN.AccountCreateLogsProps[]>([]) // 账户
|
|
|
const [tableData, setTableData] = useState<any>({})
|
|
|
+ const [activeKey, setActiveKey] = useState<string>()
|
|
|
+ const [dynamicCount, setDynamicCount] = useState<number>(0)
|
|
|
/****************************************/
|
|
|
|
|
|
useEffect(() => {
|
|
|
-
|
|
|
- }, [])
|
|
|
+ if (adData?.length > 0) {
|
|
|
+ const { siteSet, marketingCarrierType, marketingGoal, marketingTargetType, sceneSpec, automaticSiteEnabled } = adData[0]
|
|
|
+ setAddelivery({ ...addelivery, adgroups: { marketingGoal, marketingCarrierType, siteSet, automaticSiteEnabled, sceneSpec, marketingAssetOuterSpec: { marketingTargetType } } })
|
|
|
+ let AccountSet = new Set(adData.map(item => item.accountId))
|
|
|
+ setAccountCreateLogs([...AccountSet].map(accountId => ({ accountId })))
|
|
|
+ }
|
|
|
+ }, [adData])
|
|
|
|
|
|
const clearData = () => {
|
|
|
- setTableData({})
|
|
|
+ setTableData([])
|
|
|
+ }
|
|
|
+
|
|
|
+ const preview = () => {
|
|
|
+ console.log('addelivery------>', addelivery)
|
|
|
+ console.log('accountCreateLogs------>', accountCreateLogs)
|
|
|
+ if (accountCreateLogs?.length === 0) {
|
|
|
+ message.error('请先选择媒体账户')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const { adgroups, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS } = addelivery
|
|
|
+ if (!(adgroups && Object.keys(adgroups).length)) {
|
|
|
+ message.error('请先配置广告信息')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ((['MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT'].includes(adgroups?.marketingAssetOuterSpec?.marketingTargetType) || adgroups?.marketingCarrierType === 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT') && !accountCreateLogs?.some(item => item?.wechatChannelList?.length)) {
|
|
|
+ message.error('请先选择公众号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!(dynamic && Object.keys(dynamic).length)) {
|
|
|
+ message.error('请先配置创意')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ((materialData && Object.keys(materialData).length) && !(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length)) {
|
|
|
+ message.error('请先配置创意素材')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ((textData && Object.keys(textData).length) && !(dynamicCreativesTextDTOS && Object.keys(dynamicCreativesTextDTOS).length)) {
|
|
|
+ message.error('请先配置创意文案')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!accountCreateLogs?.some(item => item?.pageList?.length)) {
|
|
|
+ message.error('请先选择落地页')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let newTableData = {}, newDynamicCount = 0
|
|
|
+ adData.forEach((ad, index) => {
|
|
|
+ let item = accountCreateLogs.find(a => a.accountId === ad.accountId) as PULLIN.AccountCreateLogsProps
|
|
|
+ let textType = dynamicCreativesTextDTOS.type
|
|
|
+ let textDto = dynamicCreativesTextDTOS?.dynamicCreativesTextDetailDTOList || []
|
|
|
+ let textDtoLenth = textDto.length
|
|
|
+ let dynamicGroupLength = dynamicMaterialDTos?.dynamicGroup?.length || 0
|
|
|
+ let data = [{
|
|
|
+ id: ad.adgroupId + '_' + index,
|
|
|
+ pageListDto: item.pageList, // 落地页
|
|
|
+ adgroupsDto: ad,
|
|
|
+ dynamicDto: dynamic, // 创意信息
|
|
|
+ rowSpan: ([910].includes(dynamic.creativeTemplateId) ? item.pageList?.length : (textType === 3 ? textDtoLenth * dynamicGroupLength : dynamicGroupLength)) || 1
|
|
|
+ }]
|
|
|
+
|
|
|
+ let newData: any[] = []
|
|
|
+ if ([910].includes(dynamic.creativeTemplateId)) {
|
|
|
+ newData = cartesianProduct(data, item.pageList).map((item, index) => {
|
|
|
+ let [d1, pageList, num] = item
|
|
|
+ return {
|
|
|
+ ...d1,
|
|
|
+ id: d1.id + '_' + index,
|
|
|
+ pageListDto: [pageList],
|
|
|
+ dynamicDto: {
|
|
|
+ ...d1.dynamicDto,
|
|
|
+ dynamicCreativeName: d1.dynamicDto.dynamicCreativeName + num
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ let newDynamicGroup: any = dynamicMaterialDTos?.dynamicGroup || []
|
|
|
+ if (newDynamicGroup.length > 0 && [0, 1, 2, 3].includes(textType)) {
|
|
|
+ if (textType === 0) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any) => ({ ...item, textDto: textDto?.[0] }))
|
|
|
+ } else if (textType === 1) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index] }))
|
|
|
+ } else if (textType === 2) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index % textDtoLenth] }))
|
|
|
+ } else if (textType === 3) {
|
|
|
+ newDynamicGroup = cartesianProduct(newDynamicGroup, textDto || [{}]).map((item) => {
|
|
|
+ let [dynamicGroup, textDtoData] = item
|
|
|
+ return {
|
|
|
+ ...dynamicGroup as any,
|
|
|
+ textDto: textDtoData
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
|
|
|
+ let [d1, group, num] = item
|
|
|
+ return {
|
|
|
+ ...d1,
|
|
|
+ id: d1.id + '_' + index,
|
|
|
+ dynamicGroup: group,
|
|
|
+ textDto: (group as any)?.textDto,
|
|
|
+ dynamicDto: {
|
|
|
+ ...d1.dynamicDto,
|
|
|
+ dynamicCreativeName: d1.dynamicDto.dynamicCreativeName + '_' + num
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ newDynamicCount += newData.length
|
|
|
+ newTableData[ad.adgroupId] = newData
|
|
|
+ })
|
|
|
+ setDynamicCount(newDynamicCount)
|
|
|
+ setActiveKey(adData?.[0].adgroupId?.toString())
|
|
|
+ console.log('newTableData-->', newTableData)
|
|
|
+ setTableData(newTableData)
|
|
|
}
|
|
|
|
|
|
return <Drawer
|
|
@@ -41,13 +157,14 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
>
|
|
|
<Space direction="vertical" style={{ width: '100%' }}>
|
|
|
<Spin spinning={false}>
|
|
|
-
|
|
|
- <Text type="danger" style={{ marginBottom: 5 }}>选择的广告必须与当前已选广告的营销目的、营销载体、推广内容、广告版位一致</Text>
|
|
|
<Card
|
|
|
size="small"
|
|
|
title={<div className={style.cardTitle}>配置区</div>}
|
|
|
className={style.createAd}
|
|
|
>
|
|
|
+ <Space wrap>
|
|
|
+ {(adgroups?.marketingAssetOuterSpec?.marketingTargetType === 'MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT' || adgroups?.marketingCarrierType === 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT') && <Button type="primary" danger={!accountCreateLogs?.some(item => item?.wechatChannelList?.length)} onClick={() => { setWechatVisible(true) }}>{accountCreateLogs?.some(item => item?.wechatChannelList?.length) ? <>重新选择公众号 <CheckOutlined style={{ color: '#FFFFFF' }} /></> : '请选择公众号'}</Button>}
|
|
|
+ </Space>
|
|
|
<div className={style.settingsBody}>
|
|
|
<div className={style.settingsBody_content}>
|
|
|
<DispatchAddelivery.Provider
|
|
@@ -69,10 +186,12 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
</div>
|
|
|
<div className={style.detail}>
|
|
|
<div className={style.detail_body}>
|
|
|
-
|
|
|
- </div>
|
|
|
- <div className={style.detail_footer}>
|
|
|
-
|
|
|
+ <Title level={5} style={{ fontSize: 12 }}>已选广告</Title>
|
|
|
+ {adData?.map(item => {
|
|
|
+ return <div key={item.adgroupId}>
|
|
|
+ <div className={style.text}><Text ellipsis={{ tooltip: true }}>{item.adgroupName}</Text></div>
|
|
|
+ </div>
|
|
|
+ })}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -90,8 +209,57 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
</DispatchAddelivery.Provider>
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
+ <Space className={style.bts} wrap>
|
|
|
+ <Button type='primary' onClick={preview}><SearchOutlined />预览广告</Button>
|
|
|
+ </Space>
|
|
|
+
|
|
|
+ {/* 选择公众号 */}
|
|
|
+ {wechatVisible && <WechatAccount
|
|
|
+ visible={wechatVisible}
|
|
|
+ data={accountCreateLogs}
|
|
|
+ onClose={() => setWechatVisible(false)}
|
|
|
+ onChange={(e) => {
|
|
|
+ setAccountCreateLogs(e);
|
|
|
+ setWechatVisible(false);
|
|
|
+ clearData()
|
|
|
+ }}
|
|
|
+ />}
|
|
|
</Card>
|
|
|
</Spin>
|
|
|
+
|
|
|
+ <Card
|
|
|
+ className={style.createAd}
|
|
|
+ >
|
|
|
+ {activeKey && tableData && Object.keys(tableData)?.length > 0 ? <div className={style.cardBody}>
|
|
|
+ <Tabs
|
|
|
+ onChange={(e) => { setActiveKey(e) }}
|
|
|
+ type="card"
|
|
|
+ activeKey={activeKey}
|
|
|
+ tabBarExtraContent={<Space>
|
|
|
+ <span>创意总数:{dynamicCount}</span>
|
|
|
+ <Button type='primary'>提交创建</Button>
|
|
|
+ </Space>}
|
|
|
+ >
|
|
|
+ {adData.map(item => <Tabs.TabPane tab={item.adgroupId} key={item.adgroupId} />)}
|
|
|
+ </Tabs>
|
|
|
+ <div className={style.content} style={{ marginTop: 20 }}>
|
|
|
+ <Table
|
|
|
+ columns={columnsAddDynamic()}
|
|
|
+ dataSource={tableData[activeKey]}
|
|
|
+ size="small"
|
|
|
+ bordered
|
|
|
+ scroll={{ x: 1200 }}
|
|
|
+ rowKey={'id'}
|
|
|
+ pagination={{
|
|
|
+ defaultPageSize: 50
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div> : <div style={{ minHeight: 400, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
|
|
+ <Empty description="请先完成模块配置后,再预览广告计划" />
|
|
|
+ </div>}
|
|
|
+ </Card>
|
|
|
</Space>
|
|
|
</Drawer>
|
|
|
}
|