123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import { CommonData, CommonValue } from '~/common'
- import { Query } from '@/api/webApi'
- import { ElMessage } from 'element-plus'
- const waybillInfoItemsMap = {
- internal: [
- {
- label: '运单',
- key: 'stockCode',
- },
- {
- label: '货代公司',
- key: 'cargoCompany',
- },
- {
- label: '品名',
- key: 'typeCode',
- },
- {
- label: '特货信息',
- key: 'speCargoInfo',
- },
- {
- label: '始发机场',
- key: 'departureAirport',
- },
- {
- label: '目的机场',
- key: 'arriveAirport',
- },
- {
- label: '货物数量',
- key: 'luggageCount',
- },
- {
- label: '货物总重',
- key: 'weight',
- },
- ],
- international: [
- {
- label: '运单',
- key: 'stockCode,',
- },
- {
- label: '运单类型',
- key: 'stockType,',
- },
- {
- label: '货代公司',
- key: 'cargoCompany,',
- },
- {
- label: '品名',
- key: 'typeCode,',
- },
- {
- label: '特货信息',
- key: 'speCargoInfo,',
- },
- {
- label: '始发机场',
- key: 'departureAirport,',
- },
- {
- label: '目的机场',
- key: 'arriveAirport,',
- },
- ],
- }
- const simulateWaybillInfoMap = {
- internal: {
- C0: 'FA56888829',
- C1: '深圳市联运通货有限公司',
- C3: '电路板、手机外壳',
- C4: '特',
- C5: 'SZX',
- C6: 'NKG',
- C7: '7件',
- C8: '82KG',
- },
- international: {
- C0: 'FA56888829',
- C1: '国际普货',
- C2: '深圳市联运通货有限公司',
- C3: '电路板、手机外壳',
- C4: '特',
- C5: 'SZX',
- C6: 'NKG',
- },
- }
- export function useWaybillInfo(name: string, dataContent: CommonValue[]) {
- const waybillInfoItems = ref<
- { label: string; key?: string; getter?: (info: any) => string }[]
- >([])
- const getWaybillInfoItems = () => {
- waybillInfoItems.value =
- waybillInfoItemsMap[
- name.includes('International') ? 'international' : 'internal'
- ]
- }
- getWaybillInfoItems()
- const waybillInfo = reactive<CommonData>({})
- const getWaybillInfo = async () => {
- try {
- const {
- code,
- returnData: { listValues },
- message,
- } = await Query<CommonData>({
- id: DATACONTENT_ID.waybillInfo,
- dataContent,
- })
- if (Number(code) !== 0) {
- throw new Error(message || '失败')
- }
- if (!listValues.length) {
- ElMessage.info('未查询到运单信息')
- return
- }
- Object.assign(waybillInfo, listValues[0])
- } catch (error) {
- console.error(error)
- }
- }
- const computedWaybillInfo = computed(() => item => {
- if (item.getter) {
- return item.getter(waybillInfo)
- } else if (item.key) {
- return waybillInfo[item.key]
- } else {
- return ''
- }
- })
- const getSimulateWaybillInfo = () => {
- const simulateWaybillInfo =
- simulateWaybillInfoMap[
- name.includes('International') ? 'international' : 'internal'
- ]
- Object.assign(waybillInfo, simulateWaybillInfo)
- }
- onMounted(() => {
- getWaybillInfo()
- // getSimulateWaybillInfo()
- })
- return {
- waybillInfoItems,
- waybillInfo,
- computedWaybillInfo,
- }
- }
|