import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.scss'
import RaiseCard from '../../components/RaiseCard'
import { queryRaiseDetail } from '@/services/project'

export default class HouseResource extends Component {
  config = {
    navigationBarTitleText: '房源清单'
  }
  state = {
    houseList: [],
  }

  componentWillMount() {
    const { raiseRecordId } = this.$router.params
    queryRaiseDetail(raiseRecordId).then(res => {
      this.setState({
        houseList: res.houseList || [],

      })
    })
  }
  toHouseDetail(item) {
    if (item.housingStatus == '0' || item.saleBatchStatus == '0') {
      Taro.showToast({ title: '当前销售批次或该房源已被取消发布', icon: 'none', duration: 2000 })
    } else {
      Taro.navigateTo({
        url: `/onlineSelling/pages/detail/index?id=${item.houseId}`
      })
    }
  }
  render() {
    const { houseList } = this.state
    return (
      <View style="padding-top:30rpx">
        {
          houseList.map(item => (
            <View key={item.raiseRecordId} >
              <RaiseCard type="houseResource" handleCard={() => this.toHouseDetail(item)} summary={item} />
            </View>
          )
          )
        }
      </View>
    )
  }

}
