select-contact.vue
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<template>
<Page name="select-contact">
<template #header>
<u-search v-model="query" placeholder="请输入搜索关键词" :show-action="false" @change="onSearch" />
</template>
<template #content>
<template v-if="list.length > 0">
<template v-for="(item, index) in list">
<u-cell :key="index" :title="item.name || ' '" :value="item.mobile" is-link @click="onSelect(item)">
<template #icon>
<view class="contact-avatar">{{ item.name | firstLetter }}</view>
</template>
</u-cell>
</template>
</template>
<template v-else>
<u-empty text="暂无数据" />
</template>
</template>
</Page>
</template>
<script>
import debounce from '@/utils/debounce';
export default {
data() {
return {
query: '',
list: [],
};
},
filters: {
firstLetter(value) {
return `${value || ''}`.substring(0, 1);
},
},
onLoad() {
this.loadData();
},
methods: {
onSearch(query) {
debounce(() => this.loadData(query), 500);
},
loadData(query) {
uni.$u.api.contact.select({ query }).then(response => {
this.list = response.result || [];
});
},
onSelect(item) {
uni.$emit('select-contact', item);
uni.navigateBack();
},
},
}
</script>
<style lang="scss">
.page-select-contact {
box-sizing: border-box;
box-sizing: border-box;
&__content {
.u-cell {
background-color: $color-white;
&__title {
color: $color-text;
}
&__value {
color: $color-text-minor;
font-size: $font-md;
}
}
.contact-avatar {
background-color: rgba($color-primary, 0.8);
color: $color-white;
height: $padding-lg * 1.5;
min-width: $padding-lg * 1.5;
width: $padding-lg * 1.5;
border-radius: 50%;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
margin-right: $padding-md;
}
}
}
</style>