| | |
| | | <script lang="ts" setup> |
| | | import type { VxeTableGridOptions } from '#/adapter/vxe-table'; |
| | | import type { MesWmBarcodeApi } from '#/api/mes/wm/barcode'; |
| | | import type { MesWmBatchApi } from '#/api/mes/wm/batch'; |
| | | |
| | | import { ref } from 'vue'; |
| | | import { useRouter } from 'vue-router'; |
| | | |
| | | import { Page, useVbenModal } from '@vben/common-ui'; |
| | | import { BarcodeBizTypeEnum } from '@vben/constants'; |
| | | import { downloadFileFromBlobPart } from '@vben/utils'; |
| | | |
| | | import { message } from 'ant-design-vue'; |
| | |
| | | exportBarcode, |
| | | getBarcodePage, |
| | | } from '#/api/mes/wm/barcode'; |
| | | import { getBatchBySn, getBatchPage } from '#/api/mes/wm/batch'; |
| | | import { $t } from '#/locales'; |
| | | import TraceDetail from '#/views/mes/qc/batchtrace/modules/trace-detail.vue'; |
| | | |
| | | import { Barcode, BarcodeDetail, ScanModal } from './components'; |
| | | import { useGridColumns, useGridFormSchema } from './data'; |
| | |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | const [TraceModal, traceModalApi] = useVbenModal({ |
| | | connectedComponent: TraceDetail, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | const barcodeDetailRef = ref<InstanceType<typeof BarcodeDetail>>(); |
| | | const scanModalRef = ref<InstanceType<typeof ScanModal>>(); |
| | | |
| | | /** 扫码解析 / 成图预览 */ |
| | | function handleScan() { |
| | | scanModalRef.value?.open(); |
| | | } |
| | | |
| | | /** 条码对应的批次/SN是否支持全链路追溯 */ |
| | | function isTraceable(row: Partial<MesWmBarcodeApi.Barcode>) { |
| | | return [BarcodeBizTypeEnum.BATCH, BarcodeBizTypeEnum.SN].includes( |
| | | row.bizType as BarcodeBizTypeEnum, |
| | | ); |
| | | } |
| | | |
| | | /** 从批次码或 SN 码进入采购、生产、质量、销售全链路追溯 */ |
| | | async function handleTrace(row: Partial<MesWmBarcodeApi.Barcode>) { |
| | | if (!isTraceable(row)) { |
| | | message.warning('当前仅支持批次码和 SN 码进行全链路追溯'); |
| | | return; |
| | | } |
| | | |
| | | let batch: MesWmBatchApi.Batch | null | undefined; |
| | | if (row.bizType === BarcodeBizTypeEnum.SN) { |
| | | const sn = row.bizCode || row.content; |
| | | batch = sn ? await getBatchBySn(sn) : undefined; |
| | | } else { |
| | | const batchCode = row.bizCode || row.content; |
| | | if (batchCode) { |
| | | const page = await getBatchPage({ |
| | | code: batchCode, |
| | | pageNo: 1, |
| | | pageSize: 20, |
| | | }); |
| | | batch = page.list.find((item) => item.code === batchCode); |
| | | } |
| | | } |
| | | |
| | | if (!batch) { |
| | | message.warning('未找到该条码对应的批次数据'); |
| | | return; |
| | | } |
| | | traceModalApi.setData(batch).open(); |
| | | } |
| | | |
| | | const checkedIds = ref<number[]>([]); |
| | |
| | | |
| | | /** 跳转条码配置 */ |
| | | function handleConfig() { |
| | | router.push({ path: '/wls/barcode/config' }); |
| | | router.push({ path: '/mes/wm/barcode/config' }); |
| | | } |
| | | |
| | | /** 打开完整批次追溯清单 */ |
| | | function handleTraceCenter() { |
| | | router.push({ path: '/mes/qc/batch-trace' }); |
| | | } |
| | | |
| | | /** 导出表格 */ |
| | |
| | | </script> |
| | | |
| | | <template> |
| | | <Page auto-content-height><FormModal @success="handleRefresh" /> |
| | | <Page auto-content-height> |
| | | <FormModal @success="handleRefresh" /> |
| | | <TraceModal /> |
| | | <BarcodeDetail ref="barcodeDetailRef" /> |
| | | <ScanModal ref="scanModalRef" /> |
| | | <ScanModal ref="scanModalRef" @trace="handleTrace" /> |
| | | |
| | | <Grid table-title="条码列表"> |
| | | <template #toolbar-tools> |
| | |
| | | onClick: handleConfig, |
| | | }, |
| | | { |
| | | label: '全链路追溯', |
| | | type: 'primary', |
| | | icon: ACTION_ICON.VIEW, |
| | | auth: ['mes:wm-batch:query'], |
| | | onClick: handleTraceCenter, |
| | | }, |
| | | { |
| | | label: $t('ui.actionTitle.export'), |
| | | type: 'primary', |
| | | icon: ACTION_ICON.DOWNLOAD, |
| | |
| | | onClick: handleView.bind(null, row), |
| | | }, |
| | | { |
| | | label: '追溯', |
| | | type: 'link', |
| | | icon: ACTION_ICON.VIEW, |
| | | auth: ['mes:wm-batch:query'], |
| | | ifShow: isTraceable(row), |
| | | onClick: handleTrace.bind(null, row), |
| | | }, |
| | | { |
| | | label: $t('common.edit'), |
| | | type: 'link', |
| | | icon: ACTION_ICON.EDIT, |