import { Button, Dropdown, Menu } from "antd"; import React, { useEffect, useState } from "react"; import style from './index.less' import SelectAccount from "./selectAccount"; import { getChannelName } from '@/utils/utils' type Props = { onChange: (value: { MP?: any, ADQ?: any, id: number, accountName: string }[]) => void, value: { MP?: any, ADQ?: any, id: number, accountName: string }[] } function InputAcc(props: Props) { const { value = [], onChange } = props const [selectAccShow, setSelectAccShow] = useState(false) const [data, setData] = useState<{ title: String, num: Number }>({ title: '', num: 0 }) useEffect(() => { if (value.length > 0) { let num = 0 let title = "" for (const iterator of value) { if (iterator?.MP?.length > 0) { title = getChannelName(iterator.accountName) + '-' + iterator?.MP[0].uname break } } value?.forEach((item: any) => { if(item?.MP?.length > 0) { num += item?.MP?.length } }) setData(() => ({ title, num: num !==0 ? num - 1 : 0 })) } }, [value]) const menu = () => { return {value?.map((item: { id: number, accountName: string, MP?: any[], ADQ?: any[] }) => { if ((item?.MP && item?.MP?.length > 0) || (item?.ADQ && item?.ADQ?.length > 0)) { return
{item?.MP && item?.MP?.length > 0 && item?.MP?.map((mp: { id: number, uname: string }) =>
{getChannelName(item?.accountName)}-{mp?.uname}
)}
} else { return null } })}
} return <> {selectAccShow && { setSelectAccShow(false) }} onChange={(e: any) => { onChange(e); setSelectAccShow(false) }} channelAccounts={value} />} {value?.some((item: any) => (item?.MP?.length > 0 || item?.ADQ?.length > 0)) ?
{data.title} {data.num > 0 && +{data.num}}
: } } export default React.memo(InputAcc)