[improvement] AddressList: functional (#2757)

This commit is contained in:
neverland
2019-02-16 08:41:03 +08:00
committed by GitHub
parent 880f574b9a
commit 9aee819c29
2 changed files with 106 additions and 96 deletions

View File

@@ -1,58 +1,60 @@
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');
export default sfc({
props: {
data: Object,
disabled: Boolean,
switchable: Boolean
},
function AddressItem(h, props, slots, ctx) {
const { disabled, switchable } = props;
methods: {
onSelect() {
if (this.switchable) {
this.$emit('select');
}
},
const renderRightIcon = () => (
<Icon
name="edit"
class={bem('edit')}
onClick={event => {
event.stopPropagation();
emit(ctx, 'edit');
}}
/>
);
onClickRightIcon(event) {
event.stopPropagation();
this.$emit('edit');
},
const renderContent = () => {
const { data } = props;
const Info = [
<div class={bem('name')}>{`${data.name}${data.tel}`}</div>,
<div class={bem('address')}>{data.address}</div>
];
renderRightIcon() {
return <Icon name="edit" class={bem('edit')} onClick={this.onClickRightIcon} />;
},
return props.disabled ? Info : <Radio name={data.id}>{Info}</Radio>;
};
renderContent() {
const { data } = this;
const Info = [
<div class={bem('name')}>{`${data.name}${data.tel}`}</div>,
<div class={bem('address')}>{data.address}</div>
];
return this.disabled ? Info : <Radio name={data.id}>{Info}</Radio>;
const onSelect = () => {
if (props.switchable) {
emit(ctx, 'select');
}
},
};
render(h) {
const { disabled, switchable } = this;
return (
<Cell
class={bem({ disabled, unswitchable: !switchable })}
valueClass={bem('value')}
isLink={!disabled && switchable}
scopedSlots={{
default: renderContent,
'right-icon': renderRightIcon
}}
onClick={onSelect}
{...inherit(ctx)}
/>
);
}
return (
<Cell
class={bem({ disabled, unswitchable: !switchable })}
valueClass={bem('value')}
isLink={!disabled && switchable}
scopedSlots={{
default: this.renderContent,
'right-icon': this.renderRightIcon
}}
onClick={this.onSelect}
/>
);
}
});
AddressItem.props = {
data: Object,
disabled: Boolean,
switchable: Boolean
};
export default sfc(AddressItem);