index.vue 11 KB

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