ProjectItem.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React from 'react'
  2. import { IOrganization } from '../types'
  3. const styles = require('../Organization.less')
  4. import { Tag, Icon, Popconfirm, Tooltip } from 'antd'
  5. import ComponentPermission from 'containers/Account/components/checkMemberPermission'
  6. import Star from 'components/StarPanel/Star'
  7. import { IProject, IStarUser } from 'containers/Projects/types'
  8. interface IProjectItemProps {
  9. key: number
  10. pro: IProject,
  11. toProject: (id: number) => any
  12. loginUser: any
  13. deleteProject?: (id: number) => any
  14. collectProjects: IProject[]
  15. currentOrganization: IOrganization
  16. unStar?: (id: number) => any
  17. userList?: (id: number) => any
  18. showEditProjectForm: (type: string, option: any) => any
  19. onClickCollectProjects: (formType: string, project: object, resolve: (id: number) => any) => any
  20. onLoadCollectProjects: () => any
  21. }
  22. interface IPropsState {
  23. currentCollectProjectIds: any[],
  24. isDisableCollect: boolean
  25. }
  26. export class ProjectItem extends React.PureComponent<IProjectItemProps, IPropsState> {
  27. constructor (props) {
  28. super(props)
  29. this.state = {
  30. currentCollectProjectIds: [],
  31. isDisableCollect: false
  32. }
  33. }
  34. public componentWillReceiveProps (nextProps) {
  35. const { collectProjects } = nextProps
  36. this.setState({
  37. currentCollectProjectIds: collectProjects
  38. ? collectProjects.map((cp) => cp.id)
  39. : []
  40. })
  41. }
  42. private stopPPG = (e) => {
  43. e.stopPropagation()
  44. }
  45. private showProjectForm = (formType, option) => (e) => {
  46. this.stopPPG(e)
  47. this.props.showEditProjectForm(formType, option)
  48. }
  49. private collectProjectItem = (formType, option) => (e) => {
  50. const { onClickCollectProjects, collectProjects } = this.props
  51. this.stopPPG(e)
  52. const { currentCollectProjectIds } = this.state
  53. onClickCollectProjects(formType, option.id, () => {
  54. if (formType === 'collect') {
  55. currentCollectProjectIds.push(option.id)
  56. this.setState({
  57. currentCollectProjectIds,
  58. isDisableCollect: true
  59. })
  60. } else {
  61. this.setState({
  62. currentCollectProjectIds: currentCollectProjectIds.length !== 0
  63. ? currentCollectProjectIds.filter((item) => item !== option.id)
  64. : collectProjects.filter((cp) => cp.id !== option.id),
  65. isDisableCollect: false
  66. })
  67. }
  68. })
  69. }
  70. public render () {
  71. const { pro, loginUser, currentOrganization, collectProjects} = this.props
  72. const { currentCollectProjectIds } = this.state
  73. let currentCollectIds = []
  74. if (currentCollectProjectIds.length) {
  75. currentCollectIds = currentCollectProjectIds
  76. } else if (collectProjects) {
  77. currentCollectIds = collectProjects.map((cp) => cp.id)
  78. }
  79. const tags = (<div className={styles.tag}>{pro.createBy.id === loginUser.id ? <Tag key="small">我创建的</Tag> : ''}</div>)
  80. let CreateButton = void 0
  81. if (currentOrganization) {
  82. CreateButton = ComponentPermission(currentOrganization, '')(Icon)
  83. }
  84. // const bg = require(`assets/images/bg${pro.pic}.png`)
  85. let StarPanel = void 0
  86. if (pro) {
  87. const { isStar, starNum, id} = pro
  88. StarPanel = <Star isStar={isStar} starNum={starNum} proId={id} unStar={this.props.unStar} userList={this.props.userList}/>
  89. }
  90. return (
  91. <div className={styles.projectItemWrap} onClick={this.props.toProject(pro.id)}>
  92. <div
  93. className={styles.avatarWrapper}
  94. style={{backgroundImage: `url(${require(`assets/images/bg${pro.pic}.png`)})`}}
  95. />
  96. <div className={styles.detailWrapper}>
  97. <div className={styles.titleWrapper} style={{ flex: 1 }}>
  98. <div className={styles.title}>{pro.name}</div>
  99. <div className={styles.desc}>{pro.description}</div>
  100. </div>
  101. {tags}
  102. <div className={styles.others}>
  103. {StarPanel}
  104. {
  105. (loginUser.id === pro.createBy.id)
  106. ? ''
  107. : (
  108. <div className={styles.delete}>
  109. {
  110. currentCollectIds.indexOf(pro.id) < 0
  111. ? (
  112. <Tooltip title="收藏">
  113. <i
  114. className="iconfont icon-heart1"
  115. onClick={this.collectProjectItem('collect', pro)}
  116. />
  117. </Tooltip>
  118. )
  119. : (
  120. <Tooltip title="取消收藏">
  121. <i
  122. className="iconfont icon-heart"
  123. onClick={this.collectProjectItem('unCollect', pro)}
  124. />
  125. </Tooltip>
  126. )
  127. }
  128. </div>
  129. )
  130. }
  131. <div className={styles.delete}>
  132. <Tooltip title="设置">
  133. <CreateButton type="setting" onClick={this.showProjectForm('edit', pro)} />
  134. </Tooltip>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. )
  140. }
  141. }
  142. export default ProjectItem