useTrackData.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. import { datetimeToTime } from '@/utils/validate'
  2. import { CSSProperties } from 'vue'
  3. import { CommonData, MaybeRef } from '~/common'
  4. interface TrackNode {
  5. name: string
  6. nodeCode: string
  7. flag: boolean
  8. labelWidth?: number
  9. descriptions: string[]
  10. }
  11. interface TrackAirport {
  12. airport: string
  13. isDeparture: boolean
  14. trackSteps: TrackNode[]
  15. }
  16. interface TrackAirline {
  17. flightNO: string
  18. flightDate: string
  19. airports: TrackAirport[]
  20. }
  21. const trackNodesMap = {
  22. departure: [
  23. {
  24. name: '收运核单',
  25. nodeCode: 'DEH',
  26. },
  27. // {
  28. // name: '收运核查',
  29. // nodeCode: 'ACC_CHECK',
  30. // },
  31. {
  32. name: '安检',
  33. // nodeCode: '安检',
  34. nodeCode: 'SECURITY', // 临时-复制加货
  35. },
  36. {
  37. name: '加货',
  38. nodeCode: 'ACC_BUP',
  39. },
  40. {
  41. name: '预配载',
  42. nodeCode: 'LS_CARGO',
  43. },
  44. // {
  45. // name: '待运区',
  46. // nodeCode: 'WAT_LOC',
  47. // },
  48. // {
  49. // name: '货站交接',
  50. // nodeCode: 'CARGOS_HANDOVER_STATUS_02',
  51. // },
  52. {
  53. name: '交接复核',
  54. nodeCode: 'CARGOS_HANDOVER_STATUS_03',
  55. // labelWidth: 70,
  56. },
  57. {
  58. name: '机下交接',
  59. nodeCode: '出港货邮',
  60. },
  61. {
  62. name: '装机',
  63. nodeCode: '装载完成',
  64. },
  65. {
  66. name: '关闭舱门',
  67. nodeCode: '关闭舱门',
  68. },
  69. {
  70. name: '拉下登记',
  71. nodeCode: 'CARGOS_OFFLOAD',
  72. },
  73. {
  74. name: '拉回确认',
  75. nodeCode: 'OFFLOAD_CONFIRM',
  76. },
  77. // {
  78. // name: '起飞',
  79. // nodeCode: 'TAKEOFF', // 待定
  80. // },
  81. {
  82. name: '退运',
  83. nodeCode: 'BILL_RETURN',
  84. },
  85. ],
  86. arrival: [
  87. {
  88. name: '卸机',
  89. nodeCode: 'CARGOS_ARR_HANDOVER',
  90. },
  91. {
  92. name: '库区到达',
  93. nodeCode: 'CARGOS_HANDOVER_STATUS_01',
  94. },
  95. {
  96. name: '货站交接',
  97. nodeCode: 'CARGOS_HANDOVER_STATUS_99',
  98. },
  99. {
  100. name: '理货',
  101. nodeCode: 'IMP_TALLY',
  102. },
  103. {
  104. name: '出库',
  105. nodeCode: 'FSUDLV',
  106. },
  107. ],
  108. internationalDeparture: [
  109. {
  110. name: '入园',
  111. nodeCode: 'EPORTREL',
  112. },
  113. {
  114. name: '海关',
  115. nodeCode: 'MTREL_out',
  116. },
  117. {
  118. name: '运抵',
  119. nodeCode: 'FOH',
  120. },
  121. {
  122. name: '安检',
  123. nodeCode: 'REH',
  124. },
  125. {
  126. name: '收运核单',
  127. nodeCode: 'RCS',
  128. },
  129. {
  130. name: '理货',
  131. nodeCode: 'ACC_BUP',
  132. },
  133. // {
  134. // name: '待运区',
  135. // nodeCode: 'WAT_LOC',
  136. // },
  137. // {
  138. // name: '货站交接',
  139. // nodeCode: 'CARGOS_HANDOVER_STATUS_02',
  140. // },
  141. {
  142. name: '交接复核',
  143. nodeCode: 'CARGOS_HANDOVER_STATUS_03',
  144. },
  145. {
  146. name: '机下交接',
  147. nodeCode: '出港货邮',
  148. },
  149. {
  150. name: '装机',
  151. nodeCode: '装载完成',
  152. },
  153. {
  154. name: '拉下',
  155. nodeCode: 'CARGOS_OFFLOAD',
  156. },
  157. // {
  158. // name: '实配',
  159. // nodeCode: 'LS_CARGO',
  160. // },
  161. // {
  162. // name: '退运',
  163. // nodeCode: '',
  164. // },
  165. ],
  166. internationalArrival: [
  167. {
  168. name: '卸机',
  169. nodeCode: 'FFM',
  170. },
  171. {
  172. name: '机下交接',
  173. nodeCode: 'CARGOS_HANDOVER_STATUS_01',
  174. },
  175. {
  176. name: '货站交接',
  177. nodeCode: 'CARGOS_HANDOVER_STATUS_99',
  178. },
  179. {
  180. name: '理货',
  181. nodeCode: 'RCF报',
  182. },
  183. // {
  184. // name: '快件运抵',
  185. // nodeCode: '',
  186. // },
  187. {
  188. name: '海关放行',
  189. nodeCode: 'MTREL_in',
  190. },
  191. {
  192. name: '出库',
  193. nodeCode: 'DLV报',
  194. },
  195. ],
  196. }
  197. export function useTrackData(name: string, trackData: MaybeRef<CommonData[]>) {
  198. const isInternational = name.includes('International')
  199. const computedTrackData = computed(() => {
  200. if (name !== 'DepartureWaybill') {
  201. return unref(trackData)
  202. }
  203. return unref(trackData).reduce((prevData, currentNode) => {
  204. if (currentNode.nodeCode === 'ACC_BUP') {
  205. return [
  206. ...prevData,
  207. currentNode,
  208. { ...currentNode, nodeCode: 'SECURITY' },
  209. ]
  210. }
  211. return [...prevData, currentNode]
  212. }, [] as CommonData[])
  213. })
  214. const trackAirlines = ref<TrackAirline[]>([])
  215. const getTrackAirlines = () => {
  216. const airlines = unref(computedTrackData).reduce(
  217. (
  218. airlines,
  219. {
  220. flightNO,
  221. flightDate,
  222. departureAirport,
  223. arriveAirport,
  224. nodeCode,
  225. execPosition,
  226. ConsignmentItemPackagingQuantityQuantity,
  227. execResult,
  228. execTime,
  229. }
  230. ) => {
  231. const isDeparture =
  232. trackNodesMap.departure
  233. .concat(trackNodesMap.internationalDeparture)
  234. .some(node => node.nodeCode === nodeCode) ||
  235. (name.includes('Departure') &&
  236. typeof nodeCode === 'string' &&
  237. [
  238. 'MTEXDEC',
  239. 'NEW',
  240. 'ACC_CHECK',
  241. 'CARGOS_HANDOVER_STATUS_02',
  242. 'WAT_LOC',
  243. 'LS_CARGO',
  244. ].includes(nodeCode))
  245. const airport = isDeparture
  246. ? String(departureAirport ?? '')
  247. : String(arriveAirport ?? '')
  248. const trackNode = {
  249. flag: Boolean(
  250. execPosition ||
  251. ConsignmentItemPackagingQuantityQuantity ||
  252. execResult ||
  253. execTime
  254. ),
  255. descriptions: [
  256. String(execPosition ?? ''),
  257. String(ConsignmentItemPackagingQuantityQuantity ?? ''),
  258. execResult ? '通过' : '未通过',
  259. datetimeToTime(execTime, flightDate),
  260. ],
  261. }
  262. const nodeList = trackNodesMap[
  263. isDeparture
  264. ? isInternational
  265. ? 'internationalDeparture'
  266. : 'departure'
  267. : isInternational
  268. ? 'internationalArrival'
  269. : 'arrival'
  270. ].map(node => {
  271. if (node.nodeCode === nodeCode) {
  272. return {
  273. ...node,
  274. ...trackNode,
  275. }
  276. } else {
  277. return {
  278. ...node,
  279. flag: false,
  280. descriptions: [],
  281. }
  282. }
  283. })
  284. const airline = airlines.find(
  285. airline =>
  286. airline.flightNO === flightNO &&
  287. airline.flightDate === airline.flightDate
  288. )
  289. if (airline) {
  290. const trackAirport = airline.airports.find(
  291. trackAirport => trackAirport.airport === airport
  292. )
  293. if (trackAirport) {
  294. trackAirport.trackSteps = trackAirport.trackSteps.map(node => {
  295. if (node.nodeCode === nodeCode) {
  296. node = {
  297. ...node,
  298. ...trackNode,
  299. }
  300. }
  301. return node
  302. })
  303. } else {
  304. airline.airports.push({
  305. airport,
  306. isDeparture,
  307. trackSteps: nodeList,
  308. })
  309. }
  310. } else {
  311. airlines.push({
  312. flightNO: String(flightNO ?? ''),
  313. flightDate: String(flightDate ?? ''),
  314. airports: [
  315. {
  316. airport,
  317. isDeparture,
  318. trackSteps: nodeList,
  319. },
  320. ],
  321. })
  322. }
  323. return airlines
  324. },
  325. [] as TrackAirline[]
  326. )
  327. trackAirlines.value = airlines.map(airline => {
  328. const dealedAirports = airline.airports.map((airport, index) => ({
  329. ...airport,
  330. trackSteps: airport.trackSteps.filter(
  331. (node, i, steps) =>
  332. node.flag ||
  333. (index > 0
  334. ? ['IMP_TALLY', 'FSUDLV'].includes(node.nodeCode) &&
  335. steps.some(
  336. node =>
  337. ['IMP_TALLY', 'FSUDLV'].includes(node.nodeCode) && node.flag
  338. )
  339. : !['CARGOS_OFFLOAD', 'OFFLOAD_CONFIRM', 'BILL_RETURN'].includes(
  340. node.nodeCode
  341. ))
  342. ),
  343. }))
  344. const sortedAirports =
  345. name.includes('Departure') === airline.airports[0].isDeparture
  346. ? dealedAirports
  347. : dealedAirports.reverse()
  348. return {
  349. ...airline,
  350. airports: sortedAirports,
  351. }
  352. })
  353. }
  354. watch(trackData, () => {
  355. getTrackAirlines()
  356. })
  357. const trackBoxStyle = computed(
  358. () => (airports: TrackAirport[], index: number) => {
  359. const style: CSSProperties = {}
  360. const totalLength = airports.reduce((pre, current) => {
  361. return pre + current.trackSteps.length - 1
  362. }, 0)
  363. style.width = totalLength
  364. ? `calc((100% - ${airports.length - 1} * 8px) * ${
  365. (airports[index].trackSteps.length - 1) / totalLength
  366. })`
  367. : '100%'
  368. style.minWidth = '300px'
  369. return style
  370. }
  371. )
  372. return {
  373. trackAirlines,
  374. trackBoxStyle,
  375. }
  376. }