import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import ConsultantItem from '../../components/ConsultantItem/index'
import './index.scss'

import { connect } from '@tarojs/redux'
import * as houseActions from '@/actions/house'
import Blank from '../../components/Blank'

@connect(({ house }) => ({ house }), { ...houseActions })
export default class ConsultantList extends Component {
  config = {
    navigationBarTitleText: '选择置业顾问'
  }

  componentDidMount() {
    const { buildingId } = this.$router.params
    const { house } = this.props

    // if (!house.consultantList || !house.consultantList.length) {
    this.props.dispatchGetConsultants({
      buildingId,
      pageSize: 999,
      pageNumber: 1,
    })
    // }
  }

  handleItemClick = (consultant) => {
    console.log('----------------->', consultant)
    this.props.dispatchChooseConsultant(consultant)

    Taro.navigateBack({ delta: 1 })
  }
  toConsultantDetail(item) {
    Taro.navigateTo({
      url: `/pages/card/index?id=${item.id}`
    })
  }
  render() {
    const { house } = this.props

    return (
      <View className="consultantList">
        {
          (!house.consultantList || !house.consultantList.length) &&
          (<Blank tips="暂无数据" />)
        }

        {
          house.consultantList.map((item, index) => (
            <ConsultantItem
              data={item}
              key={index + 'card'}
              onClick={this.handleItemClick}
              onHomepage={() => this.toConsultantDetail(item)}
            >
            </ConsultantItem>
          ))
        }
      </View>
    )
  }

}
