gaoluyang
2 天以前 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmSnApi } from '#/api/mes/wm/sn';
 
import { nextTick, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
import { BarcodeBizTypeEnum } from '@vben/constants';
 
import { message } from 'ant-design-vue';
 
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSnListByUuid } from '#/api/mes/wm/sn';
import { BarcodeDetail } from '#/views/wls/barcode/components';
 
import { useDetailGridColumns } from '../data';
 
defineOptions({ name: 'WlsSnDetail' });
 
const barcodeDetailRef = ref<InstanceType<typeof BarcodeDetail>>();
 
/** 查看 SN 码条码 */
function handleBarcode(row: MesWmSnApi.Sn) {
  if (!row.id) {
    message.warning('缺少 SN 码编号,无法查看条码');
    return;
  }
  barcodeDetailRef.value?.openByBusiness(
    row.id,
    BarcodeBizTypeEnum.SN,
    row.code,
    row.itemName || row.code,
  );
}
 
/** 加载 SN 码明细 */
async function loadDetail(row?: MesWmSnApi.SnGroup) {
  if (!row?.uuid) {
    await gridApi.grid?.loadData([]);
    return;
  }
  gridApi.setLoading(true);
  try {
    const list = await getSnListByUuid(row.uuid);
    await gridApi.grid?.loadData(list);
  } finally {
    gridApi.setLoading(false);
  }
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns: useDetailGridColumns(),
    height: 520,
    pagerConfig: {
      enabled: false,
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions<MesWmSnApi.Sn>,
});
 
const [Modal, modalApi] = useVbenModal({
  showCancelButton: false,
  showConfirmButton: false,
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      await gridApi.grid?.loadData([]);
      return;
    }
    await nextTick();
    await loadDetail(modalApi.getData<MesWmSnApi.SnGroup>());
  },
});
</script>
 
<template>
  <Modal class="w-3/5" title="SN 码明细">
    <Grid class="mx-4">
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: '条码',
              type: 'link',
              auth: ['mes:wm-sn:query'],
              onClick: handleBarcode.bind(null, row),
            },
          ]"
        />
      </template>
    </Grid>
    <BarcodeDetail ref="barcodeDetailRef" />
  </Modal>
</template>