fix(ContactList): select event triggered twice

This commit is contained in:
chenjiahan 2020-10-06 16:26:31 +08:00
parent 6d483a8da5
commit 1dd4083102

View File

@ -23,28 +23,17 @@ export default createComponent({
emits: ['add', 'edit', 'select', 'update:modelValue'], emits: ['add', 'edit', 'select', 'update:modelValue'],
setup(props, { emit }) { setup(props, { emit }) {
return () => { const renderItem = (item, index) => {
const List = const onClick = () => {
props.list &&
props.list.map((item, index) => {
function onClick() {
emit('update:modelValue', item.id); emit('update:modelValue', item.id);
emit('select', item, index); emit('select', item, index);
} };
function RightIcon() { const renderRightIcon = () => (
return ( <Radio name={item.id} iconSize={16} checkedColor={RED} />
<Radio
name={item.id}
iconSize={16}
checkedColor={RED}
onClick={onClick}
/>
); );
}
function LeftIcon() { const renderLeftIcon = () => (
return (
<Icon <Icon
name="edit" name="edit"
class={bem('edit')} class={bem('edit')}
@ -54,9 +43,8 @@ export default createComponent({
}} }}
/> />
); );
}
function Content() { const renderContent = () => {
const nodes = [`${item.name}${item.tel}`]; const nodes = [`${item.name}${item.tel}`];
if (item.isDefault && props.defaultTagText) { if (item.isDefault && props.defaultTagText) {
@ -68,14 +56,14 @@ export default createComponent({
} }
return nodes; return nodes;
} };
return ( return (
<Cell <Cell
v-slots={{ v-slots={{
icon: LeftIcon, icon: renderLeftIcon,
default: Content, default: renderContent,
'right-icon': RightIcon, 'right-icon': renderRightIcon,
}} }}
key={item.id} key={item.id}
isLink isLink
@ -85,12 +73,12 @@ export default createComponent({
onClick={onClick} onClick={onClick}
/> />
); );
}); };
return ( return () => (
<div class={bem()}> <div class={bem()}>
<RadioGroup modelValue={props.modelValue} class={bem('group')}> <RadioGroup modelValue={props.modelValue} class={bem('group')}>
{List} {props.list && props.list.map(renderItem)}
</RadioGroup> </RadioGroup>
<div class={bem('bottom')}> <div class={bem('bottom')}>
<Button <Button
@ -106,6 +94,5 @@ export default createComponent({
</div> </div>
</div> </div>
); );
};
}, },
}); });