index.vue
2.33 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!--
use
<mSelect
v-model="form.reditCode"
placeholder="输入文字检索查询"
style="width: 100%"
clearable
:lists="organizationList"
lists_label="organizationName"
lists_value="entrustOrganizationId"
lists_key="entrustOrganizationId"
:total="orgTotal"
:pageSize="10"
@handleChange="handleChangeredit"
/>
-->
<template>
<el-select
v-bind="_attrs"
style="width: 100%"
remote
:loading="loading"
:remote-method="remoteOrg"
>
<el-option
v-for="(item, index) in mLists"
:key="item[lists_key] || index"
:label="`${item[lists_label]}${lists_vice_label && `(${item[lists_vice_label]})`}`"
:value="item[lists_value]"
>
</el-option>
</el-select>
</template>
<script setup name="mSelect">
import { computed, getCurrentInstance, reactive, toRef, useAttrs, watch, watchEffect } from 'vue'
const {proxy} = getCurrentInstance()
const props = defineProps({
lists: { // 列表数据
type: Array,
default: () => []
},
lists_label: {
type: String,
default: 'label'
},
lists_label: {
type: String,
default: 'label'
},
lists_label_e: {
type: String,
default: 'value'
},
lists_key: {
type: String,
default: 'value'
},
lists_vice_label: {
type: String,
default: ''
},
filterStr: {
type: String,
default: 'filterStr'
}
})
const {lists, lists_label, lists_value, lists_label_e, lists_key, lists_vice_label, filterStr} = props
const $attrs = useAttrs()
const _attrs = computed(() => {
let attrs = {
...$attrs,
onFocus: remoteOrg.bind(null, '')
}
return attrs
})
const data = reactive({
loading: false,
mLists: [],
queryDataStr: ''
})
const { loading, mLists, queryDataStr } = toRef(data)
watch(lists, (val) => {
if (val) {
mLists.value = val
}
})
const emit = defineEmits();
const remoteOrg = (query) => {
console.log('搜索' + query);
loading = true;
if (query != '') {
queryDataStr = query ;
} else {
queryDataStr = '' ;
return
}
const selector = lists.find(item => {
return (
item[lists_label].toLowerCase().indexOf(filterStr.toLowerCase()) > -1 ||
item[lists_label_e].toLowerCase().indexOf(filterStr.toLowerCase()) > -1
)
})
emit('handleChange', {
...selector
})
loading = false;
}
</script>
<style>
</style>