import React, { useState, useEffect } from 'react';
import { Select } from 'antd';

import request from '../../utils/request'

const { Option } = Select;

/**
 *
 *
 * @param {*} props
 * @returns
 */
const BuildingSelect = (props) => {
  const [ data, setData ] = useState([])
  const [ value, setValue ] = useState(props.value)

  useEffect(() => {
    getCityList();
  },[])

  const getCityList = (e) => {
    request({
        url: '/api/admin/buildinglist/select',
        method: 'GET',
        params: {pageNum: 1,pageSize: 999},
    }).then((data) => {
        setData(data.records)
    })
  }

  const handleChange = (e) => {
    setValue(e)
    props.onChange(e)
  }

  return (
      <Select value={value} style={{ width: '180px' }} placeholder="请选择项目" onChange={handleChange}>
          {data.map(building => (
            <Option key={building.buildingId}>{building.buildingName}</Option>
          ))}
      </Select>
  )
}
export default BuildingSelect

