useAirportTable.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. import { Query } from '@/api/webApi'
  2. import { CommonData, CommonTableColumn } from '~/common'
  3. const columnGroupsMap: {
  4. [x: string]: {
  5. groupName: string
  6. children: { columnName: string; columnLabel: string; [x: string]: any }[]
  7. }[]
  8. } = {
  9. departure: [
  10. {
  11. groupName: '航班相关',
  12. children: [
  13. {
  14. columnName: 'flightNO',
  15. columnLabel: '航班号',
  16. needFilters: 1,
  17. },
  18. {
  19. columnName: 'flightDate',
  20. columnLabel: '执飞日期',
  21. },
  22. {
  23. columnName: 'planDepartureTime',
  24. columnLabel: '起飞时间',
  25. },
  26. {
  27. columnName: 'landingAirport',
  28. columnLabel: '目的站',
  29. needFilters: 1,
  30. },
  31. {
  32. columnName: 'takeOffStand',
  33. columnLabel: '停机位',
  34. },
  35. {
  36. columnName: 'inFlightNO',
  37. columnLabel: '前序航班',
  38. },
  39. {
  40. columnName: 'planLandingTime',
  41. columnLabel: '实际降落\n时间',
  42. },
  43. ],
  44. },
  45. {
  46. groupName: '货站相关',
  47. children: [
  48. {
  49. columnName: 'C1',
  50. columnLabel: '特货信息',
  51. },
  52. {
  53. columnName: 'C2',
  54. columnLabel: '预计装载数\n(运单/件)',
  55. },
  56. {
  57. columnName: 'C3',
  58. columnLabel: '中转进\n(运单/件)',
  59. },
  60. {
  61. columnName: 'C4',
  62. columnLabel: '退运\n(板卡/件)',
  63. },
  64. ],
  65. },
  66. {
  67. groupName: '地服相关',
  68. children: [
  69. {
  70. columnName: 'C5',
  71. columnLabel: '收运核单\n(运单/件/重量)',
  72. },
  73. {
  74. columnName: 'C5_time',
  75. columnLabel: '收运核单\n时间',
  76. },
  77. {
  78. columnName: 'C6',
  79. columnLabel: '查验\n(拒运/查验)',
  80. },
  81. {
  82. columnName: 'C6_time',
  83. columnLabel: '查验时间',
  84. },
  85. {
  86. columnName: 'C7',
  87. columnLabel: '安检\n(运单/件)',
  88. },
  89. {
  90. columnName: 'C7_time',
  91. columnLabel: '安检时间',
  92. },
  93. {
  94. columnName: 'C8',
  95. columnLabel: '加货\n(运单/板卡/件/重量)',
  96. },
  97. {
  98. columnName: 'C8_time',
  99. columnLabel: '加货时间',
  100. },
  101. {
  102. columnName: 'C9',
  103. columnLabel: '待运区\n(板卡/件)',
  104. },
  105. {
  106. columnName: 'C9_time',
  107. columnLabel: '待运区时间',
  108. },
  109. {
  110. columnName: 'C10',
  111. columnLabel: '配载\n(板卡/件)',
  112. },
  113. {
  114. columnName: 'C10_time',
  115. columnLabel: '配载时间',
  116. },
  117. {
  118. columnName: 'C11',
  119. columnLabel: '计划交接\n时间',
  120. },
  121. {
  122. columnName: 'C12',
  123. columnLabel: '货站交接\n(板卡/件)',
  124. },
  125. {
  126. columnName: 'C12_time',
  127. columnLabel: '货站交接\n时间',
  128. },
  129. {
  130. columnName: 'C13',
  131. columnLabel: '运输前复核\n(板卡/件)',
  132. },
  133. {
  134. columnName: 'C13_time',
  135. columnLabel: '运输前复核\n时间',
  136. },
  137. {
  138. columnName: 'C14',
  139. columnLabel: '机下交接\n(板卡/件)',
  140. },
  141. {
  142. columnName: 'C14_time',
  143. columnLabel: '机下交接\n时间',
  144. },
  145. {
  146. columnName: 'C15',
  147. columnLabel: '装机\n(板卡/件)',
  148. },
  149. {
  150. columnName: 'C15_time',
  151. columnLabel: '装机时间',
  152. },
  153. {
  154. columnName: 'C16',
  155. columnLabel: '拉货登记\n(板卡/件)',
  156. },
  157. {
  158. columnName: 'C16_time',
  159. columnLabel: '拉货登记\n时间',
  160. },
  161. {
  162. columnName: 'C17',
  163. columnLabel: '拉回确认\n(板卡/件)',
  164. },
  165. {
  166. columnName: 'C17_time',
  167. columnLabel: '拉回确认\n时间',
  168. },
  169. ],
  170. },
  171. ],
  172. arrival: [
  173. {
  174. groupName: '航班相关',
  175. children: [
  176. {
  177. columnName: 'flightNO',
  178. columnLabel: '航班号',
  179. needFilters: 1,
  180. },
  181. {
  182. columnName: 'flightDate',
  183. columnLabel: '执飞日期',
  184. },
  185. {
  186. columnName: 'planLandingTime',
  187. columnLabel: '降落时间',
  188. },
  189. {
  190. columnName: 'landingAirport',
  191. columnLabel: '目的站',
  192. needFilters: 1,
  193. },
  194. {
  195. columnName: 'landingStand',
  196. columnLabel: '停机位',
  197. },
  198. ],
  199. },
  200. {
  201. groupName: '货站相关',
  202. children: [
  203. {
  204. columnName: 'C1',
  205. columnLabel: '特货信息',
  206. },
  207. {
  208. columnName: 'C2',
  209. columnLabel: '预计卸载数\n(运单/件)',
  210. },
  211. {
  212. columnName: 'C3',
  213. columnLabel: '中转出\n(运单/件)',
  214. },
  215. {
  216. columnName: 'C4',
  217. columnLabel: '收货差异\n(板卡/件)',
  218. },
  219. ],
  220. },
  221. {
  222. groupName: '地服相关',
  223. children: [
  224. {
  225. columnName: 'C5',
  226. columnLabel: '卸机\n(板/箱/卡)',
  227. },
  228. {
  229. columnName: 'C5_time',
  230. columnLabel: '卸机时间',
  231. },
  232. {
  233. columnName: 'C6',
  234. columnLabel: '机下交接\n(板/箱/卡)',
  235. },
  236. {
  237. columnName: 'C6_time',
  238. columnLabel: '机下交接\n时间',
  239. },
  240. {
  241. columnName: 'C7',
  242. columnLabel: '货站交接\n(板/箱/卡)',
  243. },
  244. {
  245. columnName: 'C7_time',
  246. columnLabel: '货站交接\n时间',
  247. },
  248. {
  249. columnName: 'C8_time',
  250. columnLabel: '理货时间',
  251. },
  252. {
  253. columnName: 'C9',
  254. columnLabel: '出库\n(批/运单/件)',
  255. },
  256. {
  257. columnName: 'C9_time',
  258. columnLabel: '出库时间',
  259. },
  260. ],
  261. },
  262. ],
  263. }
  264. const simulateTableDataMap = {
  265. departure: Array.from({ length: 3 }, (_, i) => ({
  266. flightNO: 'ZH3423',
  267. flightDate: '2022/09/10',
  268. planDepartureTime: '22/09/10 12:01',
  269. landingAirport: '-NGK-PEK',
  270. takeOffStand: '84',
  271. inFlightNO: 'HU2451',
  272. planLandingTime: '2022/09/10 11:01',
  273. C1: '锂2/冷1',
  274. C2: '365/536',
  275. C3: '1/2',
  276. C4: '',
  277. C5: '364/534/1254KG',
  278. C5_time: '12:02',
  279. C6: '0/7',
  280. C6_time: '12:02',
  281. C7: '364/534',
  282. C7_time: '12:02',
  283. C8: '8/365/536/1254KG',
  284. C8_time: '12:02',
  285. C9: '8/536',
  286. C9_time: '12:02',
  287. C10: '8/536',
  288. C10_time: '12:02',
  289. C11: '11:45',
  290. C12: i === 1 ? '4/243' : '8/536',
  291. C12_time: '12:02',
  292. C13: i === 2 ? '5/357' : '8/536',
  293. C13_time: '12:02',
  294. C14: '8/536',
  295. C14_time: '12:02',
  296. C15: '8/536',
  297. C15_time: '12:02',
  298. C16: '0/358/5',
  299. C16_time: '12:02',
  300. C17: '0/5',
  301. C17_time: '12:02',
  302. })),
  303. arrival: Array.from({ length: 3 }, (_, i) => ({
  304. flightNO: 'ZH3423',
  305. flightDate: '2022/09/10',
  306. planLandingTime: '22/09/10 12:01',
  307. landingAirport: 'NKG-PEK-',
  308. landingStand: '84',
  309. C1: '锂2/冷1',
  310. C2: '363/543',
  311. C3: '',
  312. C4: i === 0 ? '0/6' : '',
  313. C5: '8/8/8',
  314. C5_time: '12:02',
  315. C6: '8/8/8',
  316. C6_time: '12:02',
  317. C7: '8/8/8',
  318. C7_time: '12:02',
  319. C8: '8/363/537/1254KG',
  320. C8_time: '12:02',
  321. C9: '3/363/537',
  322. C9_time: '12:02',
  323. })),
  324. }
  325. const headerClassMap = ['bg-yellow', 'bg-green', 'bg-cyan']
  326. const computedWidth = (text: string) => {
  327. let width = 0
  328. text.split('\n').forEach(line => {
  329. const len = line.length
  330. let realLength = 0
  331. for (let i = 0; i < len; i++) {
  332. realLength += line.charCodeAt(i) > 255 ? 2 : 1
  333. }
  334. if (width < realLength * 8) {
  335. width = realLength * 8
  336. }
  337. })
  338. if (['航班号', '目的站'].includes(text)) {
  339. width += 8
  340. }
  341. return width
  342. }
  343. export default function useAirportTable(name: string, formData: CommonData) {
  344. const tableColumns = ref<CommonTableColumn[]>([])
  345. const tableData = ref<CommonData[]>([])
  346. const getTableColumns = () => {
  347. const groups =
  348. columnGroupsMap[name.includes('Departure') ? 'departure' : 'arrival']
  349. tableColumns.value = groups.reduce(
  350. (columns: CommonTableColumn[], group, groupIndex) => {
  351. group.children.forEach(column => {
  352. columns.push({
  353. key: column.columnName,
  354. dataKey: column.columnName,
  355. title: column.columnLabel,
  356. columnDescribe: '',
  357. dataType: '',
  358. listqueryTemplateID: null,
  359. needCount: null,
  360. needFilters: null,
  361. needGroup: null,
  362. needSearch: null,
  363. needShow: 1,
  364. needSort: null,
  365. orderNumber: null,
  366. queryTemplateColumnSetID: null,
  367. queryTemplateID: null,
  368. width: computedWidth(column.columnLabel),
  369. flexGrow: 1,
  370. align: 'center',
  371. headerClass: headerClassMap[groupIndex],
  372. groupName: group.groupName,
  373. ...column,
  374. })
  375. })
  376. return columns
  377. },
  378. []
  379. )
  380. }
  381. const getTableData = async () => {
  382. try {
  383. const {
  384. startDate,
  385. endDate,
  386. flightStatus,
  387. flightWarning,
  388. waybillType,
  389. } = formData
  390. const dataContent = [startDate, endDate, flightStatus, flightWarning]
  391. if (name.includes('International')) {
  392. dataContent.push(waybillType)
  393. }
  394. const {
  395. code,
  396. returnData: { columnSet, listValues },
  397. message,
  398. } = await Query<CommonData>({
  399. id: DATACONTENT_ID[name.slice(0, 1).toLowerCase() + name.slice(1)],
  400. dataContent,
  401. })
  402. if (Number(code) !== 0) {
  403. throw new Error(message || '失败')
  404. }
  405. // tableColumns.value = columnSet.map(column => ({
  406. // key: column.columnName,
  407. // dataKey: column.columnName,
  408. // title: column.columnLabel,
  409. // width: column.columnLabel.length * 50,
  410. // flexGrow: 1,
  411. // align: 'center',
  412. // ...column,
  413. // }))
  414. tableData.value = listValues
  415. } catch (error) {
  416. console.error(error)
  417. }
  418. }
  419. const getSimulateTableData = () => {
  420. tableData.value =
  421. simulateTableDataMap[name.includes('Departure') ? 'departure' : 'arrival']
  422. }
  423. let queryLoop: number | null = null
  424. const startQuery = async () => {
  425. await getTableData()
  426. queryLoop = window.setTimeout(
  427. startQuery,
  428. LOOP_INTERVAL[name.slice(0, 1).toLowerCase() + name.slice(1)]
  429. )
  430. }
  431. const stopQuery = () => {
  432. if (queryLoop) {
  433. clearTimeout(queryLoop)
  434. queryLoop = null
  435. }
  436. }
  437. // watch(formData, data => {
  438. // stopQuery()
  439. // if (data.startDate && data.endDate) {
  440. // startQuery()
  441. // }
  442. // })
  443. // onUnmounted(stopQuery)
  444. onMounted(() => {
  445. getTableColumns()
  446. getSimulateTableData()
  447. })
  448. return {
  449. tableColumns,
  450. tableData,
  451. }
  452. }