index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React, { useContext, useEffect, useState } from "react"
  2. import style from '../index.less'
  3. import { Button, Space } from "antd"
  4. import { EditOutlined } from "@ant-design/icons"
  5. import { DispatchAddelivery } from ".."
  6. import NewDynamic from "./newDynamic"
  7. import { AD_STATUS_ENUM, CONVERSION_DATA_ENUM, CONVERSION_TARGET_ENUM, DELIVERY_MODE_ENUM, PAGE_TYPE_ENUM, TEXT_LINK_TYPE_ENUM, pageSpecFieldConVertUn } from "../../const"
  8. import { getProfilesApi } from "@/services/adqV3/global"
  9. import { useAjax } from "@/Hook/useAjax"
  10. import { arraysHaveSameValues } from "@/utils/utils"
  11. /**
  12. * 创意
  13. * @returns
  14. */
  15. const Dynamic: React.FC<{ creativeTemplateAppellation?: string, creativeTemplateStyle?: string }> = ({ creativeTemplateAppellation, creativeTemplateStyle }) => {
  16. /***************************************/
  17. const { addelivery, setAddelivery, clearData, setAccountCreateLogs, accountCreateLogs } = useContext(DispatchAddelivery)!;
  18. const { adgroups, dynamic: dynamicData } = addelivery;
  19. const { deliveryMode, creativeTemplateId, dynamicCreativeName, creativeComponents, configuredStatus } = dynamicData
  20. const { textLink, actionButton, showData, brand, mainJumpInfo } = creativeComponents || {}
  21. const [newVisible, setNewVisible] = useState<boolean>(false);
  22. const [profileData, setprofileData] = useState<any>()
  23. const getProfiles = useAjax((params) => getProfilesApi(params))
  24. /***************************************/
  25. useEffect(() => {
  26. if (['PAGE_TYPE_H5_PROFILE'].includes(brand?.[0]?.value?.jumpInfo?.pageType)) {
  27. getProfiles.run({}).then(res => {
  28. if (res) {
  29. setprofileData(res?.find((item: { id: any }) => item.id === brand?.[0]?.value?.profileId))
  30. }
  31. })
  32. }
  33. }, [brand])
  34. return <div className={`${style.settingsBody_content_row} ${style.row3}`}>
  35. <div className={style.title}>
  36. <span>创意信息</span>
  37. </div>
  38. <div className={style.detail}>
  39. <div className={style.detail_body}>
  40. {dynamicData && Object.keys(dynamicData).length > 0 && <>
  41. <p style={{ fontWeight: 'bold', color: configuredStatus === 'AD_STATUS_NORMAL' ? '#52c41a' : '#FF4D4F' }}>创意状态:{AD_STATUS_ENUM[configuredStatus as keyof typeof AD_STATUS_ENUM]}</p>
  42. <p>创意名称:{dynamicCreativeName}</p>
  43. <p style={{ fontWeight: 'bold', color: '#000' }}>投放模式:{DELIVERY_MODE_ENUM[deliveryMode as keyof typeof DELIVERY_MODE_ENUM]}</p>
  44. <p>{((creativeTemplateId && creativeTemplateAppellation) || creativeTemplateId) && `创意形式:${creativeTemplateAppellation || creativeTemplateId}`}</p>
  45. {brand?.length > 0 && <>
  46. <p style={{ fontWeight: 'bold', color: '#000' }}>品牌形象跳转:{PAGE_TYPE_ENUM[brand?.[0]?.value?.jumpInfo?.pageType as keyof typeof PAGE_TYPE_ENUM]}</p>
  47. {['PAGE_TYPE_H5_PROFILE'].includes(brand?.[0]?.value?.jumpInfo?.pageType) ? <>
  48. {profileData ? <>
  49. <Space>
  50. <img src={profileData?.headImageUrl} alt="" width={20} style={{ display: 'block' }} />
  51. <span style={{ fontWeight: 'bold', color: '#000', fontSize: 12 }}>{profileData?.profileName}</span>
  52. </Space>
  53. <p>详细描述:{profileData?.description}</p>
  54. </> : <span style={{ color: 'red', fontWeight: 'bold', fontSize: 12 }}>{getProfiles.loading ? '' : '当前头像昵称跳转页被删除'} </span>}
  55. </> : ['PAGE_TYPE_NOT_USED'].includes(brand?.[0]?.value?.jumpInfo?.pageType) && <Space align="center">
  56. <img src={brand?.[0]?.value?.brandImageId} alt="" width={20} style={{ display: 'block' }} />
  57. <span style={{ fontWeight: 'bold', color: '#000', fontSize: 12 }}>{brand?.[0]?.value?.brandName}</span>
  58. </Space>}
  59. </>}
  60. <p style={{ fontWeight: 'bold', color: '#000' }}>跳转类型:{mainJumpInfo?.map((item: any) => {
  61. let pageType = item.value.pageType
  62. return PAGE_TYPE_ENUM[pageType as keyof typeof PAGE_TYPE_ENUM]
  63. }).toString()}</p>
  64. {textLink?.length > 0 && <>
  65. <p style={{ fontWeight: 'bold', color: '#000' }}>朋友圈文字链:开启</p>
  66. <p>文字链文案:{TEXT_LINK_TYPE_ENUM[textLink?.[0]?.value?.linkNameType as keyof typeof TEXT_LINK_TYPE_ENUM]}</p>
  67. {textLink?.[0]?.value?.jumpInfo?.pageType && <p>跳转落地页:{PAGE_TYPE_ENUM[textLink?.[0]?.value?.jumpInfo?.pageType as keyof typeof PAGE_TYPE_ENUM]}</p>}
  68. </>}
  69. {actionButton?.length > 0 && <>
  70. <p style={{ fontWeight: 'bold', color: '#000' }}>行动按钮:开启</p>
  71. <p>按钮文案:{actionButton?.[0]?.value?.buttonText}</p>
  72. {actionButton?.[0]?.value?.jumpInfo?.pageType && <p>跳转落地页:{PAGE_TYPE_ENUM[actionButton?.[0]?.value?.jumpInfo?.pageType as keyof typeof PAGE_TYPE_ENUM]}</p>}
  73. </>}
  74. {showData?.length > 0 && <>
  75. <p style={{ fontWeight: 'bold', color: '#000' }}>数据外显:开启</p>
  76. <p>数据类型:{CONVERSION_DATA_ENUM[showData?.[0]?.value?.conversionDataType as keyof typeof CONVERSION_DATA_ENUM]}</p>
  77. <p>转化行为:{CONVERSION_TARGET_ENUM[showData?.[0]?.value?.conversionTargetType as keyof typeof CONVERSION_TARGET_ENUM]}</p>
  78. </>}
  79. </>}
  80. </div>
  81. <div className={style.detail_footer}>
  82. <Button disabled={!(adgroups && Object.keys(adgroups)?.length > 0)} type="link" icon={<EditOutlined />} style={{ padding: 0, fontSize: 12 }} onClick={() => setNewVisible(true)}>编辑</Button>
  83. </div>
  84. </div>
  85. {newVisible && <NewDynamic
  86. visible={newVisible}
  87. creativeTemplateStyle={creativeTemplateStyle}
  88. value={dynamicData}
  89. onClose={() => {
  90. setNewVisible(false)
  91. }}
  92. onChange={(dynamic) => {
  93. if (
  94. dynamic.deliveryMode === deliveryMode && // 投放模式
  95. dynamic?.creativeTemplateId === creativeTemplateId // 创意形式
  96. ) {
  97. setAddelivery({ ...addelivery, dynamic })
  98. } else {
  99. setAddelivery({ ...addelivery, dynamic, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {} })
  100. }
  101. let oldPageTypeList = mainJumpInfo?.map((item: { value: { pageType: any } }) => item.value) || []
  102. let newPageTypeList = dynamic?.creativeComponents?.mainJumpInfo.map((item: { value: { pageType: any } }) => item.value)
  103. setNewVisible(false)
  104. clearData()
  105. if (!arraysHaveSameValues(oldPageTypeList || [], newPageTypeList || [])) {
  106. setAccountCreateLogs(accountCreateLogs.map(item => ({ ...item, pageList: [] })))
  107. }
  108. }}
  109. />}
  110. </div>
  111. }
  112. export default React.memo(Dynamic)