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

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

const { Option } = Select;

/**
 *
 *
 * @param {*} props
 * @returns
 */
const CitySelect = (props) => {
  const [ data, setData ] = useState([])

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

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

  return (
      <Select showSearch value={props.value} style={{ width: '180px' }} placeholder="请选择城市" onChange={props.onChange}>
          {data.map(city => (
            <Option key={city.id} value={city.id}>{city.name}</Option>
          ))}
      </Select>
  )
}
export default CitySelect

