import * as React from 'react'; import GetSpotPos from './GetSpotPos'; import './index.scss' import AvatarImg from '../../../../components/common/avatarImg/avatarImg.tsx'; import { getApiUrl, taker, getQueryString, getUserInfo } from '../../../../helper'; import PropTypes from 'prop-types'; class SpotItem extends React.Component { render() { const { setSpotPos, getAddVSBtn, levelTitle, name, index, personalPictureUrl, avatarColor, userId, hasAddVS, canVS, showTip, onMouseEnter } = this.props; const spotStyle = Object.assign({}, setSpotPos(index), { zIndex: showTip ? 10 : 1 }) return (
{levelTitle}
{name}
{ canVS ? getAddVSBtn(userId, hasAddVS) : null }
) } } interface Url { s: string, l: string, n: string, b: string } export interface RadarUserProps { userId: number; name: string; hasAvatar: boolean; avatarColor: string; personalPictureUrl: Url; levelTitle?: string; x?: number; y?: number; hasAddVS: boolean; showTip: boolean } interface RadarProps { keyword: string; addVSCallback: Function; canVS: boolean; users: any[]; showVS: Function; } interface RadarState { isFetching: boolean; currentUser: any; subordinateUsers: any; autoPlayTip: boolean; talentVSUsers:number[] } export default class Radar extends React.Component { spotIndex: number; subordinateUsersPos: any[] static contextTypes = { getSelectedUsers: PropTypes.func, updateSelectedUsers: PropTypes.func, showPromptPop: PropTypes.func }; constructor(props: RadarProps) { super(props); this.spotIndex = 0; this.subordinateUsersPos = []; this.state = { isFetching: true, currentUser: {}, subordinateUsers: [], autoPlayTip: true, talentVSUsers:[] } new GetSpotPos(this.getSpotPos) } componentDidMount() { this.getRadarData() } getRadarData = async () => { const toUserId = getQueryString()['to_user_id']; const loginId = getUserInfo()['Id'] const pageCode = getQueryString()['pageCode'] ? getQueryString()['pageCode'] : ''; const url = getApiUrl(`proxy/GetUPaaSCoreGateway/AccountService/GetUserRadarChart?toUserId=${toUserId || loginId}&originPageCode=${pageCode}`); const response = await taker(url); if (response && response.Code === 200) { const { getSelectedUsers, } = this.context; const selectedUsers = getSelectedUsers(); const { OperationObject } = response; const { CurrentUser, DirectSubordinates, SecondSubordinates ,TalentVSUsers} = OperationObject; const subordinateUsers: RadarUserProps[] = []; DirectSubordinates.forEach((item: any) => { item.levelTitle = '直接下级'; }) SecondSubordinates.forEach((item: any) => { item.levelTitle = '隔级下级'; }) const mergeSubordinates = DirectSubordinates.concat(SecondSubordinates); mergeSubordinates.forEach((item: any, index: number) => { let hasAddVS = false; if (selectedUsers.find((i: any) => i.UserId == item.UserId)) { hasAddVS = true; } if (index < 10) { subordinateUsers.push({ userId: item.UserId, name: item.Name, hasAvatar: item.HasAvatar, avatarColor: item.AvatarColor, personalPictureUrl: item.PersonalPictureUrl, levelTitle: item.levelTitle, hasAddVS, showTip: false }) } }) this.setState({ isFetching: false, currentUser: { userId: CurrentUser.UserId, name: CurrentUser.Name, hasAvatar: CurrentUser.HasAvatar, avatarColor: CurrentUser.AvatarColor, personalPictureUrl: CurrentUser.PersonalPictureUrl, hasAddVS: !!selectedUsers.find((i: any) => i.UserId == CurrentUser.UserId) }, subordinateUsers, talentVSUsers:TalentVSUsers }) this.autoPlayTip() } } timer: any = null; componentWillUnmount() { clearInterval(this.timer) } autoPlayTip = () => { clearInterval(this.timer) this.timer = setInterval(() => { let newSubordinateUsers: RadarUserProps[] = []; const { subordinateUsers } = this.state; const { mouseEnter } = this; newSubordinateUsers = subordinateUsers.map((item: RadarUserProps, index: number) => { let num = parseInt(String(Math.random() * 10)); item.showTip = mouseEnter ? false : num == index; return item }) if (mouseEnter) clearInterval(this.timer) this.setState({ subordinateUsers: newSubordinateUsers }) }, 1000) } getSpotPos = (data: any) => { const { x, y } = data; this.subordinateUsersPos.push({ x, y }) } setSpotPos = (index: number) => { const pos = this.subordinateUsersPos[index]; return { left: pos.x, top: pos.y, width: index < 4 ? 50 : 30 } } addVSUser = (userId?: any) => (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 { subordinateUsers, currentUser } = this.state; currentUser.hasAddVS = !!selectedUsers.find((i: any) => i.UserId == currentUser.userId); const newSubordinateUsers: any[] = subordinateUsers.map((item: any) => { item.hasAddVS = false; if (selectedUsers.find((i: any) => i.UserId == item.userId)) { item.hasAddVS = true; } return item; }) this.setState({ subordinateUsers: newSubordinateUsers, currentUser }) } getAddVSBtn = (userId: number, hasAddVS: boolean) => { if (hasAddVS) return 已添加 return +对比 } getCenterAddVSBtn = (userId: number, hasAddVS: boolean, name: string) => { if(this.state.talentVSUsers.find((d:number)=>d==userId)){ if (hasAddVS) return 已添加 return +对比 }else{ return '' } } mouseEnter: boolean = false handleMoudeEnter = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.mouseEnter = true; } handleMouseLeave = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.mouseEnter = false; this.autoPlayTip() } handleUserMouseEnter = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.dealUsers() } render() { const { canVS } = this.props; const { currentUser, subordinateUsers, isFetching } = this.state; return (
{ isFetching ? null :
{currentUser.name}
{ canVS ? this.getCenterAddVSBtn(currentUser.userId, currentUser.hasAddVS, currentUser.name) : null }
{subordinateUsers.map((item: RadarUserProps, index: number) => { return })}
}
) } }