import * as React from 'react' import Search from '../../../components/common/Search'; import Radar from "./Radar"; import UserList from "./UserList"; import UserTree from "./UserTree"; import './scss/index.scss'; import PropTypes from 'prop-types' import { getQueryString, getUserInfo } from '../../../helper'; // import QueueAnim from 'rc-queue-anim'; interface OrgnitionProps { addVS?: Function; referenceNode: any; closeComponent: Function; canVS: boolean; operation: boolean; type: string; showVS: Function; } interface OrgnitionTreeState { step: number; keyword: string; currentUserId: number; } const Components = [ UserTree, Radar, UserList ] export default class Orgnition extends React.PureComponent{ hadleClick = (e: React.MouseEvent) => { e.stopPropagation() e.nativeEvent.stopImmediatePropagation() } state: any; curIndex: number; constructor(props: OrgnitionProps) { super(props); // const { Top, top } = this.getPosition(); const loginId = getUserInfo()['Id']; const toUserId = getQueryString()['to_user_id'] this.state = { keyword: '', step: 0, currentUserId: toUserId || loginId } } static contextTypes = { getTouserId: PropTypes.func }; getPosition = () => { const { referenceNode } = this.props; let { top } = referenceNode.getBoundingClientRect(); let newTop = 0, newtop = 0; if (top >= 487) { newTop = -487; newtop = 467 } if (top < 487) { newTop = -top; newtop = 467 - (487 - top) } return { Top: newTop, top: newtop } } componentWillReceiveProps(nextProps: OrgnitionProps) { } addVS = (id: number) => { this.props.addVS && this.props.addVS(id) } searchFocus = (data: any) => { const { keyword } = this.state; this.setState({ step: keyword ? 2 : 1 }) } searchChange = (data: any) => { const { value } = data; const keyword = value.trim(); this.setState({ keyword, step: keyword ? 2 : 1 }) } searchCancle = (data: any) => { this.setState({ keyword: '', step: 0 }) } searchHandler = (data: any) => { const { eventType } = data; switch (eventType) { case "focus": this.searchFocus(data); break; case "change": this.searchChange(data); break; case "cancle": this.searchCancle(data); break; } } handleWrapClick = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); } toHisOrganization = (userId: number) => { this.searchRef.handleCancle() this.setState({ keyword: '', step: 0, currentUserId: userId }) } getComponent = () => { const { step, keyword, currentUserId } = this.state; const { canVS, showVS } = this.props; const Component = Components[step]; return } closeComponent = (e: React.MouseEvent) => { const { closeComponent, type } = this.props; closeComponent && closeComponent(type) } searchRef: any render() { const searchProps = { handlerCallback: this.searchHandler } const { canVS, operation } = this.props; const tailOnBottom = !operation || (!canVS && !operation); return (
this.searchRef = node} />
{ this.getComponent() }
) } }