VechicleSelect.vue 2.62 KB
<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>