import * as React from 'react'; import { Props, State } from './type'; import * as Styled from './index.style'; import {get, post} from '../utils/request'; import {rem} from '../style/function.style'; import {showMessage} from '../common/toast/toast'; import { getBountyData4Show } from '../utils/bountyFormat' import { redirectToLogin } from '../utils/login' import { LofterTitle } from '../lofterTitle' import { genSpmLink } from '../utils/statistics' import throttle from '../utils/throttle'; const textMap = { 'has-own':'已领取', 'empty-stock':'已抢完 ' } export class LofterBounty extends React.Component { static defaultProps = new Props(); state = new State(); componentDidMount(){ console.log(this.props.bounties); this.props.bounties && this.props.bounties.forEach(item=>{ return this.state.btnStatusMap.set(item.id,'') }) } private render1Column(bounty, index,styleColor,fontColor) { const bountyshow = getBountyData4Show(bounty) let statusType = this.state.btnStatusMap.get(bountyshow.id) const text = statusType ? textMap[statusType] : `领 取` return ( {}} styleColor={styleColor} fontColor={fontColor} >
¥{bountyshow.preferential}

津贴{bountyshow.name}

有效期:{bountyshow.startTime}至{bountyshow.endTime}
{bountyshow.description}
{text}
{bountyshow.doorsill}
) } private render2Column(bounty, index,styleColor,fontColor) { const bountyshow = getBountyData4Show(bounty) let statusType = this.state.btnStatusMap.get(bountyshow.id) const text = statusType ? textMap[statusType] : `领取` return (
¥{bountyshow.preferential}
{bountyshow.doorsill}
{bountyshow.name}
{text}
) } private render3Column(bounty, index,styleColor,fontColor) { const bountyshow = getBountyData4Show(bounty) let statusType = this.state.btnStatusMap.get(bountyshow.id) const text = statusType ? textMap[statusType] : `领取` return (
¥{bountyshow.preferential}
{bountyshow.doorsill}
{bountyshow.name}
{text}
) } private setBtnStatus(bountyId,status){ this.setState((preState)=>{ preState.btnStatusMap.set(bountyId,status) return { btnStatusMap:preState.btnStatusMap } }) } private getBounty(bountyId, e){ if(!!this.state.btnStatusMap.get(bountyId)){ return } e.stopPropagation(); console.log(bountyId); const params = { bountyId: bountyId } get('//www.lofter.com/market/bounty/fetch.json', params).then(resp => { if (resp.code === 401) { redirectToLogin() } else if (resp.code === 200) { this.setBtnStatus(bountyId,'has-own') showMessage({text:'领取成功~o(*≧▽≦)o'}); } else { if(resp.code === -506){ // 领完 this.setBtnStatus(bountyId,'empty-stock') } showMessage({text:`${resp.msg}~(°ー°〃)`}) } }).catch(error => { showMessage({text:'出了点小错,请重试~(°ー°〃) '}) }) } private getBountyThrottle = throttle(this.getBounty,1000) public render() { // console.log('render', this.props, this.state); const {style,title,styleColor,fontColor,bounties=[], type, isEdit, marginTop} = this.props; return ( 0 && 'f-before'}> { title && } {}} onClick={() => {}} > {bounties.map((bounty, index) => ( this[`render${type}Column`](bounty, index,styleColor,fontColor) ))} { (!bounties || bounties && bounties.length == 0 )&& isEdit &&
lofter津贴模块
}
) } }