import { ComponentClass } from 'react'
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import './index.scss'
import SdFormid from '../sdFormid';
interface DataInterface {
  buildingSiteId: string
  name: string
  process: string
  image: string
  time?: string
  status?: number; // 0 | 1 | 2 |  发布 | 草稿 | 隐藏
  getRedPacket?: number // 领取红包数量
  isHasRedPacket?: number // 是否有红包 0 无 1 有
  redPacket?: number // 红包总数
}
type PageOwnProps = {
  className?: string
  item: DataInterface
  onClick?: any
  editable?: boolean
  onEdit?: any
  onPublic?: any
  onConfig?: any
}

type PageState = {}

type DvaProps = {}

type IProps = PageOwnProps & DvaProps

interface Index {
  props: IProps;
}

class Index extends Component {

  static options = {
    addGlobalClass: true
  }

  navigateTo = () => {
    if (this.props.onClick) {
      this.props.onClick(this.props.item.buildingSiteId)
    }
  }

  handleOnEdit = () => {
    if (this.props.onEdit) {
      this.props.onEdit(this.props.item.buildingSiteId)
    }
  }
  handleOnConfig = () => {
    if (this.props.item.isHasRedPacket === 1) {
      return
    }
    this.props.onConfig(this.props.item.buildingSiteId)
  }
  handleOnPublic = () => {
    this.props.onPublic(this.props.item.buildingSiteId, this.props.item.status)
  }

  render() {
    const { item } = this.props
    return (
      <SdFormid onClick={this.navigateTo} >
        <View className={'sd-building-card ' + (this.props.className || '')} >
          <View className='sd-building-card-body' >
            <View className='sd-building-card-content'>
              <View className='sd-building-card-title sd-ell sd-ell2'>
                {item.name}
              </View>
              <View className='sd-building-card-note'>
                <Text className='sd-building-card-process'>
                  {item.process}
                </Text>
                <Text className='sd-building-card-time'>
                  {item.time}
                </Text>
              </View>
            </View>
            <Image
              mode='aspectFill'
              className='sd-building-card-img'
              src={item.image}
              lazyLoad={true} />
          </View>

        </View>
      </SdFormid>
    )
  }
}

export default Index as ComponentClass<PageOwnProps, PageState>