import styles from '@/components/InvitingPersonnelModal/index.module.scss' import { Button, Checkbox, Input, Modal, Pagination, Radio, message } from 'antd'; import { useState, useImperativeHandle, forwardRef, useEffect } from "react"; import { SearchOutlined } from '@ant-design/icons'; import { GetUserList } from '@/api/Home/User'; import { useLocation } from 'react-router-dom'; import { GetRoomUser, PostRoomInvite } from '@/api/Meeting'; import { storage } from '@/utils'; import Avatar from '@/components/Avatar'; const InvitingPersonnelModal = forwardRef((props: any, ref: any) => { useImperativeHandle(ref, () => ({ changeInvitingPersonnelModal: () => { let userInfo = JSON.parse(storage.getItem('user') as string) setUser(userInfo) setCheckedList([]) getUserList() setIsInvitingPersonnelModal(true) } })) const { state } = useLocation(); const [isInvitingPersonnelModal, setIsInvitingPersonnelModal] = useState(false); const [isFirstRender, setIsFirstRender] = useState(true); const [user, setUser] = useState(''); const [optionsValue, setOperationValue] = useState(1); const [list, setList] = useState({ data: [], searchKeywod: '', total: 0, pageIndex: 1, pageSize: 5, roomList: [] }) const [checkedList, setCheckedList] = useState([]) useEffect(() => { if (isFirstRender) { setIsFirstRender(false); } else { getUserList() } }, [list.pageIndex]); useEffect(() => { if (isFirstRender) { setIsFirstRender(false); } else { if (list.pageIndex === 1) { getUserList() } else { setList({ ...list, pageIndex: 1 }) } } }, [optionsValue]); useEffect(() => { setList((res: any) => { res.data.forEach((item: any) => { item.checked = checkedList.find((checkedItem: any) => checkedItem.id === item.id) ? true : false; item.disabled = res.roomList.find((row: any) => row.account === item.account) ? true : false; }); return { ...res, data: res.data, } }) }, [list.data]); // 获取用户列表 const getUserList = async (): Promise => { Promise.all([ GetRoomUser(state.channelId), GetUserList({ pageIndex: list.pageIndex, pageSize: list.pageSize, searchKeywod: list.searchKeywod, isOnline: optionsValue === 1 ? true : false, }) ]).then(res => { if (res[0].code === 200 && res[1].code === 200) { setList({ ...list, total: res[1].data.total, data: res[1].data.items, roomList: res[0].data }) } }) } return ( <> setIsInvitingPersonnelModal(false)} centered destroyOnClose={true} width={'700px'} >
} value={list.searchKeywod} onChange={(e) => { setList({ ...list, searchKeywod: e.target.value, }) }} onPressEnter={() => { if (list.pageIndex === 1) { getUserList() } else { setList({ ...list, pageIndex: 1 }) } }} /> { setOperationValue(e.target.value) }} style={{ flexShrink: 0, margin: '10px 0' }} value={optionsValue}> 在线 离线
{list.data.length ? list.data.map((item: any, index: number) =>
{ const newData = [...list.data] as any; newData[index].checked = e.target.checked setList({ ...list, data: newData, }) setCheckedList((checkedList: any) => { if (newData[index].checked) { return [...checkedList, newData[index]] } else { checkedList.splice(checkedList.findIndex((item: any) => item.id === newData[index].id), 1); return checkedList } }) }} disabled={!item.isOnline || item.account === user.account || item.disabled} checked={item.checked}>
{item.userName}{item.account === user.account ? '(我)' : ''}{item.disabled ? '(已入会)' : ''}
{item.isOnline ? '在线' : '离线'}
) : 暂无数据}
{ setList({ ...list, pageIndex: e }) }} pageSize={list.pageSize} current={list.pageIndex} hideOnSinglePage={true} showLessItems={true} />
已选成员
{checkedList.map((item: any, index: number) =>
{item.userName}
)}
) }) export default InvitingPersonnelModal