import { View, Image, Text } from "@tarojs/components";
import { transferImage } from '@/utils/tools'
import dayjs from 'dayjs'
import emptyImg from '@/assets/empty.png'

import './index.scss'

export default function HouseCard(props) {
  const {
    buildingName,
    termname,
    termName,
    blockName,
    displayHousePrice,
    unitName,
    floorName,
    roomName,
    price,
    housingStatus,
    saleBatchStatus,
    houseId,
    createDate,
    housingInfo = {},
    apartmentImgList = [],
    buildingImgList = [],
  } = props.summary || {}

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

  const toHouseDetail = () => {
    if (props.onClick) {
      props.onClick(props.summary)
      return;
    }

    if (housingStatus == '0' || saleBatchStatus == '0') {
      Taro.showToast({ title: '当前销售批次或该房源已被取消发布', icon: 'none', duration: 2000 })
    } else {
      Taro.navigateTo({
        url: `/onlineSelling/pages/detail/index?id=${houseId}`
      })
    }
  }
  return (
    <View className="housecard">
      <View className="head" onClick={toHouseDetail}>
        {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" onClick={toHouseDetail}>
        <View className="badge">已预选</View>
        <View className="title">{title}</View>
        {displayHousePrice && <View className="subtitle">
          <Text>现价</Text>
          <Text className="red">{wanY + '万元' || '待定'}</Text>
        </View>}

        <View className="meta">{showDT}预选</View>
      </View>


    </View>
  )
}
