import {designComponent, PropType} from "@peryl/react-compose"; import {PlcEmitsOptions, PlcPropsOptions} from "../plc/utils/plc.utils"; import {PlcScopeSlotsOptions} from "../plc/utils/plc.scope-slots"; import {usePlc} from "../plc/use/usePlc"; import {iAddressService} from "../../$address/createAddressService"; import {$configuration} from "../../$configuration"; import {Address} from "../../Address"; export const PlcAddressItem = designComponent({ name: 'plc-select-address', props: { ...PlcPropsOptions, province: { type: Boolean, default: false }, // 是否为选择省份 city: { type: Boolean, default: false }, // 是否为选择城市 district: { type: Boolean, default: false }, // 是否为选择区县 parentField: { type: String }, service: { type: Object as PropType }, }, scopeSlots: { ...PlcScopeSlotsOptions, }, emits: PlcEmitsOptions, setup({ props, event, slots, scopeSlots }) { const service = props.service || $configuration.use('address')!; const defaultAsyncFormatter = async (val?: string): Promise => { if (!val) {return null;} try { const [meta] = await service.getAddressByCodes([val]); return meta.label; } catch (e) { console.error(e); return val; } }; return usePlc({ props, event, slots, scopeSlots, proxyPropsConfig: { asyncFormatter: () => defaultAsyncFormatter }, defaultScopeSlots: { edit: ({ row }) => ( !props.field ? null :
) }, }); }, });