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
<template>
<div>
<a-select placeholder="输入学科代码名称" :default-active-first-option="false" showSearch
:show-arrow="false" :filter-option="false" @search="onSearch" @change="handleChange" :style="{width: width + 'px'}">
<a-select-option v-for="item in selectArray" :key="item.key" :value="item.key">
{{ item.title }}
</a-select-option>
</a-select>
</div>
</template>
<!-- :filterOption="filterOption" -->
<script>
export default {
name: "knowledgeSelect",
props: {
value: {
type: undefined,
default () {
return null
}
},
width: {
type: Number,
default() {
return 180;
},
},
},
data() {
return {
selectArray: [],
selected: null,
defaultValue: {
title: "--请选择" + this.title + "--",
key: "",
description: "",
selected: true,
disabled: true,
}
};
},
created() {
//this.loadValue()
},
methods: {
onSearch(value) {
if (value == '') {
return
}
let pars = { SystemCodeOrName: value }
this.$api.parameter.getParameterListBySystemCode(pars).then(({ data = {} }) => {
this.selectArray = []
// 模拟从数据库查询数据
if (data && data.length > 0) {
this.selectArray = data
}
// else {
// this.selectArray.push({ title: value, key: "00000000-0000-0000-0000-000000000000" })
// }
})
},
// filterOption(input, option) {
// // 自定义过滤逻辑,如果没有匹配的选项就保留输入值
// return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
// },
handleChange(value) {
this.$emit("input", value);
var newArr = this.selectArray.filter(x => x.key == value);
if (value && !!newArr && newArr.length > 0) {
var text = !!value ? newArr[0].title : ''
this.$emit('changeTitle', text)
}
this.$emit("change");
},
loadValue () {
if (this.isAll) {
this.selectArray.unshift(this.defaultValue)
}
if (!!!this.selected) {
if (!!this.value) {
this.selected = this.value + ''
} else {
if (this.selectArray.length > 0)
this.selected = this.selectArray[0].key
else
this.selected = ''
}
}
this.$emit("input", this.selected)
}
},
watch: {
value: {
handler (value) {
if (!!!value) {
this.selected = null
}
else
this.selected = value + ''
this.$emit("input", this.selected)
},
},
}
};
</script>