alarmListVechicleSelect.vue
2 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
<template>
<el-form-item :label="label" :prop="prop">
<el-select v-model="groupId" @change="groupChange" filterable placeholder="请选择" size="small" class="el-slect" >
<el-option
v-for="item in groupOpts"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<el-select v-show="classOpts.length" v-model="classId" @change="classChange" filterable placeholder="请选择" size="small" class="el-slect">
<el-option
v-for="item in classOpts"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</template>
<script>
import {services} from '../api'
const COMMON_SERVICE = services.common;
export default{
props:['label', 'prop', 'notPrependFirst'],
data(){
return {
groupId: '',
groupOpts: [],
classId: '',
classOpts: []
}
},
computed: {
},
created(){
COMMON_SERVICE.getAllVehicleGroup({}).then((result)=>{
if(result.returnCode == '0'){
if(!this.notPrependFirst){
this.groupOpts = [{name:'全部',id:''}].concat(result.data);
}else{
this.groupOpts = result.data;
this.groupId = this.groupOpts[0].id;
this.groupChange();
}
}
})
},
methods: {
groupChange(){
if(this.groupId){
COMMON_SERVICE.getClassListByGroupId({groupId: this.groupId}).then((result)=>{
if(result.returnCode == '0'){
this.classOpts = result.data;
this.classId = this.classOpts[0].id;
this.$emit('onVechicleChange', this.groupId, this.classId, this.classOpts[0].name)
}
});
}else{
this.classOpts = [];
this.classId = '';
this.$emit('onVechicleChange', this.groupId, this.classId)
}
},
classChange(){
const item = this.classOpts.find((o)=>{
return o.id === this.classId
});
this.$emit('onVechicleChange', this.groupId, this.classId, item.name)
},
resetSelet(){
this.groupId = "";
this.classId="";
}
}
}
</script>
<style scoped>
</style>