import * as React from 'react'; import classnames from 'classnames'; import Organization from './Organization'; import FastOS from './FastOS'; import VS from './VS'; import './index.scss'; export interface OperationType { title: string; icon: string; color: string; badge: number; data?: any; vs?: boolean; addVS?: Function; deleteOneVS?: Function; type: string; showComponent?: Function; defaultHover: boolean } class Item extends React.PureComponent { state = { dispalyComponent: false } ele: any componentDidMount() { document.addEventListener('click', this.hideComponent, true); } hideComponent: any = (e: React.MouseEvent) => { const el: any = this.ele; if (el && el.contains && !el.contains(e.target)) { this.setState({ dispalyComponent: false }) } } handleClick = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { showComponent, type } = this.props; showComponent && showComponent(type, this.ele) this.setState({ dispalyComponent: true }) } render() { const { title, icon, color, badge, type, defaultHover } = this.props; const { dispalyComponent } = this.state; const titleClass = classnames( 'quick-operation-title' ); return (
this.ele = node} >
{ type == 'vs' && badge > 0 ? 待对比{badge}人 : title }
{ dispalyComponent ? null : badge > 0 && {badge} }
) } } export interface QuickOperationProps { honorPageOperation: any users: any[] addVS: Function deleteOneVS: Function; defaultHover?: boolean; } export interface QuickOperationState { showTitle: string, showEle: any, defaultHover: boolean; displayOrganization: boolean; displayQuickHandle: boolean; displayVS: boolean; } export default class QuickOperation extends React.PureComponent { constructor(props: QuickOperationProps) { super(props); this.state = { displayOrganization: false, displayQuickHandle: false, displayVS: false, showTitle: '', showEle: null, defaultHover: this.props.defaultHover !== false } } static defaultProps = { defaultHover: true } componentDidMount() { document.addEventListener('click', this.hideComponent, true); } componentWillUnmount() { document.removeEventListener('click', this.hideComponent, true); } ele: any hideComponent: any = (e: React.MouseEvent) => { const el: any = this.ele; if (el && el.contains && !el.contains(e.target)) { this.setState({ displayOrganization: false, displayQuickHandle: false }) } } getOperationTypes = () => { const { honorPageOperation, users, addVS, deleteOneVS } = this.props; const { defaultHover } = this.state; if (honorPageOperation === undefined) { return [ { type: 'relation', title: '汇报关系', icon: 'tu-icon-departmentmanage', color: '#F5D540', defaultHover, badge: 0 }, { type: 'operation', title: '人才操作', icon: 'font-circle-add', color: '#FF9500', defaultHover, badge: 0 }, { type: 'vs', title: '人才对比', icon: 'font-circle-vs', color: '#55C6C6', defaultHover, badge: users.length } ] } else { const data: OperationType[] = []; const { operationData } = honorPageOperation; const { vs = true } = honorPageOperation; if (honorPageOperation.relation) { data.push({ type: 'relation', title: honorPageOperation.relationTitle || '汇报关系', icon: 'tu-icon-departmentmanage', color: '#F5D540', vs, addVS, badge: 0, defaultHover }) } if (honorPageOperation.operation) { data.push({ type: 'operation', title: '人才操作', icon: 'font-circle-add', color: '#FF9500', badge: 0, data: operationData, defaultHover }) } if (vs) { data.push({ type: 'vs', title: '人才对比', icon: 'font-circle-vs', color: '#55C6C6', badge: users.length, deleteOneVS, defaultHover }) } return data; } } componentWillReceiveProps(nextProps: QuickOperationProps) { // this.setState({ // users: nextProps.users || [] // }) } showComponent = (type: string, ele: any) => { const { displayVS, displayOrganization, displayQuickHandle } = this.state; this.setState({ displayOrganization: displayOrganization && type == 'vs' ? displayOrganization : type == 'relation', displayQuickHandle: displayQuickHandle && type == 'vs' ? displayQuickHandle : type == 'operation', displayVS: type == 'vs' && !displayVS ? true : displayVS, defaultHover: false }) } closeComponent = (type?: string) => { const { displayOrganization, displayQuickHandle, displayVS } = this.state if (type) { this.setState({ displayOrganization: type == 'relation' ? false : displayOrganization, displayQuickHandle: type == 'operation' ? false : displayQuickHandle, displayVS: type == 'vs' ? false : displayVS }) } else { this.setState({ displayOrganization: false, displayQuickHandle: false, displayVS: displayVS }) } } refs: any showOrganization = () => { const { honorPageOperation, addVS } = this.props; const { vs = true, operation = true } = honorPageOperation; const OrganizationEle = this.refs.relation.ele; return } showQuickHandle = () => { const { honorPageOperation } = this.props; const { operationData } = honorPageOperation; const QuickHandleEle = this.refs.operation.ele; return } showVS = () => { const { users, deleteOneVS } = this.props; const VSEle = this.refs.vs.ele; return } manualToShowOrganization = () => { this.setState({ displayOrganization: true }) } manualToShowVS = () => { this.setState({ displayVS: true }) } render() { const operationTypes = this.getOperationTypes(); const { displayOrganization, displayQuickHandle, displayVS } = this.state; return (
this.ele = node} > {/* */} { displayOrganization ? this.showOrganization() : null } {/* */} {/* */} { displayQuickHandle ? this.showQuickHandle() : null } {/* */} {/* */} { displayVS ? this.showVS() : null } {/* */} { operationTypes.map((item: OperationType, index: number) => { return ( ) }) }
) } }