import Selector from "@/pages/launchSystemNew/launchManage/createAd/selector" import React, { useEffect, useState } from "react" import style from './index.less' import { Button, Input, message, Modal, Select, Table, Tag, Tooltip, Typography } from "antd"; import { CloseCircleFilled } from "@ant-design/icons"; import { getGroupListApi, getAccountListApi } from "@/services/launchAdq/subgroup"; import { useAjax } from "@/Hook/useAjax"; import { getAccountAssetsGroupListAllApi } from "@/services/adqV3/global"; import { getAllUserAccountApi } from "@/services/launchAdq/adAuthorize"; import { arraysHaveSameValues, groupBy } from "@/utils/utils"; import { DELIVERY_MODE_ENUM } from "../../const"; import '../../index.less' const { Text } = Typography; interface Props { setAccountCreateLogs: React.Dispatch> accountCreateLogs: PULLIN.AccountCreateLogsProps[] setOwnerAccountId: React.Dispatch> ownerAccountId: number | undefined deliveryMode?: keyof typeof DELIVERY_MODE_ENUM mType?: string, putInType?: 'NOVEL' | 'GAME' onChange?: (value?: any[], isClear?: boolean) => void dynamicGroup?: any[] } /** * 选择账户 * @returns */ const SelectAccount: React.FC = ({ putInType, accountCreateLogs, setAccountCreateLogs, onChange, dynamicGroup, deliveryMode, mType }) => { /***********************************/ const [visible, setVisible] = useState(false) const [assetSharingDeta, setAssetSharingDeta] = useState<{ authMainAccountId: number, groupId: number }>() // 资产共享组 const [dataSource, setDataSource] = useState([]) const [options, setOptions] = useState([]) const [selectedRows, setSelectedRows] = useState([]) const [mediaTypeGroupIds, setMediaTypeGroupIds] = useState([]) const [loading, setLoading] = useState(false) const [inputAccountList, setInputAccountList] = useState([]) const [tipsVisible, setTipsVisible] = useState(false) const getGroupList = useAjax(() => getGroupListApi()) const getAccountAssetsGroupListAll = useAjax((params) => getAccountAssetsGroupListAllApi(params)) const getAllUserAccount = useAjax(() => getAllUserAccountApi()) /***********************************/ // 判断选择的账号是否在同一个资产组,允许选择云端素材的关键 const getauthMainAccountData = (accountCreateLogs: PULLIN.AccountCreateLogsProps[]) => { console.log('---->', getAllUserAccount?.data) if (getAllUserAccount?.data?.length && accountCreateLogs?.length) { const list = accountCreateLogs.map(item => item.accountId) const selectAccountList = getAllUserAccount.data.filter((item: { accountId: any }) => list.includes(item.accountId)) const groupAccount = groupBy(selectAccountList, (item) => item.groupId, true) const GrounpArray = Object.keys(groupAccount).map(function (group) { return groupAccount[group]; }) if (GrounpArray.length === 1) { return { authMainAccountId: GrounpArray?.[0]?.[0]?.authMainAccountId || GrounpArray?.[0]?.[0]?.accountId, isSelectRemote: true } } else if (GrounpArray.length === 2 && groupAccount?.['undefined']?.length === 1) { const undefinedAccount = groupAccount?.['undefined'][0].accountId let authMainAccountId: any Object.keys(groupAccount).forEach(key => { if (key !== 'undefined') { authMainAccountId = groupAccount[key][0].authMainAccountId } }) if (undefinedAccount === authMainAccountId) { return { authMainAccountId: authMainAccountId, isSelectRemote: true } } else { return { authMainAccountId: -1, isSelectRemote: false } } } else { return { authMainAccountId: -1, isSelectRemote: false } } } else { return { authMainAccountId: undefined, isSelectRemote: false } } } useEffect(() => { if (visible && accountCreateLogs?.length) { setSelectedRows(accountCreateLogs) } }, [accountCreateLogs, visible]) useEffect(() => { if (putInType) { // 获取账户组 getGroupList.run() // 获取资产共享组 getAccountAssetsGroupListAll.run({}) // 账户 getAllUserAccount.run().then(res => { if (res) { let options = res?.filter((item: any) => putInType === 'NOVEL' ? ['NOVEL', 'NOVEL_IAA'].includes(item.adUnitType) : putInType === 'GAME' ? ['GAME', 'GAME_IAA'].includes(item.adUnitType) : false) setOptions(options || []) setDataSource(options || []) } }) } return () => { document.body.style.overflow = 'auto'; } }, [putInType]) /** 获取分组里账号 */ const getGroupAccountList = (ids: number[]) => { setMediaTypeGroupIds(ids) setAssetSharingDeta(undefined) if (ids.length > 0) { setLoading(true) let data = ids.map(id => getAccountListApi(id)) Promise.all(data).then(res => { setLoading(false) 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.accountId) } }) }) setDataSource(options.filter(item => userArr.includes(item.accountId))) } else { message.error('操作异常') } }) } else { setDataSource(options) } } const handleOk = (isClear: boolean) => { document.body.style.overflow = 'auto'; onChange?.(selectedRows, isClear) setSelectedRows([]) setInputAccountList([]) setMediaTypeGroupIds([]) setAssetSharingDeta(undefined) setVisible(false) setTipsVisible(false) } const handleCancel = () => { document.body.style.overflow = 'auto'; setSelectedRows([]) setInputAccountList([]) setMediaTypeGroupIds([]) setAssetSharingDeta(undefined) setVisible(false) } return
{ document.body.style.overflow = 'hidden'; setVisible(true) }} >
{(visible && selectedRows.length > 0) ? <> { setSelectedRows(selectedRows.slice(1)) }} >{selectedRows[0].accountId} {selectedRows?.length > 1 && {selectedRows?.filter((_, index) => index !== 0)?.map((item) => { setSelectedRows(selectedRows?.filter(item1 => item1.accountId !== item.accountId)) }} >{item.accountId})} } > +{selectedRows.length - 1} } : (!visible && accountCreateLogs?.length > 0) ? <> { setAccountCreateLogs(accountCreateLogs.slice(1)) }} >{accountCreateLogs[0].accountId} {accountCreateLogs?.length > 1 && {accountCreateLogs?.filter((_, index) => index !== 0)?.map((item) => { setAccountCreateLogs(accountCreateLogs?.filter(item1 => item1.accountId !== item.accountId)) }} >{item.accountId})} } > +{accountCreateLogs.length - 1} } : 请选择媒体账户}
{visible} {((visible && selectedRows.length > 0) || (!visible && accountCreateLogs?.length > 0)) && { e.stopPropagation() if (visible) { setSelectedRows([]) } else { setAccountCreateLogs([]) } }}>}
{visible &&
{ let input = e.target.value let newInput: string[] = input ? input?.split(/[,,\n\s]+/ig).filter((item: any) => item) : [] setInputAccountList(newInput) }} />
inputAccountList?.length > 0 ? inputAccountList?.some(val => item.accountId?.toString().toLowerCase()?.includes(val) || item?.remark?.toString().toLowerCase()?.includes(val)) : true)} rowKey={'accountId'} scroll={{ y: 220 }} pagination={{ pageSize: 50, showTotal: total => `总共 ${total} 账户` }} loading={getAllUserAccount.loading || loading} columns={[ { title: '账号', dataIndex: 'accountId', key: 'accountId', width: 80, align: 'center', render(value) { return {value} } }, { title: '企业', dataIndex: 'corporationName', key: 'corporationName', width: 180, ellipsis: true, render(value) { return {value} } }, { title: '企业标识', dataIndex: 'corporationLicence', key: 'corporationLicence', width: 150, ellipsis: true, render(value) { return {value} } }, { title: '备注', dataIndex: 'remark', key: 'remark', ellipsis: true, render(value) { return {value || '--'} } }, ]} rowSelection={{ selectedRowKeys: selectedRows.map(item => item.accountId), onSelect: (record: { accountId: number }, selected: boolean) => { if (selected) { selectedRows.push({ ...record }) setSelectedRows([...selectedRows]) } else { let newSelectAccData = selectedRows.filter((item: { accountId: number }) => item.accountId !== record.accountId) setSelectedRows([...newSelectAccData]) } }, onSelectAll: (selected: boolean, selectedRowss: { accountId: number }[], changeRows: { accountId: number }[]) => { if (selected) { let newSelectAccData = [...selectedRows] changeRows.forEach((item: { accountId: number }) => { let index = newSelectAccData.findIndex((ite: { accountId: number }) => ite.accountId === item.accountId) if (index === -1) { let data: any = { ...item } newSelectAccData.push(data) } }) setSelectedRows([...newSelectAccData]) } else { let newSelectAccData = selectedRows.filter((item: { accountId: number }) => { let index = changeRows.findIndex((ite: { accountId: number }) => ite.accountId === item.accountId) if (index !== -1) { return false } else { return true } }) setSelectedRows([...newSelectAccData]) } } }} />
} {visible &&
} {tipsVisible && 提示} open={tipsVisible} onCancel={() => { setTipsVisible(false) }} onOk={() => handleOk(true)} className="modalResetCss" okText="清空" cancelText="留下来修改账户" >选择的素材有账户组素材,但是与当前账户不匹配,是否使用当前账号清空素材?} } export default React.memo(SelectAccount)