<template>
	<view>
	
		<uni-card >
			<!-- <text>这是一个基础卡片示例，内容较少，此示例展示了一个没有任何属性不带阴影的卡片。</text> -->
			<uni-row class="demo-uni-row">
				<uni-col :span="12">
					<view class="demo-uni-col">
						<text class="labelStyle">机号：</text>
						<text class="textStyle">{{tailNumber}}</text>
					</view>
				</uni-col>
				<uni-col :span="12">
					<view class="demo-uni-col">
						<text class="labelStyle">当前航班：</text>
						<text class="textStyle">{{currentFlight}}</text>  
					</view>
				</uni-col>
			</uni-row>
			<br>
			<uni-row class="demo-uni-row">
				<uni-col :span="12">
					<view class="demo-uni-col">
						<text class="labelStyle">机队：</text>
						<text class="textStyle">{{fleet}}</text>
					</view>
				</uni-col>
			</uni-row>
		</uni-card>
		<uni-list class="dataStyle"  >
			<uni-list-item :style="v.flightNo == currentFlight ? 'background-color:#cccccc' : 'background-color:#ffffff'" v-for="(v,i) in flightLegsnow" link :key="i" @click="flightDetail(v)" :title="v.flightNo"
				:rightText="v.offTime" :note="'航线：'+v.dep+'-->'+v.arr"></uni-list-item>
		</uni-list>
		<uni-list class="dataStyle">
			<uni-list-item v-for="(v,i) in dataSource" link :key="i" @click="flightDetail(v)" :title="v.flightNo"
				:rightText="v.outTime" :note="'航线：'+v.dep+'-->'+v.arr"></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	import {
		get72HourFlight
	} from "@/utils/requestahm.js"
	export default {
		name: "flightInforms",
		data() {
			return {
				flightLegsnow:[],
				card:{},
				dataSource: [],
				airPlane: {
				}
			};
		},
		props:{
			currentFlight:{
				type:String
			},
			tailNumber:{
				type:String
			},
			fleet:{
				type:String
			},
			flightLegs :{
				type :Array,
				default:[],
			}
		},
		created() {
			console.log('当天---航段信息-------',this.flightLegs)
			
			console.log(currentdate)
			if(this.flightLegs.length>0){
				let itemtime =  this.flightLegs[0].offTime
				let dates = new Date(itemtime);			
				console.log('当天---航段信息-------',itemtime)
				let date = new Date(dates.getTime() - 24 * 60 * 60 * 1000);			 
				 // console.log(frontOneHour)
				var symbol_gang = "-";
				var symbol_maohao = ":";
				var strMonth = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				var strDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				var strHours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				var strMinutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				var strSeconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				var currentdate = date.getFullYear() + symbol_gang + strMonth + symbol_gang + strDay
				    + " " + strHours + symbol_maohao + strMinutes
				    + symbol_maohao + strSeconds;
				this.flightLegsnow = this.flightLegs.filter(item => item.offTime > currentdate)

			}
			this.flightLegsnow.reverse()
			//console.log('当天---航段信息---后----',this.flightLegsnow.reverse())
			
		},
		mounted() {
			this.init();
		},
		onLoad(option) {
			
		},
		methods: {
			//初始化数据
			init() {
				//显示加载框
				uni.showLoading({
				    title: '加载中...'
				});
							
				get72HourFlight({
					tailnumber: this.tailNumber
				}).then(res => {
					if (res.code == 200) {
						if (res.data) {
						
							this.dataSource = res.data.nextFlightLegs
							this.fleet = res.data.fleet
							this.airPlane = res.data
							console.log('未来航班------',this.dataSource)													
						}
						if(this.dataSource.length==0){
							//隐藏加载
							uni.hideLoading();
							uni.showToast({
							    title: '无未来航班动态',
							    icon: 'none'
							})
						}else{
							//隐藏加载
							uni.hideLoading();
						}
						
					}					
				})
				
			},
			//回退到上一页面
			clickLeft() {
				uni.navigateBack()
			},
			//进入详情
			flightDetail(v) {
			
				delete this.airPlane['nextFlightLegs']
				console.log("删除完字段的数据：***", this.airPlane);
				uni.navigateTo({
					url: '/pages/modules/ahm/fraMonitoring/flightDetail?item=' +
						encodeURIComponent(JSON.stringify(v)) + '&airplane=' + encodeURIComponent(JSON.stringify(
							this.airPlane))
				})
			}
		},
		beforeUnmount() {
			//实例销毁之前调用(vue2此是 beforeDestroy)
		},
	};
</script>
<style scoped lang="less">
	.labelStyle {
		font-size: 14px;
		font-weight: bold;
	}

	.textStyle {
		font-size: 18px;
		font-weight: bolder;
		color: #0299E3;
	}

	/deep/ .uni-list {
		margin: 0 10px;
	}

	/deep/ .uni-list-item__content-title {
		font-size: 15px;
		color: #0299E3;
		overflow: hidden;
	}
</style>
