import * as React from 'react'; import './index.scss'; import AvatarImg from '../../../../components/common/avatarImg/avatarImg.tsx'; import FormatKeyword from '../../../../components/common/formatKeyword'; import { getApiUrl, taker,getQueryString } from '../../../../helper'; import PropTypes from 'prop-types'; import { Scrollbars } from 'react-custom-scrollbars'; export interface UserProps { userId: number; name: string; hasAvatar: boolean; avatarColor: string; personalPictureUrl: string; department: string; position: string; hasAddVS: boolean } interface UserListProps { keyword: string; addVSCallback: Function; canVS: boolean; users: any[]; toHisOrganization: Function; showVS: Function; } interface UserListState { userList: UserProps[]; isFetching: boolean; talentVSUsers:any[] } export default class UserList extends React.Component{ static contextTypes = { getSelectedUsers: PropTypes.func, updateSelectedUsers: PropTypes.func, showPromptPop: PropTypes.func }; total = 0; topPosition = 0; pageIndex = 1; constructor(props: UserListProps) { super(props); const { keyword } = props; this.getSearchUserData(keyword, this.pageIndex) this.state = { userList: [], isFetching: true, talentVSUsers:[] } } getSearchUserData = async (str: string, pageIndex: number) => { // http://setting.italent-inc.cn/api/v1/204233/100373299/Search/Staffs?filter=test&pinyin=&page_num=1&page_size=20 // http://setting.italent-inc.cn/api/v1/204233/100373299/Search/Staffs?filter=%E7%9A%84&pinyin=&page_num=1&page_size=20000 const url = getApiUrl(`Search/Staffs?filter=${str}&pinyin=&page_num=${pageIndex}&page_size=20`); const response = await taker(url); if (response.Code == 1) { const { userList ,talentVSUsers} = this.state; const { getSelectedUsers, } = this.context; const selectedUsers = getSelectedUsers(); // 判别搜索出来的人是否有加人权限 let userId:any[] = [] response.Data.Users.map((item:any,i:number)=>{ userId.push(item.UserId) }) const pageCode = getQueryString()['pageCode'] ? getQueryString()['pageCode'] : ''; const fetchUrl = `${getApiUrl('proxy/GetUPaaSCoreGateway/AccountService/GetCanBeVSedUsers')}?userIds=${userId}&originPageCode=${pageCode}`; const fetchRes = userId.length > 0 && await taker(fetchUrl); let fetchIds:any[] = [] if(fetchRes.Code == 200){ fetchIds = fetchRes.OperationObject; } // const searchUserList: any = []; this.total = response.Data.Total; response.Data.Users.forEach((item: any) => { let hasAddVS = false; if (selectedUsers.find((i: any) => i.UserId == item.UserId)) { hasAddVS = true; } searchUserList.push({ userId: item.UserId, name: item.UserName, hasAvatar: item.HasAvatar, avatarColor: item.Color, personalPictureUrl: item.MediumPicture, department: item.Department, position: item.Position, hasAddVS }) }) this.setState({ isFetching: false, userList: pageIndex == 1 ? searchUserList : userList.concat(searchUserList), talentVSUsers: pageIndex == 1 ? fetchIds : talentVSUsers.concat(fetchIds) }) } } changeTimer: any componentWillReceiveProps(nextProps: UserListProps) { const { keyword } = nextProps; this.total = 0; this.topPosition = 0; this.pageIndex = 1; this.setState({ isFetching: true, userList: [] }) clearTimeout(this.changeTimer) this.changeTimer = setTimeout(() => { this.getSearchUserData(keyword, 1); }, 300) } addUserVs = (userId?: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); if (!userId) return; const { updateSelectedUsers, getSelectedUsers, showPromptPop } = this.context; const selectedUsers = getSelectedUsers(); if (selectedUsers.length == 5) { showPromptPop() return; } const node = e.currentTarget; const { showVS } = this.props; showVS && showVS(); updateSelectedUsers(userId, node).then((newUsers: any) => { this.dealUsers(); }) } dealUsers = () => { const { getSelectedUsers, } = this.context; const selectedUsers = getSelectedUsers(); const { userList } = this.state; const newUserList: any[] = userList.map((item: any) => { item.hasAddVS = false; if (selectedUsers.find((i: any) => i.UserId == item.userId)) { item.hasAddVS = true; } return item; }) this.setState({ userList: newUserList }) } getAddVSBtn = (userId: number, hasAddVS: boolean) => { if(this.state.talentVSUsers.find((d:any)=>d == userId)){ if (hasAddVS) return 已添加 return +对比 }else{ return '' } } handleScrollFrame = (Signature: any) => { const { scrollTop } = Signature; const { userList, isFetching } = this.state; const { total } = this; const { keyword } = this.props; const userListLen = userList.length; this.topPosition = scrollTop; if (isFetching) return; if (scrollTop > (userListLen - 14) * 50 && userListLen < total) { this.pageIndex += 1; this.setState({ isFetching: true }) this.getSearchUserData(keyword, this.pageIndex); } } handelToOrganization = (userId: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { toHisOrganization } = this.props; toHisOrganization(userId) } handleUserMouseEnter = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.dealUsers() } render() { const { canVS, keyword } = this.props; const { userList, isFetching } = this.state; return
{ isFetching && this.pageIndex == 1 ?
Loading……
: null } //
// } > { userList.length ? userList.map((item: UserProps, index: number) => { return (
{FormatKeyword(item.name, keyword)}
{item.department}{item.position ? item.department ? `/${item.position}` : item.position : null}
{ canVS ? this.getAddVSBtn(item.userId, item.hasAddVS) : null }
) }) :
没有搜索到当前信息
}
} }