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
<template>
<a-cascader v-model="selected" :style="{width:'80%'}" :options="options" :show-search="{ filter }" :display-render="displayRender" expand-trigger="hover" placeholder="请选择学科代码" @change="onChange" />
</template>
<script>
import { specList, getSpecArray } from "@/views/components/common/config"
export default {
name: "cascaderSelect",
data () {
return {
options: specList,
selected: null,
};
},
props: {
value: {
type: String,
default () {
return null
}
},
},
created () {
if (!!this.value) {
this.selected = getSpecArray(this.value)
// this.$emit("change");
// this.$emit("input", this.selected)
}
},
methods: {
onChange (value, selectedOptions) {
this.selected = value
if (!!this.selected && this.selected.length == 3) {
this.$emit("input", this.selected[2])
this.$emit("change");
}
},
displayRender ({ labels }) {
return labels[labels.length - 1];
},
filter (inputValue, path) {
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
},
},
watch: {
value: {
handler (value) {
if (!!value) {
this.selected = getSpecArray(this.value)
if (!!this.selected && this.selected.length == 3) {
this.$emit("input", this.selected[2])
this.$emit("change");
}
}
},
},
}
};
</script>