import { PropType, defineComponent } from 'vue'; // Utils import { createNamespace, UnknownProp } from '../utils'; // Components import { Tag } from '../tag'; import { Icon } from '../icon'; import { Cell } from '../cell'; import { Radio } from '../radio'; import { Button } from '../button'; import { RadioGroup } from '../radio-group'; const [name, bem, t] = createNamespace('contact-list'); export type ContactListItem = { id?: number | string; tel: number | string; name: string; isDefault?: boolean; }; export default defineComponent({ name, props: { list: Array as PropType, addText: String, modelValue: UnknownProp, defaultTagText: String, }, emits: ['add', 'edit', 'select', 'update:modelValue'], setup(props, { emit }) { const renderItem = (item: ContactListItem, index: number) => { const onClick = () => { emit('update:modelValue', item.id); emit('select', item, index); }; const renderRightIcon = () => ( ); const renderEditIcon = () => ( { event.stopPropagation(); emit('edit', item, index); }} /> ); const renderContent = () => { const nodes: JSX.Element[] = [`${item.name},${item.tel}`]; if (item.isDefault && props.defaultTagText) { nodes.push( {props.defaultTagText} ); } return nodes; }; return ( ); }; return () => (
{props.list && props.list.map(renderItem)}
); }, });