import { useModel } from '@umijs/max';
import { Select } from 'antd';
import { useEffect } from 'react';

const { Option } = Select;

function InnerContactField(props) {
  const { value, onChange } = props;
  const { userList, run, loading } = useModel('userList');
  useEffect(() => {
    run();
  }, []);
  return (
    <Select
      showSearch
      onChange={(value) => {
        onChange(String(value));
        // onChange(JSON.stringify([value]));
      }}
      loading={loading}
      filterOption={(input, option) =>
        option.children.toLowerCase().includes(input.toLowerCase())
      }
    >
      {(userList || []).map((item) => (
        <Option key={item.ID} value={item.ID}>
          {item.CName}
        </Option>
      ))}
    </Select>
  );
}

export default InnerContactField;
