import { Tiplist, TiplistProps } from "@etsoo/materialui"; import { PersonListDto } from "../../dto/person/PersonListDto"; import { PersonListRQ } from "../../rq/person/PersonListRQ"; import { useRequiredCrmApp } from "../../CrmApp"; import { PersonUtils } from "../../utils/Person"; /** * Person list properties * 人员提示列表属性 */ export type PersonListProps = Omit< TiplistProps, "loadData" | "label" | "name" > & { /** * Label */ label?: string; /** * Name */ name?: string; /** * Default request data */ rq?: Partial; /** * Load data handler * @param rq Request data */ onLoadData?: (rq: PersonListRQ) => PersonListRQ; }; /** * Person list * 人员提示列表 * @param props Properties * @returns Component */ export function PersonList(props: PersonListProps) { // CRM app const crm = useRequiredCrmApp(); // Destruct const { fullWidth = true, label = crm.app.get("user")!, maxItems = 10, rq = {}, getOptionLabel = rq.identityType ? PersonUtils.getSimpleListLabel() : PersonUtils.getListLabel(crm), onLoadData = (rq) => rq, name = "personId", ...rest } = props; // Layout return ( label={label} getOptionLabel={getOptionLabel} name={name} fullWidth={fullWidth} maxItems={maxItems} loadData={(keyword, id, maxItems) => crm.personApi.list( onLoadData({ enabled: true, ...rq, keyword, id, queryPaging: { batchSize: maxItems } }), { showLoading: false, defaultValue: [] } ) } {...rest} /> ); }