addDynamic.tsx 41 KB

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