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