import { Component, OnInit } from '@angular/core'; import { HttpClientService } from '../../services/http-client.service'; import dateFormatter from '../../utils/data-formatter'; import routeType from '../../utils/route-type'; import flightType from '../../utils/flight-type'; import arriDept from '../../utils/arri-dept'; @Component({ selector: 'app-main', templateUrl: './main.component.html', styleUrls: ['./main.component.scss'] }) export class MainComponent implements OnInit { public airline_col_lists: Array; public airline_row_lists: Array = []; public airline_color: Array = []; public row_state: number; public TOP_1 = 1000000000000; public TOP_2 = 2000000000000; public TOP_3 = 3000000000000; public TOP_4 = 4000000000000; public TOP_5 = 5000000000000; public TOP_6 = 6000000000000; public TOP_7 = 7000000000000; public TOP_8 = 8000000000000; public TOP_9 = 9000000000000; public TOP_10 = 10000000000000; public TOP_11 = 11000000000000; public TOP_12 = 12000000000000; public TOP_13 = 13000000000000; public TOP_14 = 14000000000000; public LEVEL_1 = 100000000000000; public LEVEL_2 = 200000000000000; public LEVEL_3 = 300000000000000; public LEVEL_4 = 400000000000000; public LEVEL_5 = 500000000000000; public LEVEL_6 = 600000000000000; public LEVEL_7 = 700000000000000; public LEVEL_8 = 800000000000000; public LEVEL_9 = 900000000000000; public LEVEL_10 = 1000000000000000; public LEVEL_11 = 1100000000000000; public LEVEL_12 = 1200000000000000; public LEVEL_13 = 1300000000000000; public LEVEL_14 = 1400000000000000; filterItems = { SEARCH:'', ALCD:'', FLIN:'', FLTY:'', } constructor( private httpCilent: HttpClientService ) { } selectRow($event, i) { this.row_state = i; } getColor(col_CODE) { if (col_CODE === 'SODT') { return 'skyblue' } else { return null } } ngOnInit() { /* 获取显示列 */ this.httpCilent.get('/assets/mock-data/airline-col_code.json').subscribe( data => { data.sort(function (a, b) { return (a['COL_ORDER'] - b['COL_ORDER']); }) this.airline_col_lists = data; } ) /* 获取航班动态信息 */ this.httpCilent.get('/assets/mock-data/airline-data.json').subscribe( data => { //解析数据 data.forEach(element => { let air_message = JSON.parse(element.value); this.airline_row_lists.push(air_message); }); //查找链接航班并将其组合成一条数据 for (let i = 0; i < this.airline_row_lists.length; i++) { if (this.airline_row_lists[i]['MVIN'] === 'D') { if (this.airline_row_lists[i]['TAID']) { let index = this.airline_row_lists.findIndex(val => { return val['FLID'] === this.airline_row_lists[i]['TAID'] }); if (index > -1) { this.airline_row_lists[i]['isLinked'] = true; this.airline_row_lists[i]['linkFlight'] = this.airline_row_lists[index]; this.airline_row_lists.splice(index, 1); i--; } } } } //排序 this.airline_row_lists.forEach(element => { element['order'] = this.sequence(element) element['ORDER'] = '+' + element['order'] }) this.airline_row_lists.sort(function (a, b) { return (a['order'] - b['order']); }) } ) } /** * 行排序规则方法 * @param flight * @return */ /** (0)000000+实际时间(到达航班有实际时间,且未超过1小时) (0-1)无链接航班,取实际(到达)时间 (0-2)有链接航班,且出发航班未有实际时间,取实际(到达)时间 (1)100000+商调完成时间(商调完成登机未开始) (2)110000+登机开始时间(登机开始尚未登机结束) (3)111000+登机结束时间(登机结束) (4)111100+计划/预计时间(无商调完成时间、登机开始时间、登机结束时间、航班实际完成时间) (4-1)无链接航班 (4-1-1)若有预计时间则取预计时间 (4-1-2)若无预计时间则取计划时间 (4-2)有链接航班 (4-2-1)若无实际到达时间,则 (4-2-1-1)若有预计到达时间则取预计到达时间 (4-2-1-2)若无预计到达时间则取计划到达时间 (4-2-2)若有实际到达时间, (4-2-2-1)若有预计出发时间则取预计出发时间 (4-2-2-2)若无预计出发时间则取计划出发时间 (5)111110+计划/预计时间(航班取消)[只考虑无链接航班,因为链接航班不会有取消状态] (5-1)若有预计时间则取预计时间 (5-2)若无预计时间则取计划时间 (6)111111+实际时间(航班完成) (6-1)无链接航班,取实际(到达/出发)时间 (6-1-1)到达航班有实际时间,且超过(含)1小时 (6-1-2)出发航班有实际时间 (6-2)有链接航班,取实际(出发)时间 */ public sequence(flight) { let dateTag: number = 10; let dateToCompare = new Date().getTime(); if (!this.isCancled(flight) && !this.isDone(flight) && this.isDelayed(flight)) { if (this.isLinked(flight)) { if (this.getActualDatetime(flight['linkFlight']) && !this.getActualDatetime(flight)) { dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['linkFlight']))).getTime(); dateTag = this.TOP_1; } else { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_2; } } else { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_3; } return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isBoading(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_4; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isFlying(flight)) { if (this.isArriFlight(flight)) { if (this.getEstimatedDatetime(flight)) { dateToCompare = new Date(dateFormatter(this.getEstimatedDatetime(flight))).getTime(); } else { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); } } else if (this.isLinked(flight)) { if (this.getEstimatedDatetime(flight['linkFlight'])) { dateToCompare = new Date(dateFormatter(this.getEstimatedDatetime(flight['linkFlight']))).getTime(); } else { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['linkFlight']))).getTime(); } } dateTag = this.TOP_5; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isLinked(flight) && this.getActualDatetime(flight['linkFlight']) && !this.getActualDatetime(flight)) { dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['linkFlight']))).getTime(); dateTag = this.TOP_6; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isDeptFlight(flight) && !this.startBoading(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_7; return dateToCompare + dateTag; } if (!this.isCancled(flight) && this.isArriFlight(flight) && this.isDone(flight)) { dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight))).getTime(); dateTag = this.TOP_8; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isOverBoading(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_9; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && !this.isFlying(flight)) { if (this.isLinked(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_10; } else if (this.isArriFlight(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_11; } return dateToCompare + dateTag; } if (!this.isCancled(flight) && this.isDone(flight) && (this.isLinked(flight) || this.isDeptFlight(flight))) { dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight))).getTime(); dateTag = this.TOP_12; return dateToCompare + dateTag; } if (this.isCancled(flight)) { dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); dateTag = this.TOP_13; return dateToCompare + dateTag; } return this.TOP_14 } /** * 获取航班实际时间 * @param flight * @return */ public getActualDatetime(flight) { return flight['ACTT']; } /** * 获取航班预计时间 * @param flight * @return */ public getEstimatedDatetime(flight) { return flight['ESTT'] } /** * 获取航班计划时间 * @param flight * @return */ public getScheduledDatetime(flight) { return flight['SODT'] } /** * 判断航班是否是链接航班 * @param flight * @return */ public isLinked(flight) { if (flight.isLinked) { return true } else { return false } } /** * 判断航班是否是纯离港航班 * @param flight * @return */ public isDeptFlight(flight) { if (flight.MVIN === 'D' && !flight.isLinked) { return true } else { return false } } /** * 判断航班是否是纯到港航班 * @param flight * @return */ public isArriFlight(flight) { if (flight.MVIN === 'A' && !flight.isLinked) { return true; } else { return false; } } /** * 判断航班是否已经前站起飞 * @param flight * @return */ public isFlying(flight) { if (this.isArriFlight(flight)) { if (flight['PADT']) { return true } else { return false } } else if (this.isLinked(flight)) { if (flight['linkFlight']['PADT']) { return true } else { return false } } else { return false; } } /** * 判断航班是否取消 * @param flight * @return */ public isCancled(flight) { if (this.isArriFlight(flight) || this.isDeptFlight(flight)) { if (flight['CNCL']) { return true } else { return false } } else { return false } } /** * 判断航班是否延误(只针对纯离港航班或链接航班中的离港航班) * @param flight * @return */ public isDelayed(flight) { if (this.isDeptFlight(flight) || this.isLinked(flight)) { if (flight['DELY']) { return true } else { return false } } else { return false; } } /** * 判断航班是否已经执行完成 * @param flight * @return */ public isDone(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { if (!this.getActualDatetime(flight)) { return false; } else { return true; } } else if (this.isArriFlight(flight)) { if (!this.getActualDatetime(flight)) { return false; } else { return true; } } else { return false; } } /** * 判断航班是否开始登机 * @param flight * @return */ public startBoading(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { if (!flight['BOTM']) { return false; } else { return true; } } else { return false; } } /** * 判断航班是否正在登机中 * @param flight * @return */ public isBoading(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { if (flight['BOTM'] && !flight['GCTM']) { return true; } else { return false; } } else { return false; } } /** * 判断航班是否登机结束 * @param flight * @return */ public isOverBoading(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { if (!flight['GCTM']) { return false; } else { return true; } } else { return false; } } }