VechicleSelect.vue
2.62 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
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
<template>
<el-form-item :label="label" :prop="prop">
<el-select v-model="groupId" @change="groupChange" :placeholder="groupPlaceholder" size="small" class="el-slect" :disabled="orderStatus<=0">
<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||classId" v-model="classId" @change="classChange" :placeholder="classPlaceholder" size="small" class="el-slect" :disabled="orderStatus<=0">
<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' ,'groupIds','classIds','orderStatus','groupPlaceholder','classPlaceholder'],
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();
}
}
if(this.groupIds){
this.groupId = this.groupIds
}else{
this.groupId = ''
}
if(this.classIds){
this.classId =this.classIds
}
})
},
watch: {
groupIds(newVal,oldValue){
if(newVal){
this.groupId = newVal
}else{
this.groupId = ''
}
}
,
classIds(newVal,oldValue){
if(newVal){
this.classId = newVal
}else{
this.classId = ''
this.classOpts = [];
}
}
},
methods: {
groupChange(){
if(this.groupId){
COMMON_SERVICE.getClassListByGroupId({groupId: this.groupId}).then((result)=>{
if(result.returnCode == '0'){
this.classOpts = [{name:'全部',id:''}].concat(result.data);
//this.classId = this.classOpts[0].id;
this.classId = "";
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="";
this.groupChange()
}
}
}
</script>
<style scoped>
</style>