wjx 2 years ago
parent
commit
2a81911608
1 changed files with 37 additions and 16 deletions
  1. 37 16
      src/pages/launchSystemNew/launchManage/createAd/index.tsx

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

@@ -28,6 +28,7 @@ import CustomerServiceModal from "../../components/customerServiceModal"
 import { getTaskDetailsApi } from "@/services/launchAdq/taskList"
 import CreativeCL from "./creativeCL"
 import { groupBy } from "@/utils/utils"
+import { getAccountListApi, getGroupListApi } from "@/services/launchAdq/subgroup"
 
 const CreateAd: React.FC = () => {
 
@@ -80,8 +81,14 @@ const CreateAd: React.FC = () => {
     const getSysAdcreative = useAjax((params) => getSysAdcreativeInfo(params))
     const createAdBatch = useAjax((params) => createAdBatchApi(params))
     const getTaskDetails = useAjax((params) => getTaskDetailsApi(params))
+    const getGroupList = useAjax(() => getGroupListApi())
+    const getAccountList = useAjax((params) => getAccountListApi(params))
     /*************************/
 
+    useEffect(() => {
+        getGroupList.run()
+    }, [])
+
     /**数据回填 */
     useEffect(() => {
         let taskId = sessionStorage.getItem('TASKID')
@@ -123,7 +130,7 @@ const CreateAd: React.FC = () => {
                             let corpUserGroup2s = item?.corpUserGroup2s
                             return {
                                 adAccountId: item.accountId, id: item.adAccountId, data: groupList.map((crop: any, index: number) => {
-                                    return { ...crop, cropList: crop.type === 1 ? corpUserGroup1s[index] ? [{ ...corpUserGroup1s[index], id: corpUserGroup1s[index].groupId }] : [] : corpUserGroup2s[0] ? [{ ...corpUserGroup2s[0], id: corpUserGroup2s[0].groupId }] : []}
+                                    return { ...crop, cropList: crop.type === 1 ? corpUserGroup1s[index] ? [{ ...corpUserGroup1s[index], id: corpUserGroup1s[index].groupId }] : [] : corpUserGroup2s[0] ? [{ ...corpUserGroup2s[0], id: corpUserGroup2s[0].groupId }] : [] }
                                 })
                             }
 
@@ -624,6 +631,32 @@ const CreateAd: React.FC = () => {
         set_targetKey('0')
     }
 
+    /** 获取分组里账号 */
+    const getGroupAccountList = (ids: number[]) => {
+        if (ids.length > 0) {
+            let data = ids.map(id => getAccountListApi(id))
+            Promise.all(data).then(res => {
+                if (res?.length > 0 && res.every((item: { code: number }) => item.code === 200)) {
+                    let userArr: any[] = []
+                    res.forEach((item: { data: { adAccountList: { accountId: number, id: number }[] } }) => {
+                        item.data.adAccountList.forEach(acc => {
+                            let obj = userArr.find((item: { accountId: number }) => item.accountId === acc.accountId)
+                            if (!obj) {
+                                userArr.push(acc)
+                            }
+                        })
+                    })
+                    setAccountCreateLogs(userArr?.map((item) => ({ adAccountId: item?.accountId, id: item.id })))
+                    clearData()
+                } else {
+                    message.error('操作异常')
+                }
+            })
+        } else {
+            setAccountCreateLogs([])
+        }
+    }
+
     return <Space direction="vertical" style={{ width: '100%' }}>
         <Card
             title={<Space>
@@ -639,7 +672,7 @@ const CreateAd: React.FC = () => {
             </Space>}
             className={style.createAd}
             hoverable
-            extra={<AddGroup onChange={usersChange} pitcherData={getAdAccount?.data?.data} />}
+        // extra={<AddGroup onChange={usersChange} pitcherData={getAdAccount?.data?.data} />}
         >
             <Space wrap>
                 <Selector label="媒体账户组">
@@ -653,21 +686,9 @@ const CreateAd: React.FC = () => {
                         filterOption={(input: any, option: any) => {
                             return option!.children?.toString().toLowerCase().includes(input.toLowerCase())
                         }}
-                        onChange={(e, option) => {
-                            console.log(e, option)
-                            let userArr: any[] = []
-                            e.forEach((key: any) => {
-                                let obj = usesArr.find((item: { id: any }) => item.id === key)
-                                if (obj) {
-                                    userArr.push(obj['pitcher'])
-                                }
-                            })
-                            userArr = [...new Set(userArr.flat())]
-                            setAccountCreateLogs(userArr?.map((item: any) => ({ adAccountId: item?.split('_')[1], id: Number(item?.split('_')[0]) })))
-                            clearData()
-                        }}
+                        onChange={(e, option) => { getGroupAccountList(e) }}
                     >
-                        {usesArr?.map((item: any) => <Select.Option value={item.id} key={item.id}>{item.name}</Select.Option>)}
+                        {getGroupList.data?.map((item: any) => <Select.Option value={item.groupId} key={item.groupId}>{item.groupName}</Select.Option>)}
                     </Select>
                 </Selector>
                 <Selector label="媒体账户">