useTrackData.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { CSSProperties } from 'vue'
  2. import { CommonData, MaybeRef } from '~/common'
  3. interface TrackNode {
  4. name: string
  5. nodeCode: string
  6. flag: boolean
  7. labelWidth?: number
  8. descriptions: string[]
  9. }
  10. interface TrackAirport {
  11. airport: string
  12. isDeparture: boolean
  13. trackSteps: TrackNode[]
  14. }
  15. interface TrackAirline {
  16. flightNO: string
  17. flightDate: string
  18. airports: TrackAirport[]
  19. }
  20. const trackNodesMap = {
  21. departure: [
  22. {
  23. name: '收货核单',
  24. nodeCode: 'DEH',
  25. },
  26. {
  27. name: '查验',
  28. nodeCode: 'ACC_CHECK',
  29. },
  30. {
  31. name: '安检',
  32. nodeCode: '安检', // 暂无
  33. },
  34. {
  35. name: '加货',
  36. nodeCode: 'LS_CARGO',
  37. },
  38. {
  39. name: '待运区',
  40. nodeCode: 'WAT_LOC',
  41. },
  42. {
  43. name: '货站交接',
  44. nodeCode: 'CARGOS_DEP_ULD_HANDOVER',
  45. },
  46. {
  47. name: '机下交接',
  48. nodeCode: '出港货邮',
  49. },
  50. {
  51. name: '装机',
  52. nodeCode: '装载完成',
  53. },
  54. {
  55. name: '拉下',
  56. nodeCode: 'CARGOS_OFFLOAD',
  57. },
  58. {
  59. name: '拉回',
  60. nodeCode: 'OFFLOAD_CONFIRM',
  61. },
  62. // {
  63. // name: '起飞',
  64. // nodeCode: 'TAKEOFF', // 待定
  65. // },
  66. {
  67. name: '退运',
  68. nodeCode: 'BILL_RETURN',
  69. },
  70. ],
  71. arrival: [
  72. {
  73. name: '卸机',
  74. nodeCode: 'CARGOS_ARR_HANDOVER',
  75. },
  76. {
  77. name: '机下交接',
  78. nodeCode: 'CARGOS_HANDOVER_STATUS',
  79. },
  80. {
  81. name: '货站交接',
  82. nodeCode: '货站交接', // 暂无
  83. },
  84. {
  85. name: '理货',
  86. nodeCode: 'IMP_TALLY',
  87. },
  88. {
  89. name: '出库',
  90. nodeCode: 'FSU_DLV',
  91. },
  92. ],
  93. internationalDeparture: [],
  94. internationalArrival: [],
  95. }
  96. export function useTrackData(name: string, trackData: MaybeRef<CommonData[]>) {
  97. const isInternational = name.includes('International')
  98. const trackAirlines = ref<TrackAirline[]>([])
  99. const getTrackAirlines = () => {
  100. const airlines = unref(trackData).reduce(
  101. (
  102. airlines,
  103. {
  104. flightNO,
  105. flightDate,
  106. departureAirport,
  107. arriveAirport,
  108. nodeCode,
  109. execPosition,
  110. ConsignmentItemPackagingQuantityQuantity,
  111. execResult,
  112. execTime,
  113. }
  114. ) => {
  115. const isDeparture =
  116. trackNodesMap.departure
  117. .concat(trackNodesMap.internationalDeparture)
  118. .some(node => node.nodeCode === nodeCode) ||
  119. (name.includes('Departure') && nodeCode === 'NEW')
  120. const airport = isDeparture
  121. ? String(departureAirport ?? '')
  122. : String(arriveAirport ?? '')
  123. const trackNode = {
  124. flag: Boolean(
  125. execPosition ||
  126. ConsignmentItemPackagingQuantityQuantity ||
  127. execResult ||
  128. execTime
  129. ),
  130. descriptions: [
  131. String(execPosition ?? ''),
  132. String(ConsignmentItemPackagingQuantityQuantity ?? ''),
  133. execResult ? '通过' : '未通过',
  134. String(execTime ?? '').split('T')[1] ?? '',
  135. ],
  136. }
  137. const nodeList = trackNodesMap[
  138. isDeparture
  139. ? isInternational
  140. ? 'internationalDeparture'
  141. : 'departure'
  142. : isInternational
  143. ? 'internationalArrival'
  144. : 'arrival'
  145. ].map(node => {
  146. if (node.nodeCode === nodeCode) {
  147. return {
  148. ...node,
  149. ...trackNode,
  150. }
  151. } else {
  152. return {
  153. ...node,
  154. flag: false,
  155. descriptions: [],
  156. }
  157. }
  158. })
  159. const airline = airlines.find(
  160. airline =>
  161. airline.flightNO === flightNO &&
  162. airline.flightDate === airline.flightDate
  163. )
  164. if (airline) {
  165. const trackAirport = airline.airports.find(
  166. trackAirport => trackAirport.airport === airport
  167. )
  168. if (trackAirport) {
  169. trackAirport.trackSteps = trackAirport.trackSteps.map(node => {
  170. if (node.nodeCode === nodeCode) {
  171. node = {
  172. ...node,
  173. ...trackNode,
  174. }
  175. }
  176. return node
  177. })
  178. } else {
  179. airline.airports.push({
  180. airport,
  181. isDeparture,
  182. trackSteps: nodeList,
  183. })
  184. }
  185. } else {
  186. airlines.push({
  187. flightNO: String(flightNO ?? ''),
  188. flightDate: String(flightDate ?? ''),
  189. airports: [
  190. {
  191. airport,
  192. isDeparture,
  193. trackSteps: nodeList,
  194. },
  195. ],
  196. })
  197. }
  198. return airlines
  199. },
  200. [] as TrackAirline[]
  201. )
  202. trackAirlines.value = airlines.map(airline => {
  203. return {
  204. ...airline,
  205. airports:
  206. name.includes('Departure') === airline.airports[0].isDeparture
  207. ? airline.airports
  208. : airline.airports.reverse(),
  209. }
  210. })
  211. }
  212. watch(trackData, () => {
  213. getTrackAirlines()
  214. })
  215. const trackBoxStyle = computed(
  216. () => (airports: TrackAirport[], index: number) => {
  217. const style: CSSProperties = {}
  218. const totalLength = airports.reduce((pre, current) => {
  219. return pre + current.trackSteps.length - 1
  220. }, 0)
  221. style.width = totalLength
  222. ? `calc((100% - ${airports.length - 1} * 8px) * ${
  223. (airports[index].trackSteps.length - 1) / totalLength
  224. })`
  225. : '100%'
  226. return style
  227. }
  228. )
  229. return {
  230. trackAirlines,
  231. trackBoxStyle,
  232. }
  233. }