import React from 'react' import { IOrganization } from '../types' const styles = require('../Organization.less') import { Tag, Icon, Popconfirm, Tooltip } from 'antd' import ComponentPermission from 'containers/Account/components/checkMemberPermission' import Star from 'components/StarPanel/Star' import { IProject, IStarUser } from 'containers/Projects/types' interface IProjectItemProps { key: number pro: IProject, toProject: (id: number) => any loginUser: any deleteProject?: (id: number) => any collectProjects: IProject[] currentOrganization: IOrganization unStar?: (id: number) => any userList?: (id: number) => any showEditProjectForm: (type: string, option: any) => any onClickCollectProjects: (formType: string, project: object, resolve: (id: number) => any) => any onLoadCollectProjects: () => any } interface IPropsState { currentCollectProjectIds: any[], isDisableCollect: boolean } export class ProjectItem extends React.PureComponent { constructor (props) { super(props) this.state = { currentCollectProjectIds: [], isDisableCollect: false } } public componentWillReceiveProps (nextProps) { const { collectProjects } = nextProps this.setState({ currentCollectProjectIds: collectProjects ? collectProjects.map((cp) => cp.id) : [] }) } private stopPPG = (e) => { e.stopPropagation() } private showProjectForm = (formType, option) => (e) => { this.stopPPG(e) this.props.showEditProjectForm(formType, option) } private collectProjectItem = (formType, option) => (e) => { const { onClickCollectProjects, collectProjects } = this.props this.stopPPG(e) const { currentCollectProjectIds } = this.state onClickCollectProjects(formType, option.id, () => { if (formType === 'collect') { currentCollectProjectIds.push(option.id) this.setState({ currentCollectProjectIds, isDisableCollect: true }) } else { this.setState({ currentCollectProjectIds: currentCollectProjectIds.length !== 0 ? currentCollectProjectIds.filter((item) => item !== option.id) : collectProjects.filter((cp) => cp.id !== option.id), isDisableCollect: false }) } }) } public render () { const { pro, loginUser, currentOrganization, collectProjects} = this.props const { currentCollectProjectIds } = this.state let currentCollectIds = [] if (currentCollectProjectIds.length) { currentCollectIds = currentCollectProjectIds } else if (collectProjects) { currentCollectIds = collectProjects.map((cp) => cp.id) } const tags = (
{pro.createBy.id === loginUser.id ? 我创建的 : ''}
) let CreateButton = void 0 if (currentOrganization) { CreateButton = ComponentPermission(currentOrganization, '')(Icon) } // const bg = require(`assets/images/bg${pro.pic}.png`) let StarPanel = void 0 if (pro) { const { isStar, starNum, id} = pro StarPanel = } return (
{pro.name}
{pro.description}
{tags}
{StarPanel} { (loginUser.id === pro.createBy.id) ? '' : (
{ currentCollectIds.indexOf(pro.id) < 0 ? ( ) : ( ) }
) }
) } } export default ProjectItem