search-dict.vue
1.24 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
<template>
<Page name="search">
<template #content>
<template v-for="(item, index) in list">
<zui-cell :key="index" @click="onSelect(item, index)">
<template #title>{{ item.valueName }}</template>
</zui-cell>
</template>
</template>
</Page>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
data() {
return {
list: [],
excludes: [],
title: '字典',
dict: '',
};
},
onLoad(option) {
if (option.title) this.title = option.title;
if (option.dict) this.dict = option.dict;
if (option.excludes) this.excludes = option.excludes.split(',');
uni.setNavigationBarTitle({ title: option.title });
this.initData();
},
computed: {
...mapGetters(['dictList']),
},
methods: {
initData() {
const matchDictList = this.dictList(this.dict) || [];
this.list = matchDictList.filter(i => i.valueCode && i.valueName && !this.excludes.includes(i.valueCode));
// this.list = [{ valueCode: '', valueName: '不限' }, ...need];
},
onSelect(item) {
uni.$emit('select-dict', item.valueName == '不限' && !item.valueCode ? { valueCode: '', valueName: '' } : item);
uni.navigateBack();
},
},
};
</script>