123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- import { datetimeToTime } from '@/utils/validate'
- 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: '安检',
- nodeCode: 'SECURITY', // 临时-复制加货
- },
- {
- name: '加货',
- nodeCode: 'ACC_BUP',
- },
- {
- name: '预配载',
- nodeCode: 'LS_CARGO',
- },
- // {
- // name: '待运区',
- // nodeCode: 'WAT_LOC',
- // },
- // {
- // name: '货站交接',
- // nodeCode: 'CARGOS_HANDOVER_STATUS_02',
- // },
- {
- name: '交接复核',
- nodeCode: 'CARGOS_HANDOVER_STATUS_03',
- // labelWidth: 70,
- },
- {
- name: '机下交接',
- nodeCode: '出港货邮',
- },
- {
- 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_01',
- },
- {
- name: '货站交接',
- nodeCode: 'CARGOS_HANDOVER_STATUS_99',
- },
- {
- name: '理货',
- nodeCode: 'IMP_TALLY',
- },
- {
- name: '出库',
- nodeCode: 'FSUDLV',
- },
- ],
- internationalDeparture: [
- {
- name: '入园',
- nodeCode: 'EPORTREL',
- },
- {
- name: '海关',
- nodeCode: 'MTREL_out',
- },
- {
- name: '运抵',
- nodeCode: 'FOH',
- },
- {
- name: '安检',
- nodeCode: 'REH',
- },
- {
- name: '收运核单',
- nodeCode: 'RCS',
- },
- {
- name: '理货',
- nodeCode: 'ACC_BUP',
- },
- // {
- // name: '待运区',
- // nodeCode: 'WAT_LOC',
- // },
- // {
- // name: '货站交接',
- // nodeCode: 'CARGOS_HANDOVER_STATUS_02',
- // },
- {
- name: '交接复核',
- nodeCode: 'CARGOS_HANDOVER_STATUS_03',
- },
- {
- name: '机下交接',
- nodeCode: '出港货邮',
- },
- {
- name: '装机',
- nodeCode: '装载完成',
- },
- {
- name: '拉下',
- nodeCode: 'CARGOS_OFFLOAD',
- },
- // {
- // name: '实配',
- // nodeCode: 'LS_CARGO',
- // },
- // {
- // name: '退运',
- // nodeCode: '',
- // },
- ],
- internationalArrival: [
- {
- name: '卸机',
- nodeCode: 'FFM',
- },
- {
- name: '机下交接',
- nodeCode: 'CARGOS_HANDOVER_STATUS_01',
- },
- {
- name: '货站交接',
- nodeCode: 'CARGOS_HANDOVER_STATUS_99',
- },
- {
- name: '理货',
- nodeCode: 'RCF报',
- },
- // {
- // name: '快件运抵',
- // nodeCode: '',
- // },
- {
- name: '海关放行',
- nodeCode: 'MTREL_in',
- },
- {
- name: '出库',
- nodeCode: 'DLV报',
- },
- ],
- }
- export function useTrackData(name: string, trackData: MaybeRef<CommonData[]>) {
- const isInternational = name.includes('International')
- const computedTrackData = computed(() => {
- if (name !== 'DepartureWaybill') {
- return unref(trackData)
- }
- return unref(trackData).reduce((prevData, currentNode) => {
- if (currentNode.nodeCode === 'ACC_BUP') {
- return [
- ...prevData,
- currentNode,
- { ...currentNode, nodeCode: 'SECURITY' },
- ]
- }
- return [...prevData, currentNode]
- }, [] as CommonData[])
- })
- const trackAirlines = ref<TrackAirline[]>([])
- const getTrackAirlines = () => {
- const airlines = unref(computedTrackData).reduce(
- (
- airlines,
- {
- flightNO,
- flightDate,
- departureAirport,
- arriveAirport,
- nodeCode,
- execPosition,
- ConsignmentItemPackagingQuantityQuantity,
- execResult,
- execTime,
- }
- ) => {
- const isDeparture =
- trackNodesMap.departure
- .concat(trackNodesMap.internationalDeparture)
- .some(node => node.nodeCode === nodeCode) ||
- (name.includes('Departure') &&
- typeof nodeCode === 'string' &&
- [
- 'MTEXDEC',
- 'NEW',
- 'ACC_CHECK',
- 'CARGOS_HANDOVER_STATUS_02',
- 'WAT_LOC',
- 'LS_CARGO',
- ].includes(nodeCode))
- const airport = isDeparture
- ? String(departureAirport ?? '')
- : String(arriveAirport ?? '')
- const trackNode = {
- flag: Boolean(
- execPosition ||
- ConsignmentItemPackagingQuantityQuantity ||
- execResult ||
- execTime
- ),
- descriptions: [
- String(execPosition ?? ''),
- String(ConsignmentItemPackagingQuantityQuantity ?? ''),
- execResult ? '通过' : '未通过',
- datetimeToTime(execTime, flightDate),
- ],
- }
- 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,
- trackSteps: nodeList,
- })
- }
- } else {
- airlines.push({
- flightNO: String(flightNO ?? ''),
- flightDate: String(flightDate ?? ''),
- airports: [
- {
- airport,
- isDeparture,
- trackSteps: nodeList,
- },
- ],
- })
- }
- return airlines
- },
- [] as TrackAirline[]
- )
- trackAirlines.value = airlines.map(airline => {
- const dealedAirports = airline.airports.map((airport, index) => ({
- ...airport,
- trackSteps: airport.trackSteps.filter(
- (node, i, steps) =>
- node.flag ||
- (index > 0
- ? ['IMP_TALLY', 'FSUDLV'].includes(node.nodeCode) &&
- steps.some(
- node =>
- ['IMP_TALLY', 'FSUDLV'].includes(node.nodeCode) && node.flag
- )
- : !['CARGOS_OFFLOAD', 'OFFLOAD_CONFIRM', 'BILL_RETURN'].includes(
- node.nodeCode
- ))
- ),
- }))
- const sortedAirports =
- name.includes('Departure') === airline.airports[0].isDeparture
- ? dealedAirports
- : dealedAirports.reverse()
- return {
- ...airline,
- airports: sortedAirports,
- }
- })
- }
- 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%'
- style.minWidth = '300px'
- return style
- }
- )
- return {
- trackAirlines,
- trackBoxStyle,
- }
- }
|