import React, { } from 'react'
import Taro from '@tarojs/taro'
import toolclass from '@/utils/toolclass.js'
import '@/assets/css/reset.less'
import '@/assets/css/iconfont.less'
import './index.less'

export default function ActivityListItem (props) {

  const { Data } = props

  const BtnStatus = () => { // 按钮状态
    let StartTime = new Date(Data.enlistStart).getTime()
    let EndTime = new Date(Data.enlistEnd).getTime()
    let StopTime = new Date(Data.endDate).getTime()
    let Now = Date.now()
    if (StartTime > Now) {
      return `未开始`
    }
    if (StartTime <= Now && EndTime > Now) {
      return !!Data.isSign ? `已报名` : `去报名`
    }
    if (EndTime <= Now && StopTime > Now) {
      return `进行中`
    }
    if (StopTime <= Now) {
      return `已结束`
    }
    return ``
  }

  return (
    <view className='ActivityListItem' onClick={() => { Taro.navigateTo({ url: `/pages/HuoDong/HuoDongDetail/index?id=${Data.dynamicId}` }) }}>
      <view className='Img'>
        <image mode='aspectFill' src={Data.imgUrl} className='centerLabel'></image>
      </view>
      <view className='Info flex-h'>
        <view className='flex-item'>
          <text>{Data.title}</text>
          <text>参与截止时间：{toolclass.FormatDate(Data.enlistEnd)}</text>
        </view>
        <text className={BtnStatus() === '未开始' || BtnStatus() === '去报名' ? 'active' : ''}>{BtnStatus()}</text>
      </view>
    </view >
  )
}
