addDynamic.tsx 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. import { Button, Card, Drawer, Empty, Modal, Popconfirm, Space, Spin, Table, Tabs, Typography, message } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import '../index.less'
  4. import style from './index.less'
  5. import Dynamic from "./Dynamic";
  6. import Material from "./Material";
  7. import MaterialText from "./MaterialText";
  8. import PageList from "./PageList";
  9. import { DispatchAddelivery } from ".";
  10. import { CheckOutlined, SearchOutlined } from "@ant-design/icons";
  11. import WechatAccount from "../../components/WechatAccount";
  12. import { cartesianProduct, distributeArray, processData, splitArrayIntoRandomChunks } from "@/utils/utils";
  13. import { columnsAddDynamic } from "./tableConfig";
  14. import { useAjax } from "@/Hook/useAjax";
  15. import { createDynamicTaskApi } from "@/services/adqV3";
  16. import TacticsS from "./TacticsS";
  17. import VideoChannel from "../../components/VideoChannel";
  18. import { getCreativeDetailsApi } from "@/services/adqV3/global";
  19. const { Text, Title } = Typography;
  20. /**
  21. * 新增创意
  22. * @returns
  23. */
  24. const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose, adData: selectData, tactics, putInType }) => {
  25. /****************************************/
  26. const [addelivery, setAddelivery] = useState<PULLIN.AddeliveryProps>({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {}, mediaType: 0 })
  27. const { adgroups, dynamic } = addelivery
  28. const { marketingAssetOuterSpec, marketingCarrierType, marketingGoal, marketingSubGoal, siteSet, automaticSiteEnabled, sceneSpec } = addelivery.adgroups
  29. const { deliveryMode, creativeTemplateId, dynamicCreativeSwitch } = addelivery.dynamic
  30. const [wechatVisible, setWechatVisible] = useState<boolean>(false) // 选择微信公众号弹窗控制
  31. const [channelsProfileVisible, setChannelsProfileVisible] = useState<boolean>(false) // 选择微信公众号弹窗控制
  32. const [materialData, setMaterialData] = useState<any>({}) // 素材数据
  33. const [textData, setTextData] = useState<any>({})
  34. const [accountCreateLogs, setAccountCreateLogs] = useState<PULLIN.AccountCreateLogsProps[]>([]) // 账户
  35. const [tableData, setTableData] = useState<any>({})
  36. const [activeKey, setActiveKey] = useState<string>()
  37. const [dynamicCount, setDynamicCount] = useState<number>(0)
  38. const [adData, setAdData] = useState<any[]>(selectData)
  39. const [adLength, setAdLength] = useState<number>(0)
  40. const [adDataGroup, setAdDataGroup] = useState<{ [x: number]: any[] }>({})
  41. const [creativeTemplateAppellation, setCreativeTemplateAppellation] = useState<string>()
  42. const [creativeTemplateStyle, setCreativeTemplateStyle] = useState<string>()
  43. const getCreativeDetails = useAjax((params) => getCreativeDetailsApi(params))
  44. const createDynamicTask = useAjax((params) => createDynamicTaskApi(params))
  45. /****************************************/
  46. // 获取广告总数
  47. useEffect(() => {
  48. if (adData && adData?.length > 0) {
  49. setAdLength(adData.length)
  50. }
  51. }, [adData])
  52. useEffect(() => {
  53. if (creativeTemplateId) {
  54. let params: any = {
  55. marketingGoal,
  56. marketingTargetType: marketingAssetOuterSpec.marketingTargetType,
  57. marketingCarrierType,
  58. deliveryMode,
  59. creativeTemplateId,
  60. wechatSceneSpecPosition: sceneSpec?.wechatPosition,
  61. dynamicCreativeType: (deliveryMode === 'DELIVERY_MODE_COMPONENT' && !dynamicCreativeSwitch) ? 'DYNAMIC_CREATIVE_TYPE_PROGRAM' : 'DYNAMIC_CREATIVE_TYPE_COMMON'
  62. }
  63. if (automaticSiteEnabled) {
  64. params.automaticSiteEnabled = automaticSiteEnabled
  65. } else {
  66. params.siteSet = siteSet
  67. }
  68. params.taskType = putInType
  69. if (putInType === 'GAME') {
  70. params.marketingSubGoal = marketingSubGoal
  71. }
  72. getCreativeDetails.run(params).then(res => {
  73. if (res?.adcreativeTemplateStructAdpermits?.length > 0) {
  74. let adcreativeTemplateStructAdpermits = res?.adcreativeTemplateStructAdpermits[0]
  75. setCreativeTemplateAppellation(adcreativeTemplateStructAdpermits.creativeTemplateAppellation)
  76. setCreativeTemplateStyle(adcreativeTemplateStructAdpermits.creativeTemplateStyle)
  77. let creativeComponents = adcreativeTemplateStructAdpermits?.creativeComponents || []
  78. let result = processData(creativeComponents);
  79. let newMaterialData: any = {};
  80. let newTextData: any = {};
  81. Object.keys(result).forEach(key => {
  82. let data = result[key]
  83. if ((key === 'image_list' || key === 'short_video' || key === 'video' || key === 'image' || key === 'element_story') && data.required) {
  84. newMaterialData[key] = data
  85. } else if (key === 'title' || (data.required && key === 'description')) {
  86. newTextData[key] = data
  87. }
  88. })
  89. setMaterialData(newMaterialData)
  90. setTextData(newTextData)
  91. }
  92. })
  93. }
  94. }, [creativeTemplateId, deliveryMode, dynamicCreativeSwitch, marketingGoal, marketingAssetOuterSpec, marketingCarrierType, siteSet, sceneSpec?.wechatPosition, automaticSiteEnabled, putInType])
  95. useEffect(() => {
  96. if (adData && adData.length) {
  97. let adDataGroup: { [x: number]: any[] } = {}
  98. adData.forEach(item => {
  99. let accountId = item.accountId
  100. if (adDataGroup?.[accountId]?.length) {
  101. adDataGroup[accountId].push(item)
  102. } else {
  103. adDataGroup[accountId] = [item]
  104. }
  105. })
  106. setAdDataGroup(adDataGroup)
  107. }
  108. }, [adData])
  109. useEffect(() => {
  110. if (tactics) {
  111. const {
  112. adData,
  113. addelivery,
  114. accountCreateLogs,
  115. materialData,
  116. textData
  117. } = JSON.parse(tactics.strategyValue)
  118. setAccountCreateLogs(accountCreateLogs)
  119. if (addelivery?.adgroups) {
  120. if (addelivery?.adgroups?.smartDeliveryPlatform) {
  121. addelivery.adgroups.deliveryMethod = 'SMART'
  122. } else {
  123. addelivery.adgroups.deliveryMethod = 'NORMAL'
  124. }
  125. }
  126. setAddelivery(addelivery)
  127. setAdData(adData)
  128. setMaterialData(materialData)
  129. setTextData(textData)
  130. } else if (selectData?.length > 0) {
  131. const { siteSet, marketingCarrierType, marketingGoal, marketingTargetType, sceneSpec, automaticSiteEnabled, marketingSubGoal, smartDeliveryPlatform } = selectData[0]
  132. let adgroups: Record<string, any> = {}
  133. if (smartDeliveryPlatform) {
  134. adgroups = { marketingGoal, marketingSubGoal, marketingCarrierType, automaticSiteEnabled: true, marketingAssetOuterSpec: { marketingTargetType }, deliveryMethod: 'SMART' }
  135. } else {
  136. adgroups = { marketingGoal, marketingSubGoal, marketingCarrierType, siteSet, automaticSiteEnabled, sceneSpec, marketingAssetOuterSpec: { marketingTargetType }, deliveryMethod: 'NORMAL' }
  137. }
  138. setAddelivery({ ...addelivery, adgroups })
  139. let AccountSet = new Set(selectData.map(item => item.accountId))
  140. setAccountCreateLogs([...AccountSet].map(accountId => ({ accountId })))
  141. }
  142. }, [selectData, tactics])
  143. const clearData = () => {
  144. setTableData([])
  145. }
  146. // 预览
  147. const preview = () => {
  148. if (accountCreateLogs?.length === 0) {
  149. message.error('请先选择媒体账户')
  150. return
  151. }
  152. const { adgroups, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS, mediaType } = addelivery
  153. if (!(adgroups && Object.keys(adgroups).length)) {
  154. message.error('请先配置广告信息')
  155. return
  156. }
  157. if (!(dynamic && Object.keys(dynamic).length)) {
  158. message.error('请先配置创意')
  159. return
  160. }
  161. if ((materialData && Object.keys(materialData).length) && !(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length)) {
  162. message.error('请先配置创意素材')
  163. return
  164. }
  165. if ((textData && Object.keys(textData).length) && !(dynamicCreativesTextDTOS && Object.keys(dynamicCreativesTextDTOS).length)) {
  166. message.error('请先配置创意文案')
  167. return
  168. }
  169. if (!accountCreateLogs?.some(item => item?.pageList?.length) && !['PAGE_TYPE_WECHAT_MINI_GAME'].includes(dynamic?.creativeComponents?.mainJumpInfo?.[0]?.value?.pageType)) {
  170. message.error('请先选择落地页')
  171. return
  172. }
  173. 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)) {
  174. message.error('请先选择公众号')
  175. return
  176. }
  177. if (dynamic?.creativeComponents?.brand?.[0]?.value?.jumpInfo?.pageType === 'PAGE_TYPE_WECHAT_CHANNELS_PROFILE' && !accountCreateLogs?.some(item => item?.videoChannelList?.length)) {
  178. message.error('请先选择视频号')
  179. return
  180. }
  181. let newTableData: any = {}, newDynamicCount = 0
  182. const textType = dynamicCreativesTextDTOS.type
  183. const textDto = dynamicCreativesTextDTOS?.dynamicCreativesTextDetailDTOList || []
  184. const textDtoLenth = textDto.length
  185. const dynamicGroupLength = dynamicMaterialDTos?.dynamicGroup?.length || 0
  186. let newDynamicGroup: any = []
  187. if (![910].includes(dynamic.creativeTemplateId)) {
  188. newDynamicGroup = dynamicMaterialDTos?.dynamicGroup || []
  189. if (newDynamicGroup.length > 0 && [0, 1, 2, 3, 4].includes(textType)) {
  190. if (textType === 0) {
  191. newDynamicGroup = newDynamicGroup.map((item: any) => ({ ...item, textDto: textDto?.[0] }))
  192. } else if (textType === 1) {
  193. newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index] }))
  194. } else if (textType === 2) {
  195. newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index % textDtoLenth] }))
  196. } else if ((textType === 3 && mediaType === 0) || (textType === 4 && mediaType === 1) || (textType === 4 && mediaType === 3)) {
  197. newDynamicGroup = cartesianProduct(newDynamicGroup, textDto || [{}]).map((item) => {
  198. let [dynamicGroup, textDtoData] = item
  199. return {
  200. ...dynamicGroup as any,
  201. textDto: textDtoData
  202. }
  203. })
  204. }
  205. }
  206. }
  207. // 创意组平均分配到广告逻辑
  208. let averageAdDynamicList: any[] = []
  209. if ((mediaType === 1 || mediaType === 2 || mediaType === 3) && newDynamicGroup.length) {
  210. const adLength = adData.length
  211. if (mediaType === 1) {
  212. if (textType === 4) {
  213. if (adLength > newDynamicGroup.length) {
  214. message.error(`创意组分配规则选择“平均分配到广告”时,创意组总数必须大于等于广告总数。当前创意组数量:${dynamicGroupLength},广告数量:${adLength}`)
  215. return
  216. }
  217. averageAdDynamicList = splitArrayIntoRandomChunks(newDynamicGroup, adLength)
  218. } else {
  219. if (adLength > dynamicGroupLength) {
  220. message.error(`创意组分配规则选择“平均分配到广告”时,创意组总数必须大于等于广告总数。当前创意组数量:${dynamicGroupLength},广告数量:${adLength}`)
  221. return
  222. }
  223. averageAdDynamicList = distributeArray(newDynamicGroup, adLength)
  224. }
  225. } else if (mediaType === 2) {
  226. if (adLength < dynamicGroupLength) {
  227. message.error(`创意组分配规则选择“顺序分配到广告”时,创意组总数必须小于等于广告总数。当前创意组数量:${dynamicGroupLength},广告数量:${adLength}`)
  228. return
  229. }
  230. } else if (mediaType === 3) {
  231. const dynamicDataLength = textType === 4 ? newDynamicGroup.length : dynamicGroupLength
  232. if (Object.keys(adDataGroup).some(key => {
  233. const adLength = adDataGroup[key as any].length
  234. if (adLength > dynamicDataLength) {
  235. message.error(`创意组分配规则选择“账号下平均分配到广告”时,创意组总数必须大于等于每个账号广告总数。当前创意组数量:${dynamicDataLength},当前账号(${key})下广告数量:${adLength}`)
  236. return true
  237. }
  238. return false
  239. })) {
  240. return
  241. }
  242. }
  243. }
  244. // 落地页平均分配判断数量
  245. if ([910].includes(dynamic.creativeTemplateId) && dynamic?.landingPageType === 1) {
  246. if (accountCreateLogs.some(item => {
  247. const total = adDataGroup[item.accountId].length
  248. const pageLength = item.pageList.length
  249. if (total > pageLength) {
  250. message.error(`当前${item.accountId}下的广告总数(${total})大于落地页总数(${pageLength}),平均分配需要落地页总数大于广告总数`)
  251. return true
  252. }
  253. return false
  254. })) {
  255. return
  256. }
  257. } else if (textType === 5) {
  258. if (dynamicGroupLength * accountCreateLogs.length !== textDtoLenth) {
  259. message.error(`创意文案配置错误,内容数量和所有创意数量对不上,所有创意数量:${dynamicGroupLength * accountCreateLogs.length},文案数量:${textDtoLenth}`)
  260. return
  261. }
  262. }
  263. if (textType === 1) {
  264. if (dynamicGroupLength !== textDtoLenth) {
  265. message.error(`当前创意文案是“创意组一一对应”模式,创意组总数(${dynamicGroupLength})要等于创意文案总数(${textDtoLenth})`)
  266. return
  267. }
  268. if (!dynamicCreativesTextDTOS.dynamicCreativesTextDetailDTOList.every((item: {}) => item && Object.keys(item).length)) {
  269. message.error('创意文案配置错误,内容空')
  270. return
  271. }
  272. }
  273. let accountIndex1 = 0, accountIndex2 = 0
  274. if (dynamic?.landingPageType === 1 && [910].includes(dynamic.creativeTemplateId)) {
  275. accountCreateLogs.forEach(item => {
  276. const adData = adDataGroup[item.accountId]
  277. const averageAdPageList: any[] = distributeArray(item.pageList, adData.length)
  278. let newData: any[] = []
  279. adData.forEach((ad, index) => {
  280. const data = [{
  281. id: ad.adgroupId + '_' + index,
  282. adgroupsDto: ad,
  283. dynamicDto: dynamic, // 创意信息
  284. }]
  285. newData = cartesianProduct(data, averageAdPageList[index]).map((item, index) => {
  286. const [d1, pageList, num] = item
  287. return {
  288. ...d1,
  289. id: d1.id + '_' + index,
  290. pageListDto: [pageList],
  291. dynamicDto: {
  292. ...d1.dynamicDto,
  293. dynamicCreativeName: d1.dynamicDto.dynamicCreativeName + num
  294. },
  295. rowSpan: index === 0 ? averageAdPageList[index].length : 0,
  296. isRowSpan: true
  297. }
  298. })
  299. newTableData[ad.adgroupId] = newData
  300. })
  301. newDynamicCount += item.pageList.length
  302. })
  303. } else {
  304. const handleDynamic = (adData: any[], averageAdDynamicList: any[]) => {
  305. adData.forEach((ad, index) => {
  306. const item = accountCreateLogs.find(a => a.accountId === ad.accountId) as PULLIN.AccountCreateLogsProps
  307. const averageAdDynamic = averageAdDynamicList?.[index]
  308. const data = [{
  309. id: ad.adgroupId + '_' + index,
  310. pageListDto: item.pageList, // 落地页
  311. adgroupsDto: ad,
  312. dynamicDto: dynamic, // 创意信息
  313. averageAdDynamic,
  314. rowSpan: ((mediaType === 1 || mediaType === 3) && textType !== 4) ? averageAdDynamic.length : ([910].includes(dynamic.creativeTemplateId) ? item.pageList?.length : (textType === 3 ? textDtoLenth * dynamicGroupLength : dynamicGroupLength)) || 1
  315. }]
  316. let newData: any[] = []
  317. if ([910].includes(dynamic.creativeTemplateId)) {
  318. newData = cartesianProduct(data, item.pageList).map((item, index) => {
  319. const [d1, pageList, num] = item
  320. return {
  321. ...d1,
  322. id: d1.id + '_' + index,
  323. pageListDto: [pageList],
  324. dynamicDto: {
  325. ...d1.dynamicDto,
  326. dynamicCreativeName: d1.dynamicDto.dynamicCreativeName + num
  327. }
  328. }
  329. })
  330. } else {
  331. if (mediaType === 1 || mediaType === 3) {
  332. data.forEach(item => {
  333. const { averageAdDynamic, ...ad } = item
  334. if (textType === 3) {
  335. const rowSpan = textDtoLenth * averageAdDynamic.length
  336. cartesianProduct(textDto, averageAdDynamic).forEach((taad: any, index) => {
  337. const [textValue, aad] = taad
  338. newData.push({
  339. ...ad,
  340. id: ad.id + '_' + index,
  341. dynamicGroup: aad,
  342. textDto: textValue,
  343. rowSpan
  344. })
  345. })
  346. } else if (textType === 4) {
  347. averageAdDynamic.forEach((aad: any, index: number) => {
  348. newData.push({
  349. ...ad,
  350. id: ad.id + '_' + index,
  351. dynamicGroup: aad,
  352. textDto: aad?.textDto,
  353. rowSpan: index === 0 ? averageAdDynamic.length : 0,
  354. isRowSpan: true
  355. })
  356. })
  357. } else {
  358. averageAdDynamic.forEach((aad: any, index: number) => {
  359. newData.push({
  360. ...ad,
  361. id: ad.id + '_' + index,
  362. dynamicGroup: aad,
  363. textDto: textType === 2 ? textDto?.[index % textDtoLenth] : textType === 5 ? textDto?.[accountIndex2] : aad?.textDto
  364. })
  365. accountIndex2 += 1
  366. })
  367. }
  368. })
  369. } else if (mediaType === 2) {
  370. data.forEach((item) => {
  371. const { averageAdDynamic, ...ad } = item
  372. if (textType === 3) {
  373. cartesianProduct(textDto, [newDynamicGroup[accountIndex1 % newDynamicGroup.length]]).forEach((taad: any) => {
  374. let [textValue, aad, index] = taad
  375. newData.push({
  376. ...ad,
  377. id: ad.id + '_' + index,
  378. dynamicGroup: aad,
  379. textDto: textValue,
  380. rowSpan: textDto.length
  381. })
  382. })
  383. } else {
  384. let { textDto: nowTextDto, ...dynamicGroup } = newDynamicGroup[accountIndex1 % newDynamicGroup.length]
  385. newData.push({
  386. ...ad,
  387. dynamicGroup,
  388. textDto: textType === 2 ? textDto?.[0] : nowTextDto,
  389. rowSpan: 1
  390. })
  391. }
  392. accountIndex1 += 1
  393. })
  394. } else {
  395. newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
  396. let [d1, group] = item
  397. return {
  398. ...d1,
  399. id: d1.id + '_' + index,
  400. dynamicGroup: group,
  401. textDto: (group as any)?.textDto
  402. }
  403. })
  404. }
  405. }
  406. newDynamicCount += newData.length
  407. newTableData[ad.adgroupId] = newData
  408. })
  409. }
  410. if (mediaType === 3) {
  411. Object.keys(adDataGroup).forEach(key => {
  412. const newAdData = adDataGroup[key as any]
  413. const adLength = newAdData.length
  414. if (textType === 4) {
  415. averageAdDynamicList = splitArrayIntoRandomChunks(newDynamicGroup, adLength)
  416. } else {
  417. averageAdDynamicList = distributeArray(newDynamicGroup, adLength)
  418. }
  419. handleDynamic(newAdData, averageAdDynamicList)
  420. })
  421. } else {
  422. handleDynamic(adData, averageAdDynamicList)
  423. }
  424. }
  425. setDynamicCount(newDynamicCount)
  426. setActiveKey(adData?.[0].adgroupId?.toString())
  427. console.log('newTableData-->', newTableData)
  428. setTableData(newTableData)
  429. }
  430. // 提交
  431. const onSubmit = () => {
  432. const { dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS, mediaType } = addelivery
  433. let dynamicMaterialDTOS = []
  434. if (dynamic.deliveryMode === 'DELIVERY_MODE_CUSTOMIZE' || dynamic?.dynamicCreativeSwitch) {
  435. if ((materialData && Object.keys(materialData).length && dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length)) {
  436. const mType = Object.keys(materialData)[0];
  437. dynamicMaterialDTOS = dynamicMaterialDTos.dynamicGroup?.map((item: any) => {
  438. if (mType === 'image') {
  439. return [{
  440. type: mType,
  441. valueJson: JSON.stringify({
  442. value: {
  443. imageUrl: item?.image_id?.url,
  444. imageId: item?.image_id?.id,
  445. materialType: item?.image_id?.materialType,
  446. accountId: item?.image_id?.accountId
  447. }
  448. })
  449. }]
  450. } else if (mType === 'image_list' || mType === 'element_story') {
  451. let key = 'image_list'
  452. if (mType === 'element_story') {
  453. key = 'element_story'
  454. }
  455. const list = item?.[key]?.map((l: any) => {
  456. return {
  457. imageUrl: l?.url,
  458. imageId: l?.id,
  459. materialType: l?.materialType,
  460. accountId: l?.accountId
  461. }
  462. })
  463. return [{
  464. type: mType,
  465. valueJson: JSON.stringify({
  466. value: {
  467. list
  468. }
  469. })
  470. }]
  471. } else if (['short_video', 'video'].includes(mType)) {
  472. const value: any = {
  473. materialType: item?.video_id?.materialType || item?.short_video1?.materialType || 0,
  474. videoUrl: item?.video_id?.url || item?.short_video1?.url,
  475. videoId: item?.video_id?.id || item?.short_video1?.id,
  476. keyFrameImageUrl: item?.video_id?.keyFrameImageUrl || item?.short_video1?.keyFrameImageUrl,
  477. accountId: item?.video_id?.accountId || item?.short_video1?.accountId,
  478. }
  479. if (item?.cover_id?.url) {
  480. value.imageUrl = item?.cover_id?.url
  481. value.imageId = item?.cover_id?.id
  482. value.materialCoverType = item?.cover_id?.materialType
  483. value.accountId = item?.cover_id?.accountId
  484. }
  485. return [{
  486. type: mType,
  487. valueJson: JSON.stringify({
  488. value
  489. })
  490. }]
  491. }
  492. return [{
  493. type: mType,
  494. valueJson: ''
  495. }]
  496. })
  497. }
  498. } else {
  499. if (dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length) {
  500. dynamicMaterialDTOS = dynamicMaterialDTos.dynamicGroup?.map((item: { list: any[] }) => {
  501. return item.list.map(l => {
  502. if (l.materialType === 4) {
  503. return {
  504. type: l?.componentSubType?.includes('IMAGE_LIST') ? 'image_list' : l?.keyFrameImageUrl ? 'video' : 'image',
  505. valueJson: JSON.stringify({
  506. componentId: l.id,
  507. componentValue: l
  508. })
  509. }
  510. }
  511. if (Array.isArray(l)) {
  512. return {
  513. type: 'image_list',
  514. valueJson: JSON.stringify({
  515. value: {
  516. list: l?.map((i: any) => {
  517. return {
  518. imageUrl: i?.url,
  519. imageId: i?.id,
  520. materialType: i?.materialType,
  521. accountId: i?.accountId
  522. }
  523. })
  524. }
  525. })
  526. }
  527. } else if (l?.url?.includes('mp4') || l?.keyFrameImageUrl) {
  528. return {
  529. type: 'video',
  530. valueJson: JSON.stringify({
  531. value: {
  532. materialType: l?.materialType,
  533. videoUrl: l?.url,
  534. videoId: l?.id,
  535. keyFrameImageUrl: l?.keyFrameImageUrl,
  536. accountId: l?.accountId
  537. }
  538. })
  539. }
  540. } else {
  541. return {
  542. type: 'image',
  543. valueJson: JSON.stringify({
  544. value: {
  545. imageUrl: l?.url,
  546. imageId: l?.id,
  547. materialType: l?.materialType,
  548. accountId: l?.accountId
  549. }
  550. })
  551. }
  552. }
  553. })
  554. })
  555. }
  556. }
  557. let accountIdParamDTOMap: any = {}
  558. accountCreateLogs.forEach(item => {
  559. const { pageList, userActionSetsList, accountId, wechatChannelList, videoChannelList } = item
  560. const userActionSetsListDto = userActionSetsList?.map((item: any) => ({ id: item?.userActionSetId, type: item?.type })) // dataSourceId
  561. const pageMap: { [x: string]: any } = {}
  562. const map: any = {
  563. userActionSetsList: userActionSetsListDto,
  564. pageList: pageList?.map((item: { pageId: any, pageName?: string }) => {
  565. pageMap[item.pageId] = item?.pageName
  566. return item.pageId
  567. })
  568. }
  569. if (Object.keys(pageMap).length) {
  570. map.pageMap = pageMap
  571. }
  572. if (wechatChannelList && (['MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT'].includes(adgroups?.marketingAssetOuterSpec?.marketingTargetType) || adgroups?.marketingCarrierType === 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT' || dynamic?.creativeComponents?.brand?.[0]?.value?.jumpInfo?.pageType === 'PAGE_TYPE_WECHAT_OFFICIAL_ACCOUNT_DETAIL')) {
  573. map.wechatChannelId = wechatChannelList?.[0]?.wechatOfficialAccountId
  574. }
  575. if (videoChannelList && dynamic?.creativeComponents?.brand?.[0]?.value?.jumpInfo?.pageType === 'PAGE_TYPE_WECHAT_CHANNELS_PROFILE') {
  576. map.videoChannelId = videoChannelList?.[0]?.wechatChannelsAccountId
  577. }
  578. accountIdParamDTOMap[accountId] = map
  579. })
  580. dynamic.dynamicCreativeType = 'DYNAMIC_CREATIVE_TYPE_COMMON'
  581. if (dynamic.deliveryMode === 'DELIVERY_MODE_COMPONENT') {
  582. dynamic.dynamicCreativeType = dynamic?.dynamicCreativeSwitch ? 'DYNAMIC_CREATIVE_TYPE_COMMON' : 'DYNAMIC_CREATIVE_TYPE_PROGRAM'
  583. }
  584. let dynamicCreativesDTO = { ...dynamic, mediaType }
  585. if (dynamic.deliveryMode === 'DELIVERY_MODE_COMPONENT' && !dynamic?.dynamicCreativeSwitch) {
  586. dynamicCreativesDTO.creativeTemplateId = 711
  587. }
  588. let params = {
  589. accountAdgroupMaps: adData.map(item => `${item.accountId},${item.adgroupId}`),
  590. dynamicCreativesDTO,
  591. dynamicCreativesTextDTOS,
  592. dynamicMaterialDTOS,
  593. accountIdParamDTOMap
  594. }
  595. createDynamicTask.run(params).then(res => {
  596. if (res) {
  597. Modal.success({
  598. content: '创建任务提交成功',
  599. bodyStyle: { fontWeight: 700 },
  600. okText: '返回上一页',
  601. closable: true,
  602. onOk: () => {
  603. onChange?.()
  604. },
  605. onCancel: () => { }
  606. })
  607. }
  608. })
  609. }
  610. return <Drawer
  611. title={<strong>添加创意</strong>}
  612. open={visible}
  613. width={1500}
  614. onClose={onClose}
  615. bodyStyle={{ backgroundColor: '#f1f4fc', padding: '0 10px 10px' }}
  616. >
  617. <Space direction="vertical" style={{ width: '100%' }}>
  618. <Spin spinning={false}>
  619. <Card
  620. size="small"
  621. title={<div className={style.cardTitle}>配置区</div>}
  622. className={style.createAd}
  623. >
  624. <Space wrap>
  625. {(adgroups?.marketingAssetOuterSpec?.marketingTargetType === 'MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT' || adgroups?.marketingCarrierType === 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT' || addelivery?.dynamic?.creativeComponents?.brand?.[0]?.value?.jumpInfo?.pageType === 'PAGE_TYPE_WECHAT_OFFICIAL_ACCOUNT_DETAIL') && <Button type="primary" danger={!accountCreateLogs?.some(item => item?.wechatChannelList?.length)} onClick={() => { setWechatVisible(true) }}>{accountCreateLogs?.some(item => item?.wechatChannelList?.length) ? <>重新选择公众号 <CheckOutlined style={{ color: '#FFFFFF' }} /></> : '请选择公众号'}</Button>}
  626. {dynamic?.creativeComponents?.brand?.[0]?.value?.jumpInfo?.pageType === 'PAGE_TYPE_WECHAT_CHANNELS_PROFILE' && <Button type="primary" danger={!accountCreateLogs?.some(item => item?.videoChannelList?.length)} onClick={() => { setChannelsProfileVisible(true) }}>{accountCreateLogs?.some(item => item?.videoChannelList?.length) ? <>重新选择视频号 <CheckOutlined style={{ color: '#FFFFFF' }} /></> : '请选择视频号'}</Button>}
  627. </Space>
  628. <div className={style.settingsBody}>
  629. <div className={style.settingsBody_content}>
  630. <DispatchAddelivery.Provider
  631. value={{
  632. addelivery,
  633. setAddelivery,
  634. accountCreateLogs,
  635. setAccountCreateLogs,
  636. materialData,
  637. setMaterialData,
  638. textData,
  639. setTextData,
  640. clearData,
  641. putInType,
  642. adLength
  643. }}>
  644. <div className={style.settingsBody_content_right}>
  645. <div className={`${style.settingsBody_content_row} ${style.row1}`}>
  646. <div className={style.title}>
  647. <span>广告信息</span>
  648. </div>
  649. <div className={style.detail}>
  650. <div className={style.detail_body}>
  651. <Title level={5} style={{ fontSize: 12 }}>已选广告</Title>
  652. {Object.keys(adDataGroup).map((key: any) => {
  653. return <div key={key}>
  654. <Title level={5} style={{ fontSize: 12 }}>{key}</Title>
  655. {adDataGroup[key]?.map((item: any) => {
  656. return <div key={item.adgroupId}>
  657. <div className={style.text}><Text ellipsis={{ tooltip: true }}>{item.adgroupName}</Text></div>
  658. </div>
  659. })}
  660. </div>
  661. })}
  662. </div>
  663. </div>
  664. </div>
  665. {/* 创意 */}
  666. <Dynamic
  667. creativeTemplateAppellation={creativeTemplateAppellation}
  668. creativeTemplateStyle={creativeTemplateStyle}
  669. />
  670. {/* 创意素材 */}
  671. <Material adData={adData} />
  672. </div>
  673. <div className={style.settingsBody_content_left}>
  674. {/* 创意文案 */}
  675. <MaterialText adDataGroup={adDataGroup} />
  676. {/* 落地页 */}
  677. <PageList adDataGroup={adDataGroup} />
  678. </div>
  679. </DispatchAddelivery.Provider>
  680. </div>
  681. </div>
  682. <Space className={style.bts} wrap>
  683. <TacticsS
  684. strategyValue={{
  685. adData: adData.map(item => {
  686. const { accountId, adgroupName, adgroupId, siteSet, marketingCarrierType, marketingGoal, marketingTargetType, sceneSpec, automaticSiteEnabled, marketingSubGoal } = item
  687. return {
  688. siteSet, marketingCarrierType, marketingGoal, marketingSubGoal, marketingTargetType, sceneSpec, automaticSiteEnabled,
  689. accountId,
  690. adgroupId,
  691. adgroupName
  692. }
  693. }),
  694. addelivery,
  695. accountCreateLogs,
  696. materialData,
  697. textData
  698. }}
  699. putInType={putInType}
  700. />
  701. <Button type='primary' onClick={preview}><SearchOutlined />预览广告</Button>
  702. </Space>
  703. {/* 选择公众号 */}
  704. {wechatVisible && <WechatAccount
  705. visible={wechatVisible}
  706. data={accountCreateLogs}
  707. onClose={() => setWechatVisible(false)}
  708. onChange={(e) => {
  709. setAccountCreateLogs(e);
  710. setWechatVisible(false);
  711. clearData()
  712. }}
  713. />}
  714. {/* 选择视频号 */}
  715. {channelsProfileVisible && <VideoChannel
  716. visible={channelsProfileVisible}
  717. data={accountCreateLogs}
  718. onClose={() => setChannelsProfileVisible(false)}
  719. onChange={(e) => {
  720. setAccountCreateLogs(e);
  721. setChannelsProfileVisible(false);
  722. clearData()
  723. }}
  724. />}
  725. </Card>
  726. </Spin>
  727. <Card
  728. className={style.createAd}
  729. >
  730. {activeKey && tableData && Object.keys(tableData)?.length > 0 ? <div className={style.cardBody}>
  731. <Tabs
  732. onChange={(e) => { setActiveKey(e) }}
  733. type="card"
  734. activeKey={activeKey}
  735. tabBarExtraContent={<Space>
  736. <span>创意总数:{dynamicCount}</span>
  737. <Popconfirm
  738. title="确定提交?"
  739. onConfirm={onSubmit}
  740. >
  741. <Button type='primary' loading={createDynamicTask.loading}>提交创建</Button>
  742. </Popconfirm>
  743. </Space>}
  744. >
  745. {adData.map(item => <Tabs.TabPane tab={item.adgroupId} key={item.adgroupId} />)}
  746. </Tabs>
  747. {addelivery?.dynamicCreativesTextDTOS?.type === 4 && <Title level={5} style={{ color: 'red', fontSize: 12 }}>因为选择的是“创意组和文案叉乘打乱后分配”模式,会随机打乱,当前预览广告下创意内容会与实际建出来的创意有偏差,请以建出来的为准</Title>}
  748. <div className={style.content} style={{ marginTop: 20 }}>
  749. <Table
  750. columns={columnsAddDynamic()}
  751. dataSource={tableData[activeKey]}
  752. size="small"
  753. bordered
  754. scroll={{ x: 1200 }}
  755. rowKey={'id'}
  756. pagination={{
  757. defaultPageSize: 50
  758. }}
  759. />
  760. </div>
  761. </div> : <div style={{ minHeight: 400, display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
  762. <Empty description="请先完成模块配置后,再预览广告计划" />
  763. </div>}
  764. </Card>
  765. </Space>
  766. </Drawer>
  767. }
  768. export default React.memo(AddDynamic)