alarmListVechicleSelect.vue 2 KB
<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>