2 天以前 1c1af9b0fc10778ae5ac13cc68fd4030affbcfe1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<script lang="ts" setup>
import type { MesWmSnApi } from '#/api/mes/wm/sn';
 
import { computed, ref } from 'vue';
 
import { Button, Empty, Input, message, Modal } from 'ant-design-vue';
 
import { getSnDetail } from '#/api/mes/wm/sn';
import { useDescription } from '#/components/description';
 
import { useSnDetailSchema } from '../data';
import { formatWmLocation, getWmLocationMaps } from '../location-maps';
 
defineOptions({ name: 'WlsSnDetailModal' });
 
const open = ref(false);
const code = ref('');
const detail = ref<MesWmSnApi.SnDetail>();
const loading = ref(false);
const locationMaps = ref<Awaited<ReturnType<typeof getWmLocationMaps>>>();
 
const locationText = computed(() =>
  detail.value
    ? formatWmLocation(
        locationMaps.value ?? {
          warehouseNameMap: {},
          locationNameMap: {},
          areaNameMap: {},
        },
        detail.value.warehouseId,
        detail.value.locationId,
        detail.value.areaId,
      )
    : '-',
);
 
const lastTransactionText = computed(() => {
  const d = detail.value;
  if (!d) {
    return '-';
  }
  const direction = d.lastTransactionTypeName || '';
  const quantity = d.lastTransactionQuantity ?? '';
  const bizCode = d.lastTransactionBizCode || '-';
  return [direction, quantity, bizCode].filter(Boolean).join(' ');
});
 
async function loadDetail(snCode: string) {
  loading.value = true;
  try {
    detail.value = await getSnDetail(snCode);
    if (!locationMaps.value) {
      locationMaps.value = await getWmLocationMaps();
    }
  } finally {
    loading.value = false;
  }
}
 
async function handleQuery() {
  if (!code.value?.trim()) {
    message.warning('请输入或扫码获取 SN 码');
    return;
  }
  await loadDetail(code.value.trim());
}
 
function openModal(snCode?: string) {
  open.value = true;
  code.value = snCode ?? '';
  detail.value = undefined;
  if (snCode) {
    void loadDetail(snCode);
  }
}
 
defineExpose({ open: openModal });
 
const [Descriptions] = useDescription({
  bordered: true,
  column: 1,
  schema: useSnDetailSchema(),
  useCard: false,
  labelStyle: { width: '80px', whiteSpace: 'nowrap' },
});
</script>
 
<template>
  <Modal v-model:open="open" title="SN 码单件详情" width="720px">
    <div class="flex gap-2">
      <Input
        v-model:value="code"
        placeholder="输入或扫码 SN 码后查询"
        @press-enter="handleQuery"
      />
      <Button type="primary" :loading="loading" @click="handleQuery">
        查询
      </Button>
    </div>
    <div class="mt-4">
      <Descriptions v-if="detail" :data="detail">
        <template #location>
          {{ locationText }}
        </template>
        <template #lastTransaction>
          {{ lastTransactionText }}
        </template>
      </Descriptions>
      <Empty
        v-else
        :description="loading ? '查询中...' : '暂无数据,请输入 SN 码查询'"
      />
    </div>
    <template #footer>
      <Button @click="open = false">关闭</Button>
    </template>
  </Modal>
</template>