useWaybillInfo.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { CommonData, CommonValue } from '~/common'
  2. import { Query } from '@/api/webApi'
  3. import { ElMessage } from 'element-plus'
  4. const waybillInfoItemsMap = {
  5. internal: [
  6. {
  7. label: '运单',
  8. key: 'stockCode',
  9. },
  10. {
  11. label: '货代公司',
  12. key: 'cargoCompany',
  13. },
  14. {
  15. label: '品名',
  16. key: 'typeCode',
  17. },
  18. {
  19. label: '特货信息',
  20. key: 'speCargoInfo',
  21. },
  22. {
  23. label: '始发机场',
  24. key: 'departureAirport',
  25. },
  26. {
  27. label: '目的机场',
  28. key: 'arriveAirport',
  29. },
  30. {
  31. label: '货物数量',
  32. key: 'luggageCount',
  33. },
  34. {
  35. label: '货物总重',
  36. key: 'weight',
  37. },
  38. ],
  39. international: [
  40. {
  41. label: '运单',
  42. key: 'stockCode,',
  43. },
  44. {
  45. label: '运单类型',
  46. key: 'stockType,',
  47. },
  48. {
  49. label: '货代公司',
  50. key: 'cargoCompany,',
  51. },
  52. {
  53. label: '品名',
  54. key: 'typeCode,',
  55. },
  56. {
  57. label: '特货信息',
  58. key: 'speCargoInfo,',
  59. },
  60. {
  61. label: '始发机场',
  62. key: 'departureAirport,',
  63. },
  64. {
  65. label: '目的机场',
  66. key: 'arriveAirport,',
  67. },
  68. ],
  69. }
  70. const simulateWaybillInfoMap = {
  71. internal: {
  72. C0: 'FA56888829',
  73. C1: '深圳市联运通货有限公司',
  74. C3: '电路板、手机外壳',
  75. C4: '特',
  76. C5: 'SZX',
  77. C6: 'NKG',
  78. C7: '7件',
  79. C8: '82KG',
  80. },
  81. international: {
  82. C0: 'FA56888829',
  83. C1: '国际普货',
  84. C2: '深圳市联运通货有限公司',
  85. C3: '电路板、手机外壳',
  86. C4: '特',
  87. C5: 'SZX',
  88. C6: 'NKG',
  89. },
  90. }
  91. export function useWaybillInfo(name: string, dataContent: CommonValue[]) {
  92. const waybillInfoItems = ref<
  93. { label: string; key?: string; getter?: (info: any) => string }[]
  94. >([])
  95. const getWaybillInfoItems = () => {
  96. waybillInfoItems.value =
  97. waybillInfoItemsMap[
  98. name.includes('International') ? 'international' : 'internal'
  99. ]
  100. }
  101. getWaybillInfoItems()
  102. const waybillInfo = reactive<CommonData>({})
  103. const getWaybillInfo = async () => {
  104. try {
  105. const {
  106. code,
  107. returnData: { listValues },
  108. message,
  109. } = await Query<CommonData>({
  110. id: DATACONTENT_ID.waybillInfo,
  111. dataContent,
  112. })
  113. if (Number(code) !== 0) {
  114. throw new Error(message || '失败')
  115. }
  116. if (!listValues.length) {
  117. ElMessage.info('未查询到运单信息')
  118. return
  119. }
  120. Object.assign(waybillInfo, listValues[0])
  121. } catch (error) {
  122. console.error(error)
  123. }
  124. }
  125. const computedWaybillInfo = computed(() => item => {
  126. if (item.getter) {
  127. return item.getter(waybillInfo)
  128. } else if (item.key) {
  129. return waybillInfo[item.key]
  130. } else {
  131. return ''
  132. }
  133. })
  134. const getSimulateWaybillInfo = () => {
  135. const simulateWaybillInfo =
  136. simulateWaybillInfoMap[
  137. name.includes('International') ? 'international' : 'internal'
  138. ]
  139. Object.assign(waybillInfo, simulateWaybillInfo)
  140. }
  141. onMounted(() => {
  142. getWaybillInfo()
  143. // getSimulateWaybillInfo()
  144. })
  145. return {
  146. waybillInfoItems,
  147. waybillInfo,
  148. computedWaybillInfo,
  149. }
  150. }