useGoodsInfo.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { CommonData, CommonValue } from '~/common'
  2. import { Query } from '@/api/webApi'
  3. import { ElMessage } from 'element-plus'
  4. const goodsInfoItemsMap = {
  5. internal: [
  6. {
  7. label: '货物编码',
  8. key: 'C0',
  9. },
  10. {
  11. label: '运单',
  12. key: 'C1',
  13. },
  14. ],
  15. international: [
  16. {
  17. label: '货物编码',
  18. key: 'C0',
  19. },
  20. {
  21. label: '运单',
  22. key: 'C1',
  23. },
  24. {
  25. label: '运单类型',
  26. key: 'C2',
  27. },
  28. ],
  29. }
  30. const simulateGoodsInfoMap = {
  31. internal: {
  32. C0: '56888829',
  33. C1: 'FA67858990',
  34. },
  35. international: {
  36. C0: '56888829',
  37. C1: 'FA67858990',
  38. C2: '国际普货',
  39. },
  40. }
  41. export default function useGoodsInfo(name: string, dataContent: CommonValue[]) {
  42. const goodsInfoItems = ref<{ label: string; key: string }[]>([])
  43. const getGoodsInfoItems = () => {
  44. goodsInfoItems.value =
  45. goodsInfoItemsMap[
  46. name.includes('International') ? 'international' : 'internal'
  47. ]
  48. }
  49. getGoodsInfoItems()
  50. const goodsInfo = reactive<CommonData>({})
  51. const getGoodsInfo = async () => {
  52. try {
  53. const {
  54. code,
  55. returnData: { listValues },
  56. message,
  57. } = await Query<CommonData>({
  58. id: DATACONTENT_ID.goodsInfo,
  59. dataContent,
  60. })
  61. if (Number(code) !== 0) {
  62. throw new Error(message || '失败')
  63. }
  64. if (!listValues.length) {
  65. ElMessage.error('未查询到货物信息')
  66. return
  67. }
  68. Object.assign(goodsInfo, listValues[0])
  69. } catch (error) {
  70. console.error(error)
  71. }
  72. }
  73. const getSimulateGoodsInfo = () => {
  74. const simulateGoodsInfo =
  75. simulateGoodsInfoMap[
  76. name.includes('International') ? 'international' : 'internal'
  77. ]
  78. Object.assign(goodsInfo, simulateGoodsInfo)
  79. }
  80. onMounted(() => {
  81. // getGoodsInfo()
  82. getSimulateGoodsInfo()
  83. })
  84. return {
  85. goodsInfoItems,
  86. goodsInfo,
  87. }
  88. }