shenwu hai 1 ano
pai
achega
fddbb7e87d
Modificáronse 1 ficheiros con 102 adicións e 37 borrados
  1. 102 37
      src/pages/launchSystemNew/launchManage/createAd/index.tsx

+ 102 - 37
src/pages/launchSystemNew/launchManage/createAd/index.tsx

@@ -535,7 +535,7 @@ const CreateAd: React.FC = () => {
             message.error('请选择落地页')
             return
         }
-        if (launchMode === 2) {
+        if (launchMode !== 1) {
             if ((queryForm?.materialData && queryForm?.materialData?.length > 0) && !(newQueryForm?.materials && newQueryForm?.materials?.length > 0)) {
                 message.error('请选择创意素材')
                 return
@@ -558,8 +558,10 @@ const CreateAd: React.FC = () => {
                 return
             }
         }
+        //最终数据
         let data: any[] = []
-        if (launchMode === 2) {
+        // 素材叉乘处理
+        if (launchMode !== 1) {
             if (Array.isArray(newQueryForm.materials) && Array.isArray(newQueryForm?.texts)) {
                 let taskMediaMap = JSON.parse(JSON.stringify(newQueryForm.taskMediaMaps[0]))
                 let adcreativeElements = taskMediaMap.sysAdcreative?.adcreativeElements || {}
@@ -570,20 +572,58 @@ const CreateAd: React.FC = () => {
                 newQueryForm.taskMediaMaps = newTaskMediaMaps
             }
         }
-        accountCreateLogs.forEach((item: any) => {
-            newQueryForm.taskMediaMaps?.forEach((task, index) => {
-                let obj = {
-                    ...item,
-                    ...newQueryForm,
-                    sysAdGroupData: newQueryForm.sysAdgroup,
-                    targetingData: newQueryForm.sysTargeting,
-                    sysAdcreativeData: task.sysAdcreative,
-                    pageData: launchMode === 2 ? (newQueryForm.pageList as any)[0] || (newQueryForm.adqPageList as any)[0]?.find((adq: { adAccountId: any }) => adq.adAccountId === item.adAccountId)?.pageList[0] : (newQueryForm.pageList as any)[index] || (newQueryForm.adqPageList as any)[index]?.find((adq: { adAccountId: any }) => adq.adAccountId === item.adAccountId)?.pageList[0],
-                    myId: Number(item.id + '' + index)
-                }
-                data.push(obj)
+        console.log(newQueryForm.taskMediaMaps)
+        if (launchMode !== 3) {//叉乘和普通模式
+            accountCreateLogs.forEach((item: any) => {
+                newQueryForm.taskMediaMaps?.forEach((task, index) => {
+                    let obj = {
+                        ...item,
+                        ...newQueryForm,
+                        sysAdGroupData: newQueryForm.sysAdgroup,
+                        targetingData: newQueryForm.sysTargeting,
+                        sysAdcreativeData: task.sysAdcreative,
+                        pageData: launchMode === 2 ? (newQueryForm.pageList as any)[0] || (newQueryForm.adqPageList as any)[0]?.find((adq: { adAccountId: any }) => adq.adAccountId === item.adAccountId)?.pageList[0] : (newQueryForm.pageList as any)[index] || (newQueryForm.adqPageList as any)[index]?.find((adq: { adAccountId: any }) => adq.adAccountId === item.adAccountId)?.pageList[0],
+                        myId: Number(item.id + '' + index)
+                    }
+                    data.push(obj)
+                })
             })
-        })
+        } else {//顺序模式
+            //素材个数大于等于账号个数的顺序分配
+            if (newQueryForm?.taskMediaMaps && (newQueryForm?.taskMediaMaps?.length >= accountCreateLogs.length)) {
+                let bIndex = 0;
+                newQueryForm.taskMediaMaps?.forEach((task, index) => {
+                    let obj = {
+                        ...accountCreateLogs[bIndex],
+                        ...newQueryForm,
+                        sysAdGroupData: newQueryForm.sysAdgroup,
+                        targetingData: newQueryForm.sysTargeting,
+                        sysAdcreativeData: task.sysAdcreative,
+                        pageData: (newQueryForm.pageList as any)[0] || (newQueryForm.adqPageList as any)[0]?.find((adq: { adAccountId: any }) => adq.adAccountId === accountCreateLogs[bIndex].adAccountId)?.pageList[0],
+                        myId: Number(accountCreateLogs[bIndex].id + '' + index)
+                    }
+                    data.push(obj)
+                    bIndex = (index + 1) % accountCreateLogs.length
+                })
+            } else {
+                //素材个数小于账号个数的顺序分配
+                console.log("素材不够分配")
+                let bIndex = 0;
+                accountCreateLogs.forEach((item: any, index: number) => {
+                    let obj = {
+                        ...item,
+                        ...newQueryForm,
+                        sysAdGroupData: newQueryForm.sysAdgroup,
+                        targetingData: newQueryForm.sysTargeting,
+                        sysAdcreativeData: (newQueryForm.taskMediaMaps as any)[bIndex] ? (newQueryForm.taskMediaMaps as any)[bIndex].sysAdcreative : (newQueryForm.taskMediaMaps as any)[0].sysAdcreative,
+                        pageData: (newQueryForm.pageList as any)[0] || (newQueryForm.adqPageList as any)[0]?.find((adq: { adAccountId: any }) => adq.adAccountId === item.adAccountId)?.pageList[0],
+                        myId: Number(item.id + '' + index)
+                    }
+                    data.push(obj)
+                    bIndex = (index + 1) % accountCreateLogs.length
+                })
+            }
+        }
         if (['OPTIMIZATIONGOAL_FOLLOW', 'OPTIMIZATIONGOAL_PAGE_SCAN_CODE'].includes(newQueryForm.sysAdgroup.optimizationGoal) && !(newQueryForm.sysAdgroup.deepConversionSpec && Object.keys(newQueryForm.sysAdgroup.deepConversionSpec).length > 0)) {
             Modal.confirm({
                 title: '请注意',
@@ -598,9 +638,9 @@ const CreateAd: React.FC = () => {
             });
         } else {
             setTableData(data)
-        } 
+        }
     }
-
+    // 提交
     const submit = (props: { campaignName: string, count?: number }) => {
         let newQueryForm = JSON.parse(JSON.stringify(queryForm))
         if (launchMode === 2) {
@@ -859,14 +899,16 @@ const CreateAd: React.FC = () => {
     }, [queryForm, targetKey])
 
     // 切换投放模式
-    const switchLaunchMode = () => {
-        if (launchMode === 1) {
-            setLaunchMode(2)
-            localStorage.setItem('LAUNCHMODE', '2')
-        } else {
-            setLaunchMode(1)
-            localStorage.setItem('LAUNCHMODE', '1')
-        }
+    const switchLaunchMode = (mode: number) => {
+        setLaunchMode(mode)
+        localStorage.setItem('LAUNCHMODE', mode.toString())
+        // if (launchMode === 1) {
+        //     setLaunchMode(2)
+        //     localStorage.setItem('LAUNCHMODE', '2')
+        // } else {
+        //     setLaunchMode(1)
+        //     localStorage.setItem('LAUNCHMODE', '1')
+        // }
         delBdPlan()
         set_targetKey('0')
     }
@@ -900,17 +942,40 @@ const CreateAd: React.FC = () => {
 
     return <Space direction="vertical" style={{ width: '100%' }}>
         <Card
-            title={<Space>
-                <div className={style.cardTitle}>配置区</div>
-                <Popconfirm
-                    title="数据部分不会保存,是否切换?"
-                    onConfirm={switchLaunchMode}
-                    okText="是"
-                    cancelText="否"
-                >
-                    <Button type="link" style={{ padding: 0 }}>切换投放模式</Button>
-                </Popconfirm>
-            </Space>}
+            title={
+                <Space>
+                    <div className={style.cardTitle}>配置区</div>
+                    <Select
+                        style={{ width: 100 }} size="small"
+                        value={launchMode}
+                        onChange={(value) => {
+                            switchLaunchMode(value)
+                        }}
+                        options={[
+                            {
+                                value: 1,
+                                label: "普通模式",
+                            },
+                            {
+                                value: 2,
+                                label: "叉乘模式",
+                            },
+                            {
+                                value: 3,
+                                label: "顺序模式",
+                            }
+                        ]}>
+                    </Select>
+                    {/* <Popconfirm
+                        title={<>当前已编辑的数据部分不会保存,是否切换?</>}
+                        onConfirm={switchLaunchMode}
+                        okText="是"
+                        cancelText="否"
+                    >
+                        <Button type="link" style={{ padding: 0 }}>切换投放模式</Button>
+                    </Popconfirm> */}
+                </Space>
+            }
             className={style.createAd}
             hoverable
             extra={<UserTactics setQueryForm={setQueryForm} setAccountCreateLogs={setAccountCreateLogs} setLaunchMode={setLaunchMode} />}
@@ -1009,7 +1074,7 @@ const CreateAd: React.FC = () => {
                         })}
                     </Select>
                 </Selector>
-                {launchMode === 2 && accountCreateLogs?.length > 0 && <>
+                {launchMode !== 1 && accountCreateLogs?.length > 0 && <>
                     <Button onClick={() => { setGoodsVisible(true) }}>商品广告(选填){accountCreateLogs?.some(item => item?.productList?.length) && <CheckOutlined style={{ color: '#1890ff' }} />}</Button>
                     <Button onClick={() => { setSourceVisible(true) }}>精准匹配归因(选填){accountCreateLogs?.some(item => item?.userActionSetsList?.length) && <CheckOutlined style={{ color: '#1890ff' }} />}</Button>
                 </>}