import { CSSProperties } from 'vue' import { CommonData, MaybeRef } from '~/common' interface TrackNode { name: string nodeCode: string flag: boolean labelWidth?: number descriptions: string[] } interface TrackAirport { airport: string isDeparture: boolean trackSteps: TrackNode[] } interface TrackAirline { flightNO: string flightDate: string airports: TrackAirport[] } const trackNodesMap = { departure: [ { name: '收货核单', nodeCode: 'DEH', }, { name: '查验', nodeCode: 'ACC_CHECK', }, { name: '安检', nodeCode: '安检', // 暂无 }, { name: '加货', nodeCode: 'LS_CARGO', }, { name: '待运区', nodeCode: 'WAT_LOC', }, { name: '货站交接', nodeCode: 'CARGOS_DEP_ULD_HANDOVER', }, { name: '机下交接', nodeCode: '出港货邮', }, { name: '装机', nodeCode: '装载完成', }, { name: '拉下', nodeCode: 'CARGOS_OFFLOAD', }, { name: '拉回', nodeCode: 'OFFLOAD_CONFIRM', }, // { // name: '起飞', // nodeCode: 'TAKEOFF', // 待定 // }, { name: '退运', nodeCode: 'BILL_RETURN', }, ], arrival: [ { name: '卸机', nodeCode: 'CARGOS_ARR_HANDOVER', }, { name: '机下交接', nodeCode: 'CARGOS_HANDOVER_STATUS', }, { name: '货站交接', nodeCode: '货站交接', // 暂无 }, { name: '理货', nodeCode: 'IMP_TALLY', }, { name: '出库', nodeCode: 'FSU_DLV', }, ], internationalDeparture: [], internationalArrival: [], } export function useTrackData(name: string, trackData: MaybeRef) { const isInternational = name.includes('International') const trackAirlines = ref([]) const getTrackAirlines = () => { const airlines = unref(trackData).reduce( ( airlines, { flightNO, flightDate, departureAirport, arriveAirport, nodeCode, execPosition, ConsignmentItemPackagingQuantityQuantity, execResult, execTime, } ) => { if ( !nodeCode || Object.values(trackNodesMap) .flat() .every(node => node.nodeCode !== nodeCode) ) { return airlines } const isDeparture = [ 'DEH', 'ACC_CHECK', '安检', 'ACC_BUP', 'WAT_LOC', 'CARGOS_DEP_ULD_HANDOVER', '出港货邮', '装载完成', 'CARGOS_OFFLOAD', 'OFFLOAD_CONFIRM', 'BILL_RETURN', ].includes(String(nodeCode)) const airport = isDeparture ? String(departureAirport ?? '') : String(arriveAirport ?? '') const trackNode = { flag: Boolean( execPosition || ConsignmentItemPackagingQuantityQuantity || execResult || execTime ), descriptions: [ String(execPosition ?? ''), String(ConsignmentItemPackagingQuantityQuantity ?? ''), String(execResult ?? ''), String(execTime ?? '').split('T')[1] ?? '', ], } const nodeList = trackNodesMap[ isDeparture ? isInternational ? 'internationalDeparture' : 'departure' : isInternational ? 'internationalArrival' : 'arrival' ].map(node => { if (node.nodeCode === nodeCode) { return { ...node, ...trackNode, } } else { return { ...node, flag: false, descriptions: [], } } }) const airline = airlines.find( airline => airline.flightNO === flightNO && airline.flightDate === airline.flightDate ) if (airline) { const trackAirport = airline.airports.find( trackAirport => trackAirport.airport === airport ) if (trackAirport) { trackAirport.trackSteps = trackAirport.trackSteps.map(node => { if (node.nodeCode === nodeCode) { node = { ...node, ...trackNode, } } return node }) } else { airline.airports.push({ airport, isDeparture: isDeparture, trackSteps: nodeList, }) } } else { airlines.push({ flightNO: String(flightNO ?? ''), flightDate: String(flightDate ?? ''), airports: [ { airport, isDeparture: isDeparture, trackSteps: nodeList, }, ], }) } return airlines }, [] as TrackAirline[] ) trackAirlines.value = airlines.map(airline => { return { ...airline, airports: name.includes('Departure') === airline.airports[0].isDeparture ? airline.airports : airline.airports.reverse(), } }) } watch(trackData, () => { getTrackAirlines() }) const trackBoxStyle = computed( () => (airports: TrackAirport[], index: number) => { const style: CSSProperties = {} const totalLength = airports.reduce((pre, current) => { return pre + current.trackSteps.length - 1 }, 0) style.width = totalLength ? `calc((100% - ${airports.length - 1} * 8px) * ${ (airports[index].trackSteps.length - 1) / totalLength })` : '100%' return style } ) return { trackAirlines, trackBoxStyle, } }