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

const { Option } = Select;

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


  const getWxDictList = e => {
    request({ ...apis.wxDict.list, 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(wxDict => (
            <Option key={wxDict.sceneType} value={wxDict.sceneType}>{wxDict.sceneAlias}</Option>
          ))}
      </Select>
  )
}
export default WxDictSelect
