import { View, Image, Text, Block } from "@tarojs/components";
import { transferImage } from '@/utils/tools'
import dayjs from 'dayjs'
import copyImg from '../../assets/copy.png'
import closeImg from '../../assets/close.png'

import './index.scss'

export default function RaiseCard(props) {
  let {
    buildingName,
    termName,
    blockName,
    unitName,
    roomName,
    price,
    houseLockingStatus,
    apartmentName,
    mineLocked,
    createDate,
    buildingArea,
    insideArea,
    payStatus,
    houseId,
    taHousingResourcesList = [],
    apartmentImgList = [],
    taRaise = {},
    buildingImgList = [],
  } = props.summary || {}

  if (!taRaise) {
    taRaise = {}
  }

  const defHouse = taHousingResourcesList[0] || {}
  const title = `${buildingName || defHouse.buildingName || ''} ${termName || defHouse.termName || ''} ${blockName || defHouse.blockName || ''} ${unitName || defHouse.unitName || ''} ${roomName || defHouse.roomName || '　'}`
  const thumb = (buildingImgList || []).length
  const thumb2 = (apartmentImgList || []).length
  const showDT = dayjs(createDate).format('YYYY/MM/DD')
  const wanY = Number(price)


  const copyData = (e) => {
    e.stopPropagation()
    Taro.setClipboardData({
      data: `${houseId}`,
      onSuccess: (() => { }),
    })
  }

  const handleCancel = () => {
    if (props.onCancel) {
      props.onCancel(props.summary)
    }
  }
  return (
    <View className="housecard" style={props.style} >
      <View className="head" onClick={() => (props.handleCard && props.handleCard())}>
        {thumb && <Image className="thumb" src={transferImage((buildingImgList)[0].url)} mode="aspectFit" />
        }
        {!thumb && !thumb2 &&
          <Text style="font-size:26rpx;color:#666">暂无户型图</Text>
        }
        {thumb2 && <Image className="thumb" src={transferImage((apartmentImgList)[0].url)} mode="aspectFit" />
        }
      </View>
      <View className="body">
        {props.type == 'raiseMoney' && !props.disableCancel && <Image src={closeImg} onClick={handleCancel} className="close-img"></Image>}
        <View onClick={() => (props.handleCard && props.handleCard())}>
          {!props.type && <View className={payStatus == 'paid' ? 'raised badge' : payStatus == 'unpaid' ? 'unraise badge' : 'badge'}>{payStatus == 'paid' ? '已缴费' : payStatus == 'unpaid' ? '未缴费' : '已退费'}</View>}
          {(props.type == 'raiseProfile' || props.type == 'houseResource') && <View style="color:#FF3C3C" className='badge'>{mineLocked ? '已锁给我' : '　'}</View>}
          {(props.type == 'raiseProfile' || props.type == 'raiseMoney') && <View style={props.type == 'raiseMoney' ? 'color:#BB9C79;font-size:30rpx' : 'color:#BB9C79;font-size:30rpx;margin-top:-20rpx'}>{apartmentName || ''}</View>}
          {props.type == 'raiseMoney' && taRaise.displayHousePrice && <View className="red-price">现价{Number(price) + 0}万</View>}
          {props.type == 'houseResource' && <View style="color:#BB9C79;font-size:28rpx;margin:-40rpx 0 12rpx 0">{houseLockingStatus == 'locked' ? '已锁定' : '未锁定'}</View>}
          <View className="title">{title}</View>
          {!props.type && <View className="meta">{showDT}</View>}
          {props.type == 'raiseProfile' && taRaise.displayHousePrice && <View className="price">现价<Text className="red">{Number(price) + 0}</Text>万</View>}
          {(props.type == 'raiseProfile' || props.type == 'raiseMoney') &&
            <Block>
              {buildingArea ? <View className="area">建筑面积约 <Text className="red">{buildingArea}m²</Text>
              </View> : <View className="area">建筑面积待定
            </View>}
            </Block>
          }
          {(props.type == 'raiseProfile' || props.type == 'raiseMoney') &&
            <Block>
              {insideArea ? <View className="area">使用面积约 <Text className="red">{insideArea}m²</Text>
              </View> : <View className="area">使用面积待定
            </View>}
            </Block>
          }
        </View>
        {props.type == 'houseResource' && <View className="house-code" style="margin-top:14rpx">房源编号：{houseId}
          <Image src={copyImg} className="copy-img" onClick={copyData}></Image>
        </View>}
      </View>

    </View>
  )
}
