Files
airport-chengdu-web/src/app/pages/tabset/related-tab/related-tab.component.ts
T
2019-02-18 17:59:22 +08:00

162 lines
7.6 KiB
TypeScript

import { Component, OnInit, Input } from '@angular/core';
import { Utils } from '../../../utils/utils';
@Component({
selector: 'app-related-tab',
templateUrl: './related-tab.component.html',
styleUrls: ['./related-tab.component.scss']
})
export class RelatedTabComponent implements OnInit {
private utils = new Utils();
public lines;
public airports;
public predelay;
public precancle;
public prefdiv;
public prefret;
public readelay;
public reacancle;
public reafdiv;
public reafret;
@Input() allAirports;
@Input() flightDefinitions;
@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: this.utils.timeFormatter(this.lines.preFlight.ERUT[i].SCDT), scat: this.utils.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: this.utils.timeFormatter(this.lines.reaFlight.ERUT[i].SCDT), scat: this.utils.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: this.utils.timeFormatter(linkAirport[i].SCDT), scat: this.utils.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 = Object.assign({}, delyMessage[delyMessage.length - 1]);
let fimsFlightstatusDefinition = null;
if (this.flightDefinitions && this.flightDefinitions.length > 0) {
for (let i = 0; i < this.flightDefinitions.length; i++) {
let temp = this.flightDefinitions[i];
if (temp.flightStatus && temp.flightStatus === this.predelay['CODE'] && temp.flightStatusType && temp.flightStatusType === "DLY") {
fimsFlightstatusDefinition = temp;
break;
}
}
}
if (fimsFlightstatusDefinition) {
this.predelay['TYPE'] = fimsFlightstatusDefinition.ddsc;
}
this.predelay['STRT'] = new Date(this.utils.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) {
let cancle = this.lines.preFlight['ABN'][cancleIndex].BODY;
this.precancle = new Date(this.utils.dateFormatter(cancle)).getTime();
}
if (fdivIndex > -1) {
let fdiv = this.lines.preFlight['ABN'][fdivIndex].BODY;
if (fdiv.DDES) {
this.prefdiv = Object.assign({}, fdiv);
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 = Object.assign({}, 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 = Object.assign({}, delyMessage[delyMessage.length - 1]);
let fimsFlightstatusDefinition = null;
if (this.flightDefinitions && this.flightDefinitions.length > 0) {
for (let i = 0; i < this.flightDefinitions.length; i++) {
let temp = this.flightDefinitions[i];
if (temp.flightStatus && temp.flightStatus === this.readelay['CODE'] && temp.flightStatusType && temp.flightStatusType === "DLY") {
fimsFlightstatusDefinition = temp;
break;
}
}
}
if (fimsFlightstatusDefinition) {
this.readelay['TYPE'] = fimsFlightstatusDefinition.ddsc;
}
this.readelay['STRT'] = new Date(this.utils.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) {
let cancle = this.lines.reaFlight['ABN'][cancleIndex].BODY;
this.reacancle = new Date(this.utils.dateFormatter(cancle)).getTime();
}
if (fdivIndex > -1) {
let fdiv = this.lines.reaFlight['ABN'][fdivIndex].BODY;
if (fdiv.DDES) {
this.reafdiv = Object.assign({}, fdiv);
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 = Object.assign({}, fret);
}
}
}
};
constructor() { }
ngOnInit() {
}
}