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
124
125
126
127
128
129
130
131
132
133
134
<template>
<div style=" width:auto; display:inline-block !important; display:inline;z-index:100">
<a-select :style="{width: width + 'px'}" v-model="parSelected" @change="parentChange($event)" :key="0">
<a-select-option v-for="item in parArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
<a-select :style="{width: width + 'px'}" v-model="selected" @change="childChange($event)" :key="1">
<a-select-option v-for="item in chArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
</div>
</template>
<script>
export default {
//用法 <para-multi-select v-model="formData.projClass" :typeId="52" />
name: "paraMultiSelect",
data () {
return {
parArray: [],
chArray: [],
parSelected: '',
selected: '',
defaultAll: {
title: "--请选择" + this.title + "--",
key: "",
children: [{
title: "--请先选择上级-",
key: "",
}]
},
loading: false
};
},
props: {
value: {
type: String,
default () {
return null
}
},
typeId: {
type: Number,
default () {
return 0
}
},
width: {
type: Number,
default () {
return 180
}
},
title: {
type: String,
default () {
return ''
}
},
},
created () {
this.load(this.value)
},
methods: {
async load (value) {
if (!!!this.parArray || this.parArray.length == 0) {
this.parArray = await this.$store.dispatch('cache/getDictByType', 6)
this.parArray.unshift(this.defaultAll)
this.chArray = this.parArray[0].children
this.parSelected = ''
this.selected = ''
}
if (!!value) {
var show = this.getParIndex(this.parArray, value)
this.chArray = this.parArray[show].children
this.parSelected = this.parArray[show].key
this.selected = value
}
},
parentChange (value) {
this.childArray = [];
this.childArray.unshift(this.defaultChild)
this.childValue = ''
if (value != '') {
let pars2 = { typeId: this.typeId, parentId: value };
this.$api.parameter.getParameterList(pars2).then(({ data = {} }) => {
if (data) {
this.childArray = data.data
this.childArray.unshift(this.defaultChild)
}
}).catch(() => { });
}
else {
this.childArray = [this.defaultChild]
this.childValue = ''
this.$emit("input", null);
this.$emit("change");
}
this.$emit('parentChange', value)
this.$emit("change");
},
childChange (value) {
this.$emit("input", value);
var newArr = this.childArray.filter(x => x.key == value);
if (!!newArr && newArr.length > 0) {
var text = !!value ? newArr[0].title : ''
this.$emit('changeTitle', text)
}
this.$emit("change");
},
getParIndex (list, value) {
var show = 0
if (!!list && list.length > 0) {
for (var i = 0; i < list.length; i++) {
for (var j = 0; j < list[i].children.length; j++) {
if (list[i].children[j].key == value) {
show = i
break
}
}
}
}
return show
}
},
watch: {
value: {
handler (value) {
if (!!value && !this.loading) {
this.loading = true
this.load(value)
}
},
},
}
}
</script>