import * as React from 'react'; import { Scrollbars } from 'react-custom-scrollbars'; import { taker, getApiUrl, getQueryString, getUserInfo, getBSGlobal, encodeURIFnTop } from '&/helper'; import AvatarImg from '&/components/common/avatarImg/avatarImg.tsx'; import './index.scss'; export interface UserInterface { name: string; userId: number; color: string; avatar: string; position: string; } export interface RightFixedProps { hisPeers: boolean; hisSubordinate: boolean; hisSimilar: boolean; hisVistors: boolean; supportVs: boolean; } export interface RightFixedState { peers: UserInterface[]; subordinate: UserInterface[]; similar: UserInterface[]; vistors: UserInterface[]; showAllPeers: boolean; showAllSubordinate: boolean; toVSPeersLink: string; toVSSubordinateLink: string; isFetching: boolean; scrollTop: number } export default class RightFied 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 } if (hisPeers || hisSubordinate || hisSimilar || hisVistors) this.getUsers(props); } componentWillReceiveProps(nextProps: RightFixedProps) { const { hisPeers, hisSubordinate, hisSimilar, hisVistors, } = nextProps; if (hisPeers || hisSubordinate || hisSimilar || hisVistors) this.getUsers(nextProps); } willUnmount = false componentWillUnmount() { this.willUnmount = true } getUsers = async (props: RightFixedProps) => { const { hisPeers, hisSubordinate, hisSimilar, hisVistors, supportVs } = props; // samelevel,directsub,similar,visitor const loginId = getUserInfo().Id; const toUserId = getQueryString()['to_user_id']; const getVistorsUrl = getApiUrl(`proxy/GetUPaaSCoreGateway/AccountService/GetRecommendComponentInfo?toUserId=${toUserId || loginId}&configStr=${hisPeers ? 'samelevel,' : ''}${hisSubordinate ? 'directsub,' : ''}${hisSimilar ? 'similar,' : ''}${hisVistors ? 'visitor,' : ''}`); const res = await taker(getVistorsUrl); if (res && res.Code == 200) { const { OperationObject } = res; if (OperationObject) { const { sameLevelColleagues, directSubordinates, similarColleagues, visitorColleagues } = OperationObject; const peers = hisPeers ? sameLevelColleagues || [] : [], subordinate = hisSubordinate ? directSubordinates || [] : []; this.setState({ isFetching: false, peers, subordinate, similar: hisSimilar ? similarColleagues || [] : [], vistors: hisVistors ? visitorColleagues || [] : [], }) if (peers.length && supportVs) { this.setPeersToVSLink(peers) } if (subordinate.length && supportVs) { this.setSubordinateToVSLink(subordinate) } } } } handleSeeHisHonourPage = (userId: any) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const isEdit = getQueryString().isEdit; const { origin, pathname } = location; const title = getQueryString().pageTitle; const gotoHash = `#/HonourView?pageTitle=${title}&layout=honour&to_user_id=${userId}`; const gotoHref = `${origin}${pathname}${gotoHash}`; if (isEdit == 'true') { location.href = gotoHref } else { location.hash = gotoHash } // changeQueryString('to_user_id', userId) } 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) => { // let toVSUsers: UserInterface[] = []; 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 // urls[0] = api; // const url = urls. } toVSPeersBtn: any; toVSSubordinateBtn: any render() { const { peers, subordinate, similar, vistors, showAllPeers, showAllSubordinate, toVSPeersLink, toVSSubordinateLink, isFetching, scrollTop } = this.state; const { hisPeers, hisSubordinate, hisSimilar, hisVistors, supportVs } = 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 } return (
{ (noData && !isFetching) ?
这里将会
为您推荐相关的人,
目前还没有任何推荐哦~
: null } { hisPeers && peers.length ?
{`${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}的同级 `}({peers.length}) { peers.length > 4 ? { showAllPeers ? '收起' : '全部' } : null }
{showPeers.map((item: any, index: number) => { return (
{item.Name}
{ item.PositionName ?
{item.PositionName}
: null }
) }) } { supportVs ? 一键对比 : null }
: null } { hisSubordinate && subordinate.length ?
{`${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}的下属 `}({subordinate.length}) { subordinate.length > 5 ? { showAllSubordinate ? '收起' : '全部' } : null }
{ subordinate.length ?
{showSubordinate.map((item: any, index: number) => { return (
{item.Name}
{ item.PositionName ?
{item.PositionName}
: null }
) }) } { supportVs ? 一键对比 : null }
: null }
: null } { hisSimilar && similar.length ?
{`与${tarId ? tarId == selfId ? '我' : 'Ta' : '我'}相似的`}
{ similar.map((item: any, index: number) => { if (index < 9) { return (
{item.Name}
) } else { return '' } }) }
: null } { hisVistors && vistors.length ?
最近访客
{vistors.map((item: any, index: number) => { if (index < 10) { return (
) } else { return null; } }) }
: null }
) } }