<template>
	<view>
		
		<view >
			<select-cy  :value="tvalinfo" placeholder="请选择机号" name="name"
				:options="datalist" :showClearIcon="true" :zindex="zindex"
				@change="change_select_cy"></select-cy>
		</view>
	</view>
		
</template>

<script>
	import {
		getTailnumberlist
	} from '@/utils/requestahm.js';
	
	export default {
	
		data() {
			return{				
				
				// //模拟初始数据
				tvalinfo:[],
				// //模拟数据列表
				 datalist: [
				],
				listitem:[],
			}
		},
		props: {
			tval:{
				type:Array,
				default:[],
			},
			zindex:Number,	
			fleetlist:Array,
		},
		watch:{
			fleetlist:{
				handler(newValue, oldValue) {
					this.querfleet()				
				}
			}
		},
		methods:{
			
			querfleet(){
				this.datalist = []
				
				if(this.fleetlist.length == 0){
					let param = {}
					for (var i = 0; i < this.listitem.length; i++) {
							param = {
								label:this.listitem[i].tailnumber,
								value:this.listitem[i].tailnumber,
							}
							this.datalist.push(param)
						
					}
				
				}else{
					let param = {}
					for (var i = 0; i < this.listitem.length; i++) {
						if(this.fleetlist.indexOf(this.listitem[i].fleet)>-1){
							param = {
								label:this.listitem[i].tailnumber,
								value:this.listitem[i].tailnumber,
							}
							this.datalist.push(param)
						}
												
					}
					if(this.datalist.length == 0){
						param = {
							label:'暂无数据',
							value:'暂无数据',
						}
						this.datalist.push(param)
					}
				
				}
			},
			
			async getDate(){
				
				const Tailnumberlist = await getTailnumberlist({
				
				})
			
				this.listitem = Tailnumberlist.data
				let param = {}
				
				
					for (var i = 0; i < Tailnumberlist.data.length; i++) {						
							param = {
								label:Tailnumberlist.data[i].tailnumber,
								value:Tailnumberlist.data[i].tailnumber,
							}
							this.datalist.push(param)
						
					}
				
								
			},
			// onchangeafter(){
			// 	let gg ='88'
			// 	return  gg
			// },
			//下拉框改变
			change_select_cy(item, value) {
		
				this.tvalinfo = value;
				this.$emit('changevalue', this.tvalinfo)
			},
			
		},
		created() {
			if(this.tval.length>0){
				this.tvalinfo = this.tval 
			}
			this.getDate()
		}
	}
</script>

<style>
</style>