import React, { useState } from "react"; import { SearchOutlined, DeleteOutlined } from "@ant-design/icons"; import { Button, Input } from "antd"; import { Avatar } from "antd-mobile"; import style from "./index.module.scss"; import { FriendSelectionProps } from "./data"; import SelectionPopup from "./selectionPopup"; export default function FriendSelection({ selectedOptions = [], onSelect, deviceIds = [], enableDeviceFilter = true, placeholder = "选择微信好友", className = "", visible, onVisibleChange, selectedListMaxHeight = 300, showInput = true, showSelectedList = true, readonly = false, onConfirm, }: FriendSelectionProps) { const [popupVisible, setPopupVisible] = useState(false); // 内部弹窗交给 selectionPopup 处理 // 受控弹窗逻辑 const realVisible = visible !== undefined ? visible : popupVisible; const setRealVisible = (v: boolean) => { if (onVisibleChange) onVisibleChange(v); if (visible === undefined) setPopupVisible(v); }; // 打开弹窗 const openPopup = () => { if (readonly) return; setRealVisible(true); }; // 获取显示文本 const getDisplayText = () => { if (!selectedOptions || selectedOptions.length === 0) return ""; return `已选择 ${selectedOptions.length} 个好友`; }; // 删除已选好友 const handleRemoveFriend = (id: number) => { if (readonly) return; onSelect((selectedOptions || []).filter(v => v.id !== id)); }; // 弹窗确认回调 const handleConfirm = ( selectedIds: number[], selectedItems: typeof selectedOptions, ) => { onSelect(selectedItems); if (onConfirm) onConfirm(selectedIds, selectedItems); setRealVisible(false); }; return ( <> {/* 输入框 */} {showInput && (