import * as React from 'react' import { createPortal } from 'react-dom' import { Image } from '../image' import { addInvite } from '../actions' import { lock, unlock } from '../../utils/body-scroll-lock' import { ColDetail } from '../type' import { Container, PanelContainer, PanelContentContainer, Header, HeaderHandle, Title, ListContainer, ListItem, FixedButton } from './index.style' interface Props { show: boolean; close: () => any; data?: OwnColDetail[]; refresh?: () => void; activityId: string; } export interface OwnColDetail extends ColDetail { // 展示状态,1:正常,2:已发布,3:已满员 showStatus: 1 | 2 | 3; } export interface State { panelShow: boolean; canSubmit: boolean; checkedColItem: number | undefined; aniType: 'unfold' | 'fold' | '' } export class CollectionPanel extends React.Component { state: State = { canSubmit: false, checkedColItem: undefined, aniType: '', panelShow: false } modalContent: HTMLElement; componentDidUpdate(preProps: any) { if (preProps.show !== this.props.show && this.props.show) { lock(this.modalContent) this.setState({ panelShow: true }) setTimeout(() => { this.setState({ aniType: 'unfold' }) }, 0) } else if (preProps.show !== this.props.show && !this.props.show) { unlock() this.setState({ canSubmit: false, checkedColItem: undefined, }) this.setState({ aniType: 'fold' }) setTimeout(() => { this.setState({ panelShow: false }) }, 300) } } handleClosePanel = (e: React.MouseEvent) => { // @ts-ignore if (e.target.getAttribute('id') === 'collection-panel-con') { this.props.close() } } handleItemCheck = (item: OwnColDetail) => { if (item.showStatus !== 1) return this.setState({ checkedColItem: item.id, canSubmit: true }) } goToGuide = () => { window.location.href = '//www.lofter.com/front/customer-service/#/question-answer/1000520' } submit = async () => { if (!this.state.canSubmit) return await addInvite( this.state.checkedColItem, this.props.activityId ) this.props.refresh?.() this.props.close() } render() { const { data } = this.props const { aniType, canSubmit, checkedColItem, panelShow } = this.state return ( createPortal((
选择合集 <div className="link" onClick={this.goToGuide} > <Image src="https://lofter.lf127.net/1637129266373/common_icon_notice_light.png" width={32} height={32} className="icon" /> 共创合集 </div> this.modalContent = ref} > { data?.map(item => (
{item.name}
{ item.showStatus === 2 || item.showStatus === 3 ? ( { item.showStatus === 2 && '已发布' } { item.showStatus === 3 && '已满员' } ) : item.collectionType === 1 && ( 共创 ) }
)) }
确定
), document.getElementById('app')!) ) } }