|
@@ -33,10 +33,26 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
const [activeKey, setActiveKey] = useState<string>()
|
|
|
const [dynamicCount, setDynamicCount] = useState<number>(0)
|
|
|
const [adData, setAdData] = useState<any[]>(selectData)
|
|
|
+ const [adDataGroup, setAdDataGroup] = useState<{ [x: number]: any[] }>({})
|
|
|
|
|
|
const createDynamicTask = useAjax((params) => createDynamicTaskApi(params))
|
|
|
/****************************************/
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (adData && adData.length) {
|
|
|
+ let adDataGroup: { [x: number]: any[] } = {}
|
|
|
+ adData.forEach(item => {
|
|
|
+ let accountId = item.accountId
|
|
|
+ if (adDataGroup?.[accountId]?.length) {
|
|
|
+ adDataGroup[accountId].push(item)
|
|
|
+ } else {
|
|
|
+ adDataGroup[accountId] = [item]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setAdDataGroup(adDataGroup)
|
|
|
+ }
|
|
|
+ }, [adData])
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (tactics) {
|
|
|
const {
|
|
@@ -149,112 +165,169 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 落地页平均分配判断数量
|
|
|
+ if ([910].includes(dynamic.creativeTemplateId) && dynamic?.landingPageType === 1) {
|
|
|
+ if (accountCreateLogs.some(item => {
|
|
|
+ let total = adDataGroup[item.accountId].length
|
|
|
+ let pageLength = item.pageList.length
|
|
|
+ if (total > pageLength) {
|
|
|
+ message.error(`当前${item.accountId}下的广告总数(${total})大于落地页总数(${pageLength}),平均分配需要落地页总数大于广告总数`)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ })) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- let accountIndex1 = 0
|
|
|
- adData.forEach((ad, index) => {
|
|
|
- let item = accountCreateLogs.find(a => a.accountId === ad.accountId) as PULLIN.AccountCreateLogsProps
|
|
|
- let averageAdDynamic = averageAdDynamicList?.[index]
|
|
|
- let data = [{
|
|
|
- id: ad.adgroupId + '_' + index,
|
|
|
- pageListDto: item.pageList, // 落地页
|
|
|
- adgroupsDto: ad,
|
|
|
- dynamicDto: dynamic, // 创意信息
|
|
|
- averageAdDynamic,
|
|
|
- rowSpan: (mediaType === 1 && textType !== 4) ? averageAdDynamic.length : ([910].includes(dynamic.creativeTemplateId) ? item.pageList?.length : (textType === 3 ? textDtoLenth * dynamicGroupLength : dynamicGroupLength)) || 1
|
|
|
- }]
|
|
|
+ if (textType === 1) {
|
|
|
+ if (dynamicGroupLength !== textDtoLenth) {
|
|
|
+ message.error(`当前创意文案是“创意组一一对应”模式,创意组总数(${dynamicGroupLength})要等于创意文案总数(${textDtoLenth})`)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!dynamicCreativesTextDTOS.dynamicCreativesTextDetailDTOList.every((item: {}) => item && Object.keys(item).length)) {
|
|
|
+ message.error('创意文案配置错误,内容空')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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
|
|
|
+ let accountIndex1 = 0
|
|
|
+ if (dynamic?.landingPageType === 1 && [910].includes(dynamic.creativeTemplateId)) {
|
|
|
+ accountCreateLogs.forEach(item => {
|
|
|
+ let adData = adDataGroup[item.accountId]
|
|
|
+ let averageAdPageList: any[] = distributeArray(item.pageList, adData.length)
|
|
|
+ let newData: any[] = []
|
|
|
+ adData.forEach((ad, index) => {
|
|
|
+ let data = [{
|
|
|
+ id: ad.adgroupId + '_' + index,
|
|
|
+ adgroupsDto: ad,
|
|
|
+ dynamicDto: dynamic, // 创意信息
|
|
|
+ }]
|
|
|
+ newData = cartesianProduct(data, averageAdPageList[index]).map((item, index) => {
|
|
|
+ let [d1, pageList, num] = item
|
|
|
+ return {
|
|
|
+ ...d1,
|
|
|
+ id: d1.id + '_' + index,
|
|
|
+ pageListDto: [pageList],
|
|
|
+ dynamicDto: {
|
|
|
+ ...d1.dynamicDto,
|
|
|
+ dynamicCreativeName: d1.dynamicDto.dynamicCreativeName + num
|
|
|
+ },
|
|
|
+ rowSpan: index === 0 ? averageAdPageList[index].length : 0,
|
|
|
+ isRowSpan: true
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
+ newTableData[ad.adgroupId] = newData
|
|
|
})
|
|
|
- } else {
|
|
|
- if (mediaType === 1) {
|
|
|
- data.forEach(item => {
|
|
|
- const { averageAdDynamic, ...ad } = item
|
|
|
- if (textType === 3) {
|
|
|
- let rowSpan = textDtoLenth * averageAdDynamic.length
|
|
|
- cartesianProduct(textDto, averageAdDynamic).forEach((taad: any, index) => {
|
|
|
- let [textValue, aad] = taad
|
|
|
- newData.push({
|
|
|
- ...ad,
|
|
|
- id: ad.id + '_' + index,
|
|
|
- dynamicGroup: aad,
|
|
|
- textDto: textValue,
|
|
|
- rowSpan
|
|
|
+ newDynamicCount += item.pageList.length
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ adData.forEach((ad, index) => {
|
|
|
+ let item = accountCreateLogs.find(a => a.accountId === ad.accountId) as PULLIN.AccountCreateLogsProps
|
|
|
+ let averageAdDynamic = averageAdDynamicList?.[index]
|
|
|
+ let data = [{
|
|
|
+ id: ad.adgroupId + '_' + index,
|
|
|
+ pageListDto: item.pageList, // 落地页
|
|
|
+ adgroupsDto: ad,
|
|
|
+ dynamicDto: dynamic, // 创意信息
|
|
|
+ averageAdDynamic,
|
|
|
+ rowSpan: (mediaType === 1 && textType !== 4) ? averageAdDynamic.length : ([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 {
|
|
|
+ if (mediaType === 1) {
|
|
|
+ data.forEach(item => {
|
|
|
+ const { averageAdDynamic, ...ad } = item
|
|
|
+ if (textType === 3) {
|
|
|
+ let rowSpan = textDtoLenth * averageAdDynamic.length
|
|
|
+ cartesianProduct(textDto, averageAdDynamic).forEach((taad: any, index) => {
|
|
|
+ let [textValue, aad] = taad
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: textValue,
|
|
|
+ rowSpan
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
- } else if (textType === 4) {
|
|
|
- averageAdDynamic.forEach((aad: any, index: number) => {
|
|
|
- newData.push({
|
|
|
- ...ad,
|
|
|
- id: ad.id + '_' + index,
|
|
|
- dynamicGroup: aad,
|
|
|
- textDto: aad?.textDto,
|
|
|
- rowSpan: index === 0 ? averageAdDynamic.length : 0,
|
|
|
- isRowSpan: true
|
|
|
+ } else if (textType === 4) {
|
|
|
+ averageAdDynamic.forEach((aad: any, index: number) => {
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: aad?.textDto,
|
|
|
+ rowSpan: index === 0 ? averageAdDynamic.length : 0,
|
|
|
+ isRowSpan: true
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
- } else {
|
|
|
- averageAdDynamic.forEach((aad: any, index: number) => {
|
|
|
- newData.push({
|
|
|
- ...ad,
|
|
|
- id: ad.id + '_' + index,
|
|
|
- dynamicGroup: aad,
|
|
|
- textDto: aad?.textDto
|
|
|
+ } else {
|
|
|
+ averageAdDynamic.forEach((aad: any, index: number) => {
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: aad?.textDto
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- } else if (mediaType === 2) {
|
|
|
- data.forEach((item) => {
|
|
|
- const { averageAdDynamic, ...ad } = item
|
|
|
- if (textType === 3) {
|
|
|
- cartesianProduct(textDto, [newDynamicGroup[accountIndex1 % newDynamicGroup.length]]).forEach((taad: any) => {
|
|
|
- let [textValue, aad, index] = taad
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if (mediaType === 2) {
|
|
|
+ data.forEach((item) => {
|
|
|
+ const { averageAdDynamic, ...ad } = item
|
|
|
+ if (textType === 3) {
|
|
|
+ cartesianProduct(textDto, [newDynamicGroup[accountIndex1 % newDynamicGroup.length]]).forEach((taad: any) => {
|
|
|
+ let [textValue, aad, index] = taad
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: textValue,
|
|
|
+ rowSpan: textDto.length
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ let { textDto, ...dynamicGroup } = newDynamicGroup[accountIndex1 % newDynamicGroup.length]
|
|
|
newData.push({
|
|
|
...ad,
|
|
|
- id: ad.id + '_' + index,
|
|
|
- dynamicGroup: aad,
|
|
|
- textDto: textValue,
|
|
|
- rowSpan: textDto.length
|
|
|
+ dynamicGroup,
|
|
|
+ textDto,
|
|
|
+ rowSpan: 1
|
|
|
})
|
|
|
- })
|
|
|
- } else {
|
|
|
- let { textDto, ...dynamicGroup } = newDynamicGroup[accountIndex1 % newDynamicGroup.length]
|
|
|
- newData.push({
|
|
|
- ...ad,
|
|
|
- dynamicGroup,
|
|
|
- textDto,
|
|
|
- rowSpan: 1
|
|
|
- })
|
|
|
- }
|
|
|
- accountIndex1 += 1
|
|
|
- })
|
|
|
- } else {
|
|
|
- newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
|
|
|
- let [d1, group] = item
|
|
|
- return {
|
|
|
- ...d1,
|
|
|
- id: d1.id + '_' + index,
|
|
|
- dynamicGroup: group,
|
|
|
- textDto: (group as any)?.textDto
|
|
|
- }
|
|
|
- })
|
|
|
+ }
|
|
|
+ accountIndex1 += 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
|
|
|
+ let [d1, group] = item
|
|
|
+ return {
|
|
|
+ ...d1,
|
|
|
+ id: d1.id + '_' + index,
|
|
|
+ dynamicGroup: group,
|
|
|
+ textDto: (group as any)?.textDto
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- newDynamicCount += newData.length
|
|
|
- newTableData[ad.adgroupId] = newData
|
|
|
- })
|
|
|
+ newDynamicCount += newData.length
|
|
|
+ newTableData[ad.adgroupId] = newData
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
setDynamicCount(newDynamicCount)
|
|
|
setActiveKey(adData?.[0].adgroupId?.toString())
|
|
|
console.log('newTableData-->', newTableData)
|
|
@@ -451,9 +524,14 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
<div className={style.detail}>
|
|
|
<div className={style.detail_body}>
|
|
|
<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>
|
|
|
+ {Object.keys(adDataGroup).map(key => {
|
|
|
+ return <div key={key}>
|
|
|
+ <Title level={5} style={{ fontSize: 12 }}>{key}</Title>
|
|
|
+ {adDataGroup[key]?.map((item: any) => {
|
|
|
+ return <div key={item.adgroupId}>
|
|
|
+ <div className={style.text}><Text ellipsis={{ tooltip: true }}>{item.adgroupName}</Text></div>
|
|
|
+ </div>
|
|
|
+ })}
|
|
|
</div>
|
|
|
})}
|
|
|
</div>
|
|
@@ -468,7 +546,7 @@ const AddDynamic: React.FC<PULLIN.NewAddDynamic> = ({ visible, onChange, onClose
|
|
|
{/* 创意文案 */}
|
|
|
<MaterialText />
|
|
|
{/* 落地页 */}
|
|
|
- <PageList />
|
|
|
+ <PageList adDataGroup={adDataGroup} />
|
|
|
</div>
|
|
|
</DispatchAddelivery.Provider>
|
|
|
</div>
|