import { createNamespace } from '../utils'; import { emit, inherit } from '../utils/functional'; import Icon from '../icon'; import Cell from '../cell'; import Radio from '../radio'; import Tag from '../tag'; // Types import { CreateElement, RenderContext } from 'vue/types'; import { DefaultSlots } from '../utils/types'; export type AddressItemData = { id: string | number; tel: string | number; name: string; address: string; isDefault: boolean; }; export type AddressItemProps = { data: AddressItemData; disabled?: boolean; switchable?: boolean; defaultTagText?: string; }; export type AddressItemEvents = { onEdit(): void; onClick(): void; onSelect(): void; }; const [createComponent, bem] = createNamespace('address-item'); function AddressItem( h: CreateElement, props: AddressItemProps, slots: DefaultSlots, ctx: RenderContext ) { const { disabled, switchable } = props; function onClick() { if (switchable) { emit(ctx, 'select'); } emit(ctx, 'click'); } const genRightIcon = () => ( { event.stopPropagation(); emit(ctx, 'edit'); emit(ctx, 'click'); }} /> ); function genTag() { if (props.data.isDefault && props.defaultTagText) { return ( {props.defaultTagText} ); } } function genContent() { const { data } = props; const Info = [
{`${data.name} ${data.tel}`} {genTag()}
,
{data.address}
, ]; if (switchable && !disabled) { return ( {Info} ); } return Info; } return ( ); } AddressItem.props = { data: Object, disabled: Boolean, switchable: Boolean, defaultTagText: String, }; export default createComponent( AddressItem );