index.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React, { useContext, useEffect, useState } from "react"
  2. import style from '../index.less'
  3. import { DispatchAddelivery } from "..";
  4. import { Button, Empty, Typography } from "antd";
  5. import { FolderOpenOutlined, RedoOutlined } from "@ant-design/icons";
  6. import AddMaterial from "./addMaterial";
  7. import VideoNews from "@/pages/launchSystemNew/components/newsModal/videoNews";
  8. const { Title } = Typography;
  9. const Material: React.FC<{ adData?: any[] }> = ({ adData }) => {
  10. /***************************************/
  11. const { materialData, addelivery, setAddelivery, clearData, accountCreateLogs } = useContext(DispatchAddelivery)!;
  12. const { dynamic, dynamicMaterialDTos, mediaType, targeting, adgroups: { marketingAssetOuterSpec } } = addelivery
  13. const { creativeTemplateId, deliveryMode } = dynamic
  14. const [adLength, setAdLength] = useState<number>(0)
  15. const [newVisible, setNewVisible] = useState<boolean>(false)
  16. const [mType, setMtype] = useState<string>()
  17. /***************************************/
  18. useEffect(() => {
  19. if (materialData && Object.keys(materialData).length > 0) {
  20. let type = Object.keys(materialData)[0];
  21. setMtype(type)
  22. }
  23. }, [materialData])
  24. // 获取广告总数
  25. useEffect(() => {
  26. if (adData && adData?.length > 0) {
  27. setAdLength(adData.length)
  28. } else if (accountCreateLogs?.length > 0 && marketingAssetOuterSpec?.marketingTargetType) {
  29. let adLength = 0
  30. accountCreateLogs.forEach(item => {
  31. let productList: any[] = []
  32. if (['MARKETING_TARGET_TYPE_FICTION'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 小说
  33. productList = item?.productList || []
  34. } else if (['MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 公众号
  35. productList = item?.wechatChannelList || []
  36. }
  37. adLength += productList.length * targeting.length
  38. })
  39. setAdLength(adLength)
  40. }
  41. }, [accountCreateLogs, marketingAssetOuterSpec, adData])
  42. return <div className={`${style.settingsBody_content_row} ${style.row4}`}>
  43. <div className={style.title}>
  44. <span>创意素材 <span className={style.selected}>已选 {dynamicMaterialDTos?.dynamicGroup?.length || 0}</span></span>
  45. {(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length > 0) ? <Button type="link" size="small" style={{ fontSize: 11, padding: 0 }} onClick={() => setAddelivery({ ...addelivery, dynamicMaterialDTos: [], dynamicCreativesTextDTOS: {} })}><RedoOutlined />清空</Button> : null}
  46. </div>
  47. <div className={style.detail}>
  48. <div className={style.detail_body}>
  49. {(dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length > 0) ?
  50. <>
  51. <Title level={5} style={{ fontSize: 12 }}>{mediaType === 0 ? '全账号复用' : mediaType === 1 ? '创意组平均分配到广告' : null}</Title>
  52. <div className={style.detail_body_m}>
  53. {dynamicMaterialDTos.dynamicGroup.map((item: any, index: number) => {
  54. return <div key={index} style={{ width: deliveryMode === 'DELIVERY_MODE_CUSTOMIZE' ? [641, 642, 643].includes(creativeTemplateId) ? '100%' : [720, 721, 722, 1529, 618].includes(creativeTemplateId) ? '50%' : '25%' : '100%' }}>
  55. <Title level={5} style={{ fontSize: 12 }}>创意组{index + 1}</Title>
  56. {mType ? ['short_video', 'video'].includes(mType) ? <div className={style.video}>
  57. <VideoNews src={item?.video_id?.url || item?.short_video1?.url} />
  58. {item?.cover_id && <div className={style.cover_image}>
  59. <img src={item?.cover_id?.url} />
  60. </div>}
  61. </div> : ['image_list'].includes(mType) ? <div className={style.imageList}>
  62. {item?.image_list?.map((item: { url: string | undefined; }, index: undefined) => <div className={style.cover_image} key={index}>
  63. <img src={item?.url} />
  64. </div>)}
  65. </div> : ['element_story'].includes(mType) ? <div className={style.imageList}>
  66. {item?.element_story?.map((item: { url: string | undefined; }, index: undefined) => <div className={style.cover_image} key={index}>
  67. <img src={item?.url} />
  68. </div>)}
  69. </div> : ['image'].includes(mType) ? <div className={style.cover_image}>
  70. <img src={item?.image_id?.url} />
  71. </div> : null : null}
  72. </div>
  73. })}
  74. </div>
  75. </> :
  76. <div className={style.empty_block}>
  77. <Empty description="暂无素材" imageStyle={{ height: 50 }} />
  78. </div>}
  79. {((dynamic && Object.keys(dynamic).length > 0) && !(materialData && Object.keys(materialData).length > 0)) && <div className={style.ad_config}>
  80. <div className={style.ad_config_item}>无需设置创意素材</div>
  81. </div>}
  82. </div>
  83. <div className={style.detail_footer}>
  84. <Button disabled={!(dynamic && Object.keys(dynamic)?.length > 0)} type="link" icon={<FolderOpenOutlined />} style={{ padding: 0, fontSize: 12 }} onClick={() => setNewVisible(true)}>选择素材</Button>
  85. </div>
  86. </div>
  87. {newVisible && <AddMaterial
  88. adLength={adLength}
  89. creativeTemplateId={creativeTemplateId}
  90. value={{ dynamicMaterialDTos, mediaType }}
  91. materialData={materialData}
  92. deliveryMode={deliveryMode}
  93. visible={newVisible}
  94. onClose={() => {
  95. setNewVisible(false)
  96. }}
  97. onChange={({ dynamicMaterialDTos, mediaType }) => {
  98. setAddelivery({ ...addelivery, dynamicMaterialDTos, mediaType })
  99. setNewVisible(false)
  100. clearData()
  101. }}
  102. />}
  103. </div>
  104. }
  105. export default React.memo(Material)