import React, { useState, useEffect, useMemo } from 'react';
import { Select } from 'antd';
import apis from '../../services/apis';
import request from '../../utils/request'

const { Option } = Select;

/**
 *
 *
 * @param {*} props
 * @returns
 */
const ChannelSelect = props => {
  const [data, setData] = useState([])
  useEffect(() => {
    getChannelSelect({buildingId:props.buildingId});
  }, [props.value,props.buildingId])



  const getChannelSelect = params => {
    request({ ...apis.customer.buildingConsultant, params: { ...params,pageNumber: 1, pageSize: 999 } }).then(data => {
      setData(data.records)
      // 默认选中第一个
    })
  }

  return (
    <Select
      showSearch
      value={props.value}
      style={{ width: '250px' }}
      placeholder="请选择置业顾问"
      onChange={props.onChange}
      filterOption={(input, option) =>
        option.props.children && option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
      }>
      {data.map(Item => (
        <Option key={Item.userId} value={`${Item.userId}`}> {Item.userName} </Option>
      ))}
    </Select>
  )
}
export default ChannelSelect
