| | |
| | | import { Page, useVbenModal } from "@vben/common-ui"; |
| | | import { downloadFileFromBlobPart } from "@vben/utils"; |
| | | |
| | | import { message } from "ant-design-vue"; |
| | | import { message, Modal, Tag } from "ant-design-vue"; |
| | | |
| | | import { ACTION_ICON, TableAction, useVbenVxeGrid } from "#/adapter/vxe-table"; |
| | | import { |
| | | deletePallet, |
| | | exportPalletExcel, |
| | | exportPalletQr, |
| | | exportPalletQrByIds, |
| | | getPalletPage, |
| | | } from "#/api/mes/pro/pallet"; |
| | | import { $t } from "#/locales"; |
| | | |
| | | import { useGridColumns, useGridFormSchema } from "./data"; |
| | | import BindBatchModal from "./modules/bind-batch.vue"; |
| | | import GenerateModal from "./modules/generate-form.vue"; |
| | | import QrTraceModal from "../components/qr-trace-modal.vue"; |
| | | |
| | |
| | | |
| | | const [GenerateFormModal, generateFormModalApi] = useVbenModal({ |
| | | connectedComponent: GenerateModal, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | const [BindBatchFormModal, bindBatchFormModalApi] = useVbenModal({ |
| | | connectedComponent: BindBatchModal, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | |
| | | gridApi.query(); |
| | | } |
| | | |
| | | /** 批量生成托盘码 */ |
| | | /** 批量预生成托盘码 */ |
| | | function handleCreate() { |
| | | generateFormModalApi.open(); |
| | | } |
| | | |
| | | /** 预生成成功:展示生成的临时托盘码 */ |
| | | function handlePreGenerateSuccess(result: { id: number; tempCode: string }[]) { |
| | | Modal.success({ |
| | | title: "预生成临时托盘码成功", |
| | | content: result.map((item) => item.tempCode).join("\n"), |
| | | centered: true, |
| | | }); |
| | | } |
| | | |
| | | /** 扫码追溯 */ |
| | |
| | | qrTraceQueryModalApi.open(); |
| | | } |
| | | |
| | | /** 查看二维码(行内预填码值) */ |
| | | /** 获取托盘显示用的码值(正式托盘码优先,其次临时托盘码) */ |
| | | function getDisplayCode(row: MesProPalletApi.Pallet) { |
| | | return row.code || row.tempCode || ""; |
| | | } |
| | | |
| | | /** 查看二维码(行内预填码值,临时托盘用临时托盘码) */ |
| | | function handleViewQr(row: MesProPalletApi.Pallet) { |
| | | qrTraceQueryModalApi.setData({ code: row.code }).open(); |
| | | qrTraceQueryModalApi.setData({ code: getDisplayCode(row) }).open(); |
| | | } |
| | | |
| | | /** 获取勾选的临时托盘记录 */ |
| | | function getSelectedTempPallets(): MesProPalletApi.Pallet[] | undefined { |
| | | const records = [ |
| | | ...(gridApi.grid.getCheckboxReserveRecords?.() ?? []), |
| | | ...(gridApi.grid.getCheckboxRecords?.() ?? []), |
| | | ] as MesProPalletApi.Pallet[]; |
| | | const uniqueRecords = [ |
| | | ...new Map(records.map((record) => [record.id, record])).values(), |
| | | ]; |
| | | const tempRecords = uniqueRecords.filter((record) => !record.batchId); |
| | | if (uniqueRecords.length === 0) { |
| | | message.warning("请至少勾选一条托盘码记录"); |
| | | return undefined; |
| | | } |
| | | if (tempRecords.length === 0) { |
| | | message.warning("勾选的记录均已绑定批次,无需绑定"); |
| | | return undefined; |
| | | } |
| | | return tempRecords; |
| | | } |
| | | |
| | | /** 绑定批次 */ |
| | | function handleBindBatch() { |
| | | const records = getSelectedTempPallets(); |
| | | if (!records) return; |
| | | bindBatchFormModalApi |
| | | .setData({ ids: records.map((record) => record.id!) }) |
| | | .open(); |
| | | } |
| | | |
| | | /** 导出二维码 ZIP(按当前查询条件的批次) */ |
| | |
| | | downloadFileFromBlobPart({ fileName: "托盘码二维码.zip", source: data }); |
| | | } |
| | | |
| | | /** 导出单个托盘码二维码 ZIP(支持未绑定批次的临时托盘) */ |
| | | async function handleExportQrById(row: MesProPalletApi.Pallet) { |
| | | const data = await exportPalletQrByIds([row.id!]); |
| | | downloadFileFromBlobPart({ |
| | | fileName: `托盘码二维码-${getDisplayCode(row)}.zip`, |
| | | source: data, |
| | | }); |
| | | } |
| | | |
| | | /** 删除托盘码 */ |
| | | async function handleDelete(row: MesProPalletApi.Pallet) { |
| | | await deletePallet(row.id!); |
| | | message.success($t("ui.actionMessage.deleteSuccess", [row.code])); |
| | | message.success($t("ui.actionMessage.deleteSuccess", [getDisplayCode(row)])); |
| | | handleRefresh(); |
| | | } |
| | | |
| | |
| | | schema: useGridFormSchema(), |
| | | }, |
| | | gridOptions: { |
| | | checkboxConfig: { |
| | | highlight: true, |
| | | reserve: true, |
| | | }, |
| | | columns: useGridColumns(), |
| | | height: "auto", |
| | | keepSource: true, |
| | |
| | | |
| | | <template> |
| | | <Page auto-content-height> |
| | | <GenerateFormModal @success="handleRefresh" /> |
| | | <GenerateFormModal @success="handlePreGenerateSuccess" /> |
| | | <BindBatchFormModal @success="handleRefresh" /> |
| | | <QrTraceQueryModal /> |
| | | <Grid table-title="托盘码列表"> |
| | | <template #toolbar-tools> |
| | | <TableAction :actions="[ |
| | | { |
| | | label: '批量生成', |
| | | label: '预生成二维码', |
| | | type: 'primary', |
| | | icon: ACTION_ICON.ADD, |
| | | auth: ['mes:pro-pallet:create'], |
| | | onClick: handleCreate, |
| | | }, |
| | | { |
| | | label: '绑定批次', |
| | | icon: ACTION_ICON.EDIT, |
| | | auth: ['mes:pro-pallet:update'], |
| | | onClick: handleBindBatch, |
| | | }, |
| | | { |
| | | label: '扫码追溯', |
| | |
| | | }, |
| | | ]" /> |
| | | </template> |
| | | <template #code="{ row }"> |
| | | <span>{{ getDisplayCode(row) }}</span> |
| | | <Tag v-if="!row.code" color="warning">未绑定批次</Tag> |
| | | </template> |
| | | <template #batchCode="{ row }"> |
| | | <span v-if="row.batchCode">{{ row.batchCode }}</span> |
| | | <Tag v-else color="warning">未绑定批次</Tag> |
| | | </template> |
| | | <template #actions="{ row }"> |
| | | <TableAction :actions="[ |
| | | { |
| | |
| | | onClick: handleViewQr.bind(null, row), |
| | | }, |
| | | { |
| | | label: '导出二维码', |
| | | type: 'link', |
| | | icon: ACTION_ICON.DOWNLOAD, |
| | | auth: ['mes:pro-pallet:export'], |
| | | onClick: handleExportQrById.bind(null, row), |
| | | }, |
| | | { |
| | | label: $t('common.delete'), |
| | | type: 'link', |
| | | danger: true, |
| | |
| | | auth: ['mes:pro-pallet:delete'], |
| | | ifShow: !row.bagCount, |
| | | popConfirm: { |
| | | title: $t('ui.actionMessage.deleteConfirm', [row.code]), |
| | | title: $t('ui.actionMessage.deleteConfirm', [getDisplayCode(row)]), |
| | | confirm: handleDelete.bind(null, row), |
| | | }, |
| | | }, |