import * as React from 'react'; import { Scrollbars } from 'react-custom-scrollbars'; import { taker, getApiUrl, getQueryString, getUserInfo, getBSGlobal, encodeURIFnTop,getToUserId } from '../../helper'; import AvatarImg from '../../components/common/avatarImg/avatarImg.tsx'; import './index.scss'; import {RightFixedProps, RightFixedState} from './defaultData' import ToolTip from '@beisen/tool-tip'; export default class RightFixed extends React.PureComponent { constructor(props: RightFixedProps) { super(props); const { hisPeers, hisSubordinate, hisSimilar, hisVistors, } = props; this.state = { peers: [], subordinate: [], similar: [], vistors: [], showAllPeers: false, showAllSubordinate: false, toVSPeersLink: 'javascript:;', toVSSubordinateLink: 'javascript:;', isFetching: true, scrollTop: 0, showVsButton: false, showSubordinateVs: false } if (hisPeers || hisSubordinate || hisSimilar || hisVistors) { this.getUsers(props); } } toVSPeersBtn: any; toVSSubordinateBtn: any willUnmount = false componentWillReceiveProps(nextProps: RightFixedProps) { let origin = JSON.stringify(this.props); let next = JSON.stringify(nextProps); if(next != origin){ this.getUsers(nextProps); } } componentWillUnmount() { this.willUnmount = true } getUsers = async (props: RightFixedProps) => { const { hisPeers, hisSubordinate, hisSimilar, hisVistors, supportVs } = props; const loginId = getUserInfo()['Id']; const toUserId = getQueryString()['to_user_id']; const pageCode = getQueryString()['pageCode'] ? getQueryString()['pageCode'] : ''; const getVistorsUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/AccountService/GetRecommendComponentInfo?toUserId=${toUserId || loginId}&configStr=${hisPeers ? 'samelevel,' : ''}${hisSubordinate ? 'directsub,' : ''}${hisSimilar ? 'similar,' : ''}${hisVistors ? 'visitor,' : ''}&originPageCode=${pageCode}`); const res = await taker(getVistorsUrl); if (res && res.Code == 200) { const { OperationObject } = res; if (OperationObject) { const { sameLevelColleagues, directSubordinates, similarColleagues, visitorColleagues, canVsSameLevel } = OperationObject; const peers = hisPeers ? sameLevelColleagues || [] : [], subordinate = hisSubordinate ? directSubordinates || [] : []; // https://setting.italent.link/api/v1/245494/201038245/proxy/GetUPaaSCoreGateway/AccountService/IsAllCanBeVSed?userIds=201038245,201038395,201038396 let uids: number[] uids = subordinate.map((item: any, index: number) => { return item.UserId }) // 判断获取到的下级是否都有权限进行对比\ const verificationUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/AccountService/IsAllCanBeVSed?userIds=${uids}&originPageCode=${pageCode}`) const verificationRes = await taker(verificationUrl); if (this.willUnmount) return; this.setState({ isFetching: false, peers, subordinate, similar: hisSimilar ? similarColleagues || [] : [], vistors: hisVistors ? visitorColleagues || [] : [], showVsButton: canVsSameLevel, showSubordinateVs: verificationRes && verificationRes.Code == 200 ? verificationRes.OperationObject : false }) if (peers.length && supportVs) { this.setPeersToVSLink(peers) } if (subordinate.length && supportVs) { if (verificationRes && verificationRes.Code == 200 && !verificationRes.OperationObject) return this.setSubordinateToVSLink(subordinate) } } } } handleSeeHisHonourPage = (userId: any) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const gotoHash = `#/okr/panel?&to_user_id=${userId}`; location.hash = gotoHash } handleVS = (users: any) => { if (users.length) { let sexs = [0, 0]; let ages = [0, 0]; let enrolledYears = [0, 0]; let userIds: any[] = []; users.forEach((item: any, index: number) => { userIds.push(item.UserId); if (!item.Sex || item.Sex === '2' || item.Sex === '0') { sexs[0] = sexs[0] + 1 } else { sexs[1] = sexs[1] + 1 } if (item.Age) { ages[0] += parseInt(item.Age) ages[1] += 1 } if (item.EnrolledYears) { enrolledYears[0] += parseInt(item.EnrolledYears) enrolledYears[1] += 1 } }) const avaAge = ages[1] === 0 ? 0 : (ages[0] / ages[1]).toFixed(1); const avaYear = enrolledYears[1] === 0 ? 0 : (enrolledYears[0] / enrolledYears[1]).toFixed(1); const uid = getUserInfo()['Id']; const apiServer = getBSGlobal('apiPath'); const url = encodeURIFnTop(`${apiServer}/${uid}/TalentVS#/home?pageId=065a79fd-3884-4757-9f71-a6890ec9e721&uids=${userIds}&sexs=${sexs}&ave_year=${[avaAge, avaYear]}`); // http://www.upaas.link/201138437/UpaasHome#widget/italent-no-sidebar?iTalentFrame=admin.upaas.link/201138437/TalentVS#/home?pageId=065a79fd-3884-4757-9f71-a6890ec9e721&uids=201138437,201138343,201153307,201153313,201153314&sexs=1,1&ave_year=0,0.1 window.open(url) } } setPeersToVSLink = (peers: any) => { const toUserID = getQueryString()['to_user_id'] || getUserInfo()['Id']; let peerUserIds = [toUserID]; peers.forEach((item: any, index: number) => { if (index < 4) { peerUserIds.push(item.UserId) } }) this.GetTalentVsLink(peerUserIds).then(talentVsLink => { if (talentVsLink && talentVsLink.OperationObject) { const newUrl = this.changUrl(talentVsLink.OperationObject) const url = encodeURIFnTop(`//${newUrl}`) if (!this.willUnmount) { this.setState({ toVSPeersLink: url }) } } }) } setSubordinateToVSLink = (subordinate: any) => { let subordinateUserIds: any[] = []; subordinate.forEach((item: any, index: number) => { if (index < 5) { subordinateUserIds.push(item.UserId) } }) this.GetTalentVsLink(subordinateUserIds).then(talentVsLink => { if (talentVsLink && talentVsLink.OperationObject) { const newUrl = this.changUrl(talentVsLink.OperationObject) const url = encodeURIFnTop(`//${newUrl}`) if (!this.willUnmount) { this.setState({ toVSSubordinateLink: url }) } } }) } GetTalentVsLink = async (userIds: any[]) => { const url = `${getApiUrl('proxy/PostUPaaSCoreGateway/TalentVS/GetTalentVsLink')}`; return await taker(url, 'post', { userIds }) } handleShowAllPeers = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); e.preventDefault(); const { showAllPeers } = this.state; this.setState({ showAllPeers: !showAllPeers }) } handleShowAllSubordinate = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); e.preventDefault(); const { showAllSubordinate } = this.state; this.setState({ showAllSubordinate: !showAllSubordinate }) } scrollbarCallback = (data: any) => { this.setState({ scrollTop: data.scrollTop }) } changUrl = (url: string) => { let urls = url.split('/').slice(1).join('/'); const api = getBSGlobal('apiPath'); return api + '/' + urls } handleToggle = () => { const {onToggle} = this.props; onToggle&& onToggle() } render() { const { peers, subordinate, similar, vistors, showAllPeers, showAllSubordinate, toVSPeersLink, toVSSubordinateLink, isFetching, scrollTop, showVsButton, showSubordinateVs } = this.state; const { hisPeers, hisSubordinate, hisSimilar, hisVistors, supportVs, showBottomCover,hide } = this.props; const tarId = getQueryString()['to_user_id']; const selfId = getUserInfo()['Id']; let noData = true; let showPeers = peers; let showSubordinate = subordinate; if (peers.length) { if (!showAllPeers) showPeers = peers.slice(0, 4) } if (subordinate.length) { if (!showAllSubordinate) showSubordinate = subordinate.slice(0, 5) } if ((hisPeers && peers.length) || (hisSubordinate && subordinate.length) || (hisSimilar && similar.length) || (hisVistors && vistors.length)) { noData = false } let url = getBSGlobal('apiPath')+ '/u/'+getBSGlobal('loginUserInfo').Id+'/home#/okr/panel'; return
{ getToUserId() != selfId && } { noData && !isFetching &&
这里将会
为您推荐相关的人,
目前还没有任何推荐哦~
} { hisPeers && !!peers.length &&
{`${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}的同级 (${peers.length})`} { peers.length > 4 && { showAllPeers ? '收起' : '全部' } }
{showPeers.map((item: any, index: number) => { return
{item.Name}
{ item.PositionName &&
{item.PositionName}
}
}) } { supportVs && showVsButton && 一键对比 }
} { hisSubordinate && !!subordinate.length &&
{`${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}的下属 (${subordinate.length})`} { subordinate.length > 5 && { showAllSubordinate ? '收起' : '全部' } }
{ subordinate.length &&
{showSubordinate.map((item: any, index: number) => { return
{item.Name}
{ item.PositionName &&
{item.PositionName}
}
}) } { supportVs && showSubordinateVs && 一键对比 }
}
} { hisSimilar && !!similar.length &&
{`与${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}相似的`}
{ similar.map((item: any, index: number) => { return index < 9 ?
{item.Name}
: null }) }
} { hisVistors && !!vistors.length &&
最近访客
{ vistors.map((item: any, index: number) => { return index < 10 ?
: null }) }
}
} }