2019-02-16 08:41:03 +08:00

61 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { use } from '../utils';
import { emit, inherit } from '../utils/functional';
import Icon from '../icon';
import Cell from '../cell';
import Radio from '../radio';
const [sfc, bem] = use('address-item');
function AddressItem(h, props, slots, ctx) {
const { disabled, switchable } = props;
const renderRightIcon = () => (
<Icon
name="edit"
class={bem('edit')}
onClick={event => {
event.stopPropagation();
emit(ctx, 'edit');
}}
/>
);
const renderContent = () => {
const { data } = props;
const Info = [
<div class={bem('name')}>{`${data.name}${data.tel}`}</div>,
<div class={bem('address')}>{data.address}</div>
];
return props.disabled ? Info : <Radio name={data.id}>{Info}</Radio>;
};
const onSelect = () => {
if (props.switchable) {
emit(ctx, 'select');
}
};
return (
<Cell
class={bem({ disabled, unswitchable: !switchable })}
valueClass={bem('value')}
isLink={!disabled && switchable}
scopedSlots={{
default: renderContent,
'right-icon': renderRightIcon
}}
onClick={onSelect}
{...inherit(ctx)}
/>
);
}
AddressItem.props = {
data: Object,
disabled: Boolean,
switchable: Boolean
};
export default sfc(AddressItem);