import { Popup, SafeArea, SearchBar } from "@nutui/nutui-react-taro"; import { Icon } from "@/components"; import { ScrollView, View } from "@tarojs/components"; import React, { useEffect, useState } from "react"; import { business } from "@/services"; import { SupplierVO } from "@/types/typings"; interface ISupplierPickerProps { trigger?: React.ReactNode; onFinish: (supplierVO: SupplierVO) => void; } export default function SupplierPicker(props: ISupplierPickerProps) { const { onFinish, trigger } = props; const [supplierVO, setSupplierVO] = useState(); const [visible, setVisible] = useState(false); const [supplierList, setSupplierList] = useState(); const [searchText, setSearchText] = useState(""); useEffect(() => { if (visible) { handleSearch().then(); } }, [visible]); const handleSearch = async (value?: string) => { const { data } = await business.supplier.listSupplier({ supplierListQry: { name: value || undefined, status: true }, }); let supplierList = data?.data; setSupplierList(supplierList as any); }; return ( { setVisible(true); event.stopPropagation(); }} > {trigger} {/* 选择瓜农 */} { if (visible) { setSupplierVO(undefined) setSearchText(""); setVisible(false); } else if (supplierVO) { onFinish(supplierVO); } }} > setSearchText(value)} onSearch={handleSearch} onClear={() => handleSearch("")} /> {supplierList?.length === 0 && ( 未找到匹配的瓜农 )} {supplierList?.map((item) => ( { setSupplierVO(item); setSearchText("") setVisible(false); }} > {item.name} ))} {/**/} {/* {*/} {/* Taro.navigateTo({*/} {/* url: "/pages/community/choose/index",*/} {/* success: () => {*/} {/* setVisible(false);*/} {/* },*/} {/* });*/} {/* }}*/} {/* >*/} {/* 加入新小区*/} {/* */} {/**/} ); }