Files
airport-chengdu-web/src/app/pages/main/related-tab/related-tab.component.ts
T

124 lines
5.8 KiB
TypeScript

import { Component, OnInit, Input } from '@angular/core';
import timeFormatter from '../../../utils/time-formatter';
import dateFormatter from '../../../utils/date-formatter';
@Component({
selector: 'app-related-tab',
templateUrl: './related-tab.component.html',
styleUrls: ['./related-tab.component.scss']
})
export class RelatedTabComponent implements OnInit {
public lines;
public airports;
public predelay;
public precancle;
public prefdiv;
public prefret;
public readelay;
public reacancle;
public reafdiv;
public reafret;
@Input() allAirports;
@Input() set flight(flight) {
this.predelay = '';
this.precancle = '';
this.prefdiv = '';
this.prefret = '';
this.readelay = '';
this.reacancle = '';
this.reafdiv = '';
this.reafret = '';
this.lines = Object.assign({}, flight);
if (this.lines.preFlight && !this.lines.reaFlight) {
this.airports = this.lines.renderFlight.ERUT.split(' - ');
for (let i = 0; i < this.airports.length; i++) {
this.airports[i] = { airport: this.airports[i], scdt: timeFormatter(this.lines.preFlight.ERUT[i].SCDT), scat: timeFormatter(this.lines.preFlight.ERUT[i].SCAT) }
}
} else if (!this.lines.preFlight && this.lines.reaFlight) {
this.airports = this.lines.renderFlight.ERUT.split(' - ');
for (let i = 0; i < this.airports.length; i++) {
this.airports[i] = { airport: this.airports[i], scdt: timeFormatter(this.lines.reaFlight.ERUT[i].SCDT), scat: timeFormatter(this.lines.reaFlight.ERUT[i].SCAT) }
}
} else {
this.lines.preFlight.ERUT[this.lines.preFlight.ERUT.length - 1]['SCDT'] = this.lines.reaFlight.ERUT[0]['SCDT'];
let concatArray = this.lines.reaFlight.ERUT.slice(1);
let linkAirport = this.lines.preFlight.ERUT.concat(concatArray)
this.airports = this.lines.renderFlight.ERUT.split(' - ');
for (let i = 0; i < this.airports.length; i++) {
this.airports[i] = { airport: this.airports[i], scdt: timeFormatter(linkAirport[i].SCDT), scat: timeFormatter(linkAirport[i].SCAT) }
}
}
if (this.lines.preFlight && this.lines.preFlight['ABN'] && this.lines.preFlight['ABN'].length > 0) {
let delyIndex = this.lines.preFlight['ABN'].findIndex(ele => ele.TYPE === 'DLY');
let cancleIndex = this.lines.preFlight['ABN'].findIndex(ele => ele.TYPE === 'CAN');
let fdivIndex = this.lines.preFlight['ABN'].findIndex(ele => ele.TYPE === 'ALT');
let fretIndex = this.lines.preFlight['ABN'].findIndex(ele => ele.TYPE === 'RTN');
if (delyIndex > -1) {
let delyMessage = this.lines.preFlight['ABN'][delyIndex].BODY
this.predelay = delyMessage[delyMessage.length - 1];
this.predelay['STRT'] = new Date(dateFormatter(this.predelay['STRT'])).getTime();
this.predelay['DURA'] = parseInt(this.predelay['DURA'].substr(0, 2)) * 3600000 + parseInt(this.predelay['DURA'].substr(2, 3)) * 60000 + this.predelay['STRT']
}
if (cancleIndex > -1) {
this.precancle = this.lines.preFlight['ABN'][cancleIndex].BODY;
this.precancle = new Date(dateFormatter(this.precancle)).getTime();
}
if (fdivIndex > -1) {
this.prefdiv = this.lines.preFlight['ABN'][fdivIndex].BODY;
let airportIndex = this.allAirports.findIndex(val => val.airportCodeIata === this.prefdiv.DDES);
if (airportIndex > -1) {
this.prefdiv.DDES = this.allAirports[airportIndex].briefNameChn
}
}
if (fretIndex > -1) {
let fret = this.lines.preFlight['ABN'][fretIndex].BODY;
if (fret.VALUE && fret.REID) {
this.prefret = fret;
}
}
}
if (this.lines.reaFlight && this.lines.reaFlight['ABN'] && this.lines.reaFlight['ABN'].length > 0) {
let delyIndex = this.lines.reaFlight['ABN'].findIndex(ele => ele.TYPE === 'DLY');
let cancleIndex = this.lines.reaFlight['ABN'].findIndex(ele => ele.TYPE === 'CAN');
let fdivIndex = this.lines.reaFlight['ABN'].findIndex(ele => ele.TYPE === 'ALT');
let fretIndex = this.lines.reaFlight['ABN'].findIndex(ele => ele.TYPE === 'RTN');
if (delyIndex > -1) {
let delyMessage = this.lines.reaFlight['ABN'][delyIndex].BODY
this.readelay = delyMessage[delyMessage.length - 1];
this.readelay['STRT'] = new Date(dateFormatter(this.readelay['STRT'])).getTime();
this.readelay['DURA'] = parseInt(this.readelay['DURA'].substr(0, 2)) * 3600000 + parseInt(this.readelay['DURA'].substr(2, 3)) * 60000 + this.readelay['STRT'];
}
if (cancleIndex > -1) {
this.reacancle = this.lines.reaFlight['ABN'][cancleIndex].BODY;
this.reacancle = new Date(dateFormatter(this.reacancle)).getTime();
}
if (fdivIndex > -1) {
this.reafdiv = this.lines.reaFlight['ABN'][fdivIndex].BODY;
let airportIndex = this.allAirports.findIndex(val => val.airportCodeIata === this.reafdiv.DDES);
if (airportIndex > -1) {
this.reafdiv.DDES = this.allAirports[airportIndex].briefNameChn
}
}
if (fretIndex > -1) {
let fret = this.lines.reaFlight['ABN'][fretIndex].BODY;
if (fret.VALUE && fret.REID) {
this.reafret = fret;
}
}
}
};
constructor() { }
ngOnInit() {
}
}