1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { CommonData, CommonValue } from '~/common'
- import { Query } from '@/api/webApi'
- import { ElMessage } from 'element-plus'
- const goodsInfoItemsMap = {
- internal: [
- {
- label: '货物编码',
- key: 'C0',
- },
- {
- label: '运单',
- key: 'C1',
- },
- ],
- international: [
- {
- label: '货物编码',
- key: 'C0',
- },
- {
- label: '运单',
- key: 'C1',
- },
- {
- label: '运单类型',
- key: 'C2',
- },
- ],
- }
- const simulateGoodsInfoMap = {
- internal: {
- C0: '56888829',
- C1: 'FA67858990',
- },
- international: {
- C0: '56888829',
- C1: 'FA67858990',
- C2: '国际普货',
- },
- }
- export default function useGoodsInfo(name: string, dataContent: CommonValue[]) {
- const goodsInfoItems = ref<{ label: string; key: string }[]>([])
- const getGoodsInfoItems = () => {
- goodsInfoItems.value =
- goodsInfoItemsMap[
- name.includes('International') ? 'international' : 'internal'
- ]
- }
- getGoodsInfoItems()
- const goodsInfo = reactive<CommonData>({})
- const getGoodsInfo = async () => {
- try {
- const {
- code,
- returnData: { listValues },
- message,
- } = await Query<CommonData>({
- id: DATACONTENT_ID.goodsInfo,
- dataContent,
- })
- if (Number(code) !== 0) {
- throw new Error(message || '失败')
- }
- if (!listValues.length) {
- ElMessage.error('未查询到货物信息')
- return
- }
- Object.assign(goodsInfo, listValues[0])
- } catch (error) {
- console.error(error)
- }
- }
- const getSimulateGoodsInfo = () => {
- const simulateGoodsInfo =
- simulateGoodsInfoMap[
- name.includes('International') ? 'international' : 'internal'
- ]
- Object.assign(goodsInfo, simulateGoodsInfo)
- }
- onMounted(() => {
- // getGoodsInfo()
- getSimulateGoodsInfo()
- })
- return {
- goodsInfoItems,
- goodsInfo,
- }
- }
|