VechicleBrand.vue
3.25 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
<el-form-item :label="label" :prop="prop">
<el-select v-model="brandId" @change="brandChange" filterable placeholder="请选择" size="mini" class="el-slect" :disabled="disabled">
<el-option
v-for="item in brandOpts"
:key="item.brandId"
:label="item.brandName"
:value="item.brandId">
</el-option>
</el-select>
<el-select v-model="typeId" @change="typeChange" placeholder="" size="mini" class="el-slect" :disabled="disabled">
<el-option
v-for="item in typeOpts"
:key="item.vehicleTypeId"
:label="item.vehicleTypeName"
:value="item.vehicleTypeId">
</el-option>
</el-select>
</el-form-item>
</template>
<script>
import {services} from '../api'
const COMMON_SERVICE = services.common;
export default{
props:['label', 'prop', 'brandId', 'typeId', 'disabled', 'init'],
data(){
return {
//brandId: this.initBrandId?this.initBrandId:'',
brandOpts: [],
//typeId: this.initTypeId?this.initTypeId:'',
typeOpts: [],
bid: this.brandId,
tid: this.typeId,
_promise: null
}
},
computed: {
areaStr:{
get(){
return this.province+this.city+this.area;
}
}
},
created(){
this._promise = new Promise((resolve, reject)=>{
COMMON_SERVICE.getAllVehicleBrand({}).then((result)=>{
if(result.returnCode == 0){
this.brandOpts = result.data;
resolve()
}
})
})
},
watch: {
/* brandId(newVal, oldValue){console.log('watch brandId')
this._promise.then(()=>{
this.bid = newVal
if(this.init){
if(newVal && newVal!=oldValue){
if(this.brandOpts.length){
this.ing = true
COMMON_SERVICE.getBrandTypeByBrandId({vehicleBrandId: newVal}).then((result)=>{
if(result.returnCode == '0'){
this.typeOpts = result.data;
}
});
}
}
}
})
},
typeId(newVal){console.log('watch typeId')
if(newVal){
this.tid = parseInt(newVal)
}else{
this.tid = ''
this.typeOpts = []
}
} */
init(newVal){
if(newVal === true){
this.$emit('onBrandInitChange')
this._promise.then(()=>{
COMMON_SERVICE.getBrandTypeByBrandId({vehicleBrandId: this.brandId}).then((result)=>{
if(result.returnCode == '0'){
this.typeOpts = result.data;
}
});
})
}
}
},
methods: {
brandChange(){
if(this.brandOpts.length){
this.$emit('onBrandInitChange')
COMMON_SERVICE.getBrandTypeByBrandId({vehicleBrandId: this.brandId}).then((result)=>{
if(result.returnCode == '0'){
this.typeOpts = result.data;
this.typeId = this.typeOpts[0].vehicleTypeId;
this.brandName = this.brandOpts.find(item => item.brandId === this.brandId).brandName
this.typeName = this.typeOpts.find(item => item.vehicleTypeId === this.typeId).vehicleTypeName
this.$emit('onBrandChange', this.brandId, this.typeId, this.brandName, this.typeName)
}
});
}
},
typeChange(){
this.brandName = this.brandOpts.find(item => item.brandId === this.brandId).brandName
this.typeName = this.typeOpts.find(item => item.vehicleTypeId === this.typeId).vehicleTypeName
this.$emit('onBrandChange', this.brandId, this.typeId, this.brandName, this.typeName)
}
}
}
</script>
<style>
</style>