index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="waybill">
  3. <div class="waybill-info">
  4. <div class="waybill-info-title">运单基本信息</div>
  5. <div class="waybill-info-content flex">
  6. <div
  7. v-for="(item, index) in waybillInfoItems"
  8. :key="index"
  9. class="waybill-info-item"
  10. >
  11. <div>{{ item.label }}:</div>
  12. <el-tooltip
  13. :disabled="!computedWaybillInfo(item) || !item.showOverflowTooltip"
  14. :content="computedWaybillInfo(item)"
  15. effect="light"
  16. >
  17. <div>{{ computedWaybillInfo(item) }}</div>
  18. </el-tooltip>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="waybill-header flex">
  23. <div class="waybill-header-title flex-wrap">
  24. <div class="manageTitle">运单跟踪信息</div>
  25. <div class="status">正常</div>
  26. </div>
  27. <div class="waybill-header-operate flex-wrap">
  28. <Search @clear="clear" @search="search" />
  29. <el-button
  30. class="button-sqaure"
  31. color="#ac014d"
  32. @click="exportHandler"
  33. >
  34. <i class="icon-export" />
  35. </el-button>
  36. <ColumnSet
  37. class="button-sqaure"
  38. :table-columns="tableColumns"
  39. @checked-submit="columnChecked"
  40. />
  41. </div>
  42. </div>
  43. <div
  44. v-show="trackAirlines.length"
  45. :style="{
  46. maxHeight: trackAirlines.length > 1 ? `${208 * 2 + 8}px` : '208px',
  47. }"
  48. class="waybill-track"
  49. >
  50. <el-scrollbar always>
  51. <div class="waybill-track-warpper">
  52. <div
  53. v-for="trackAirline in trackAirlines"
  54. :key="trackAirline.flightNO"
  55. class="waybill-track-row"
  56. >
  57. <div
  58. v-for="(trackAirport, index) in trackAirline.airports"
  59. :key="trackAirport.airport"
  60. class="waybill-track-box"
  61. :style="trackBoxStyle(trackAirline.airports, index)"
  62. >
  63. <div class="title flex-wrap">
  64. <span v-if="index === 0" class="title-span"
  65. >航班号:{{ trackAirline.flightNO }}</span
  66. >
  67. <!-- <span
  68. v-if="!name.includes('InternationalDeparture')"
  69. class="title-span"
  70. >{{ trackAirport.isDeparture ? '出港' : '进港' }}:{{
  71. trackAirport.airport
  72. }}</span
  73. > -->
  74. <span class="title-span"
  75. >日期:{{ trackAirline.flightDate }}</span
  76. >
  77. </div>
  78. <Steps :steps="trackAirport.trackSteps" />
  79. </div>
  80. </div>
  81. </div>
  82. </el-scrollbar>
  83. </div>
  84. <div class="goods-list">
  85. <SimpleTable
  86. ref="tableRef"
  87. :data="tableData"
  88. :columns="tableColumns"
  89. scrollbar-always-on
  90. :row-class-name="rowClass"
  91. :cell-class-name="cellClass"
  92. @cell-click="cellClickHandler"
  93. :column-props="{ formatter, minWidth: 75 }"
  94. />
  95. </div>
  96. </div>
  97. </template>
  98. <script setup lang="ts">
  99. import Search from '@/components/search/index.vue'
  100. import Steps from '@/components/steps/index.vue'
  101. import ColumnSet from '@/components/ColumnSet/index.vue'
  102. import SimpleTable from '@/components/SimpleTable/index.vue'
  103. import { useTrackData } from '../../hooks/useTrackData'
  104. import { useTable } from '../../hooks/useTable'
  105. import { useTableColumnSet } from '@/hooks/useTableColumnSet'
  106. import { useTableExport } from '../../hooks/useTableExport'
  107. import { useTableStyle } from '../../hooks/useTableStyle'
  108. import { useTableCellClick } from '../../hooks/useTableCellClick'
  109. import { useWaybillInfo } from './useWaybillInfo'
  110. import { CommonData, CommonTableFormatter, CommonValue } from '~/common'
  111. import { useLoop } from '@/hooks/useLoop'
  112. import { datetimeToTime } from '@/utils/validate'
  113. const props = defineProps({
  114. name: {
  115. type: String,
  116. required: true,
  117. },
  118. })
  119. const route = useRoute()
  120. const { flightDate, waybillNO } = route.query
  121. const dataContent = [flightDate, waybillNO] as string[]
  122. const {
  123. waybillInfoItems,
  124. waybillInfo,
  125. computedWaybillInfo,
  126. getWaybillInfo,
  127. } = useWaybillInfo(props.name, dataContent)
  128. const { tableColumns, tableData: trackData, getTableData } = useTable(
  129. `${props.name}Goods`,
  130. dataContent
  131. )
  132. // 判断是否有另外一个机场的节点信息,没有则隐藏那些列
  133. watch(trackData, data => {
  134. let anotherAirportNodeFlag = ''
  135. if (props.name.includes('Departure')) {
  136. anotherAirportNodeFlag = 'node-arrival'
  137. } else {
  138. anotherAirportNodeFlag = 'node-departure'
  139. }
  140. const activeNodes = data.reduce((nodes: string[], row) => {
  141. if (typeof row.nodeCode === 'string' && !nodes.includes(row.nodeCode)) {
  142. nodes.push(row.nodeCode)
  143. }
  144. return nodes
  145. }, [])
  146. tableColumns.value.forEach(column => {
  147. if (
  148. column.defaultDisabled ||
  149. (typeof column.className === 'string' &&
  150. column.className.includes(anotherAirportNodeFlag))
  151. ) {
  152. column.checkDisabled = true
  153. if (activeNodes.includes(column.columnName)) {
  154. column.hidden = false
  155. } else {
  156. column.hidden = true
  157. }
  158. }
  159. })
  160. })
  161. useLoop([getWaybillInfo, getTableData], 'waybill')
  162. const { trackAirlines, trackBoxStyle } = useTrackData(props.name, trackData)
  163. const tableData = computed(() => {
  164. const mergedTableData = trackData.value.reduce(
  165. (data: CommonData[], current) => {
  166. const sameRow = data.find(row =>
  167. ['flightNO', 'flightDate', 'cargoSN'].every(
  168. key => row[key] === current[key]
  169. )
  170. )
  171. const {
  172. stockCode,
  173. flightNO,
  174. flightDate,
  175. departureAirport, // 装载机场
  176. arriveAirport, // 卸载机场
  177. ULDNO,
  178. cargoSN,
  179. pullMark,
  180. returnMark,
  181. // transMark,
  182. exceptionCustomsMark,
  183. execPosition, // 读取位置
  184. nodeCode, // 节点名称
  185. ConsignmentItemPackagingQuantityQuantity, // 跟踪节点件数
  186. execResult,
  187. execTime,
  188. } = current
  189. const nodeValue = `${execPosition ?? ''}\n${
  190. execResult ? '通过' : '未通过'
  191. }\n${execTime ?? ''}`
  192. if (sameRow) {
  193. sameRow[String(nodeCode)] = nodeValue
  194. ;[
  195. 'ULDNO',
  196. // 'cargoSN'
  197. ].forEach(key => {
  198. const oldValue = sameRow[key]
  199. const currentValue = current[key]
  200. if (typeof currentValue === 'string' && currentValue !== oldValue) {
  201. if (typeof oldValue === 'string') {
  202. sameRow[key] = [
  203. ...new Set([
  204. ...oldValue.split(','),
  205. ...currentValue.split(','),
  206. ]),
  207. ].join(',')
  208. } else {
  209. sameRow[key] = currentValue
  210. }
  211. }
  212. })
  213. ;['pullMark', 'returnMark'].forEach(key => {
  214. sameRow[key] = sameRow[key] ?? current[key]
  215. })
  216. } else {
  217. data.push({
  218. ...current,
  219. [String(nodeCode)]: nodeValue,
  220. })
  221. }
  222. return data
  223. },
  224. []
  225. )
  226. return mergedTableData.reduce((data: CommonData[], current) => {
  227. const { cargoSN } = current
  228. if (typeof cargoSN === 'string') {
  229. const splitedRows = cargoSN.split(',').map(splitedCargoSN => ({
  230. ...current,
  231. cargoSN: splitedCargoSN,
  232. }))
  233. data.push(...splitedRows)
  234. } else {
  235. data.push(current)
  236. }
  237. return data
  238. }, [])
  239. })
  240. const formatter: CommonTableFormatter = (row, column, cellValue, index) => {
  241. const value = String(cellValue ?? '').split('\n')
  242. if (value[2]) {
  243. value[2] = datetimeToTime(value[2], flightDate as CommonValue)
  244. }
  245. return value.join('\n')
  246. }
  247. const search = (text: string) => {
  248. console.log(text)
  249. }
  250. const clear = () => {}
  251. const tableRef = ref<InstanceType<typeof SimpleTable> | null>(null)
  252. const { exportToExcel } = useTableExport()
  253. const exportHandler = () => {
  254. const table = tableRef.value!.table!
  255. exportToExcel({ table })
  256. }
  257. const { columnChecked } = useTableColumnSet(tableColumns)
  258. const { rowClass, cellClass } = useTableStyle(`${props.name}Goods`)
  259. const { cellClickHandler } = useTableCellClick(`${props.name}Goods`)
  260. </script>
  261. <style lang="scss" scoped>
  262. .waybill {
  263. height: 100%;
  264. display: flex;
  265. flex-direction: column;
  266. &-info {
  267. height: 144px;
  268. background: #410425;
  269. padding: 24px 30px;
  270. color: #ffffff;
  271. &-title {
  272. font-size: 18px;
  273. font-family: Microsoft YaHei;
  274. font-weight: bold;
  275. margin-bottom: 40px;
  276. }
  277. &-item {
  278. display: flex;
  279. .el-tooltip__trigger {
  280. max-width: 300px;
  281. overflow: hidden;
  282. white-space: nowrap;
  283. text-overflow: ellipsis;
  284. }
  285. }
  286. }
  287. &-header :deep {
  288. margin: 24px 0;
  289. line-height: 32px;
  290. .status {
  291. font-size: 16px;
  292. font-family: Microsoft YaHei;
  293. font-weight: bold;
  294. color: #519f6b;
  295. }
  296. .el-button {
  297. // background-color: #d5327b;
  298. border: none;
  299. }
  300. .button-sqaure {
  301. width: 30px;
  302. height: 30px;
  303. border-radius: 4px;
  304. font-size: 16px;
  305. margin-left: 24px;
  306. &:first-of-type {
  307. margin-left: 19px;
  308. }
  309. }
  310. }
  311. &-track {
  312. height: 0;
  313. flex: 1.5;
  314. &-row {
  315. height: 208px;
  316. display: flex;
  317. &:not(:last-child) {
  318. margin-bottom: 8px;
  319. }
  320. }
  321. &-box {
  322. background: #ffffff;
  323. padding: 24px 24px 12px 24px;
  324. &:not(:last-child) {
  325. margin-right: 8px;
  326. }
  327. .title {
  328. font-size: 16px;
  329. font-family: Microsoft YaHei;
  330. font-weight: bold;
  331. color: #101116;
  332. margin-bottom: 10px;
  333. &-span:not(:last-of-type) {
  334. margin-right: 8px;
  335. }
  336. }
  337. }
  338. }
  339. .goods-list :deep {
  340. margin-top: 16px;
  341. height: 0;
  342. flex: 1;
  343. .el-table__body .el-table__cell .cell {
  344. padding: 4px 8px;
  345. }
  346. }
  347. }
  348. </style>