[improvement] use scoped-slots (#2712)

This commit is contained in:
neverland
2019-02-11 17:52:43 +08:00
committed by GitHub
parent 9f7c91a3b9
commit 9c4ad97731
5 changed files with 159 additions and 122 deletions
+36 -35
View File
@@ -19,41 +19,43 @@ export default sfc({
onSelect(express) {
this.$emit('select-search', express);
this.$emit('input', `${express.address || ''} ${express.name || ''}`.trim());
},
onFinish() {
this.$refs.field.blur();
},
renderFinish() {
const showFinish = this.value && this.focused && android;
if (showFinish) {
return (
<div class={bem('finish')} onClick={this.onFinish}>
{t('complete')}
</div>
);
}
},
renderSearchResult() {
const showSearchList = this.focused && this.searchResult && this.showSearchResult;
if (showSearchList) {
return this.searchResult.map(express => (
<Cell
key={express.name + express.address}
title={express.name}
label={express.address}
icon="location-o"
clickable
onClick={() => {
this.onSelect(express);
}}
/>
));
}
}
},
render(h) {
const { value, focused, searchResult } = this;
const Finish = value && focused && android && (
<div
slot="icon"
class={bem('finish')}
onClick={() => {
this.$refs.field.blur();
}}
>
{t('complete')}
</div>
);
const SearchList =
focused &&
searchResult &&
this.showSearchResult &&
searchResult.map(express => (
<Cell
key={express.name + express.address}
title={express.name}
label={express.address}
icon="location-o"
clickable
onClick={() => {
this.onSelect(express);
}}
/>
));
return (
<Cell class={bem()}>
<Field
@@ -67,11 +69,10 @@ export default sfc({
error={this.error}
label={t('label')}
placeholder={t('placeholder')}
scopedSlots={{ icon: this.renderFinish }}
{...{ on: this.$listeners }}
>
{Finish}
</Field>
{SearchList}
/>
{this.renderSearchResult()}
</Cell>
);
}