import * as React from 'react'; // import QueueAnim from 'rc-queue-anim'; import AvatarImg from '../../../../../components/common/avatarImg/avatarImg.tsx'; import PropTypes from 'prop-types'; import {getBSGlobal,getUserInfo} from '../../../../../helper'; export interface User { avatarColor: string; avatarImg: string; name: string; userId: number; position: string; count: number; } export interface SupLevelProps { users: User[], toogleCard: Function; isFetching: boolean; canVS: boolean; addVSCallback: Function; showVS: Function; talentVSUsers: number[]; drillDownUsers: number[]; RedirectToProfileUsers:any } interface SupLevelState { hasAddVS: boolean; } export default class SupLevel extends React.PureComponent{ static contextTypes = { getSelectedUsers: PropTypes.func, updateSelectedUsers: PropTypes.func, showPromptPop: PropTypes.func, handleChangeUser: PropTypes.func, }; constructor(props: SupLevelProps) { super(props); const { users } = props; this.state = { hasAddVS: users.length ? this.confirmHasAddVS(users[0].userId) : false } } componentWillReceiveProps(nextProps: SupLevelProps) { const { users } = nextProps; this.setState( { hasAddVS: users.length ? this.confirmHasAddVS(users[0].userId) : false } ) } handleToogle = (userId: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { toogleCard, drillDownUsers } = this.props; const ids = this.props.RedirectToProfileUsers.find((d:number)=>{ return d==userId}); if (!!ids) { if(this.context.handleChangeUser){ this.context.handleChangeUser(userId) return; } const webPath = getBSGlobal('webPath'); const loginId = getUserInfo()['Id']; const host = getBSGlobal('titaHost'); // const gotoHash = `#/view?layout=honour&to_user_id=${userId}`; const gotoHash = `Home#${`okr/panel?to_user_id=${userId}&isSuper=true`}`; const gotoHref = `${host}/${loginId}/PageBuilderForEdit${gotoHash}`; let iframeBoxUrl = '//www.' if (webPath.indexOf('tita') > -1) { // iframeBoxUrl += `${webPath}/u/${loginId}/Home#${encodeURIComponent(`widget/italent?iTalentFrameType=iframe&iTalentNavId=&iTalentFrame=${encodeURIComponent(gotoHref)}`)}`; iframeBoxUrl += `${webPath}/u/${loginId}/Home#${`okr/panel?to_user_id=${userId}`}`; } if (webPath.indexOf('italent') > -1) { iframeBoxUrl += `${webPath}/${loginId}/ITalentHome#${encodeURIComponent(`widget/italent?iTalentFrameType=iframe&iTalentNavId=&iTalentFrame=${encodeURIComponent(gotoHref)}`)}`; } if (top == self) { location.href = iframeBoxUrl } else { location.hash = gotoHash } return // changeQueryString('to_user_id', userId) } // 判断要查看的人员id是否在允许查看起组织架构的列表中 if (drillDownUsers.find(item => item == userId)) toogleCard('top', userId) } handleAddVS = (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.setState( { hasAddVS: this.confirmHasAddVS(userId) } ) }) } confirmHasAddVS = (userId: number) => { const { getSelectedUsers, } = this.context; const selectedUsers = getSelectedUsers() || []; return selectedUsers.find((item: any) => item.UserId == userId) } getAddVSBtn = (userId: number) => { const { hasAddVS } = this.state; if (this.props.talentVSUsers.find((i: number) => i == userId)) { if (hasAddVS) return 已添加 return +对比 } else { return '' } } handleUserMouseEnter = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { users } = this.props; this.setState( { hasAddVS: this.confirmHasAddVS(users[0].userId) } ) } render() { const { users, isFetching, canVS } = this.props; return (
{ isFetching ? null : users.map((item: User, index: number) => { return (
{ item.count ?
{item.count}
: null }
{item.name}
{ canVS ?
{ this.getAddVSBtn(item.userId) }
: null }
) }) } { users.length ?
: null }
) } }