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
<template>
<div style="width:auto;display:inline-block !important; display:inline;">
<a-select mode="tags" v-model="selected" style="width: 400px" @change="onChange" showArrow allowClear>
<a-select-opt-group v-for="item in selectArray" :key="item.key">
<span slot="label">
<a-icon type="bars" />{{ item.title }}
</span>
<a-select-option v-for="arr in item.children" :key="arr.key" :value="arr.key">
{{ arr.title }}
</a-select-option>
</a-select-opt-group>
</a-select>
</div>
</template>
<script>
// 用法 <spec-select v-model="formData.projClass" />
export default {
name: "SpecSelect",
data () {
return {
selectArray: [],
selected: [],
loadState: false,
};
},
props: {
value: null,
width: {
type: Number,
default () {
return 180
}
}
},
created () {
this.load(this.value)
},
methods: {
load (value) {
if (this.selectArray.length > 0) {
this.selected = value
} else {
this.$api.parameter.getArrayListByType({ typeId: 56 }).then(({ data = {} }) => {
if (data) {
this.selectArray = data
this.selected = value
}
}).catch(() => { })
}
},
onChange () {
if (this.selected.length > 3) {
this.$message.error('最多只能选三个专业')
this.selected = this.selected.splice(0, 3)
}
this.$emit("input", this.selected);
this.$emit("change");
},
},
watch: {
value: {
handler (value) {
if (!this.loadState) {
this.load(value)
this.loadState = true
}
}
},
},
};
</script>