import { PropType, defineComponent } from 'vue'; // Utils import { createNamespace } from '../utils'; // Components import { Tag } from '../tag'; import { Icon } from '../icon'; import { Cell } from '../cell'; import { Radio } from '../radio'; const [name, bem] = createNamespace('address-item'); export type AddressListAddress = { id: number | string; tel: number | string; name: string; address: string; isDefault?: boolean; }; export default defineComponent({ name, props: { disabled: Boolean, switchable: Boolean, defaultTagText: String, address: { type: Object as PropType, required: true, }, }, emits: ['edit', 'click', 'select'], setup(props, { slots, emit }) { const onClick = () => { if (props.switchable) { emit('select'); } emit('click'); }; const renderRightIcon = () => ( { event.stopPropagation(); emit('edit'); emit('click'); }} /> ); const renderTag = () => { if (slots.tag) { return slots.tag(props.address); } if (props.address.isDefault && props.defaultTagText) { return ( {props.defaultTagText} ); } }; const renderContent = () => { const { address, disabled, switchable } = props; const Info = [
{`${address.name} ${address.tel}`} {renderTag()}
,
{address.address}
, ]; if (switchable && !disabled) { return ( {Info} ); } return Info; }; return () => { const { disabled } = props; return (
{slots.bottom?.({ ...props.address, disabled })}
); }; }, });