| | |
| | | import { MesProBagCodeStatusEnum } from "@vben/constants"; |
| | | import { downloadFileFromBlobPart } from "@vben/utils"; |
| | | |
| | | import { message } from "ant-design-vue"; |
| | | import { message, Modal } from "ant-design-vue"; |
| | | |
| | | import { ACTION_ICON, TableAction, useVbenVxeGrid } from "#/adapter/vxe-table"; |
| | | import { |
| | |
| | | import { useGridColumns, useGridFormSchema } from "./data"; |
| | | import BindPalletModal from "./modules/bind-pallet.vue"; |
| | | import GenerateModal from "./modules/generate-form.vue"; |
| | | import ReplaceModal from "./modules/replace-form.vue"; |
| | | import QrTraceModal from "../components/qr-trace-modal.vue"; |
| | | |
| | | defineOptions({ name: "MesProBagCode" }); |
| | |
| | | |
| | | const [BindPalletFormModal, bindPalletFormModalApi] = useVbenModal({ |
| | | connectedComponent: BindPalletModal, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | | const [ReplaceFormModal, replaceFormModalApi] = useVbenModal({ |
| | | connectedComponent: ReplaceModal, |
| | | destroyOnClose: true, |
| | | }); |
| | | |
| | |
| | | /** 生成数据包 */ |
| | | function handleGenerate() { |
| | | generateFormModalApi.open(); |
| | | } |
| | | |
| | | /** 替换成功后展示结果并刷新列表 */ |
| | | function handleReplaceSuccess(result: MesProBagCodeApi.ReplaceResult) { |
| | | showReplaceResult(result); |
| | | handleRefresh(); |
| | | } |
| | | |
| | | /** 扫码追溯 */ |
| | |
| | | |
| | | /** 获取勾选的袋码记录 */ |
| | | function getSelectedRecords(): MesProBagCodeApi.BagCode[] | undefined { |
| | | const records = gridApi.grid.getCheckboxRecords() as MesProBagCodeApi.BagCode[]; |
| | | if (records.length === 0) { |
| | | const records = [ |
| | | ...(gridApi.grid.getCheckboxReserveRecords?.() ?? []), |
| | | ...(gridApi.grid.getCheckboxRecords?.() ?? []), |
| | | ] as MesProBagCodeApi.BagCode[]; |
| | | const uniqueRecords = [ |
| | | ...new Map(records.map((record) => [record.id, record])).values(), |
| | | ]; |
| | | if (uniqueRecords.length === 0) { |
| | | message.warning("请至少勾选一条袋码记录"); |
| | | return undefined; |
| | | } |
| | | return records; |
| | | return uniqueRecords; |
| | | } |
| | | |
| | | /** 展示替换结果 */ |
| | | function showReplaceResult(result: MesProBagCodeApi.ReplaceResult) { |
| | | const items = result.items ?? []; |
| | | const content = items.length |
| | | ? items |
| | | .map( |
| | | (item) => |
| | | `${item.oldCode ?? "-"} → ${item.newCode ?? "-"}${ |
| | | item.newPalletCode ? `(托盘:${item.newPalletCode})` : "" |
| | | }`, |
| | | ) |
| | | .join("\n") |
| | | : "替换明细暂无"; |
| | | Modal.success({ |
| | | title: "破损袋码替换成功", |
| | | content: `批次:${result.batchCode ?? "-"}\n替换数量:${ |
| | | result.count ?? items.length |
| | | }\n${content}`, |
| | | centered: true, |
| | | }); |
| | | } |
| | | |
| | | /** 批量替换破损袋码 */ |
| | | async function handleReplace() { |
| | | const records = getSelectedRecords(); |
| | | if (!records) return; |
| | | if (records.length > 200) { |
| | | message.warning("单次最多替换 200 个袋码"); |
| | | return; |
| | | } |
| | | const batchIds = new Set(records.map((record) => record.batchId)); |
| | | if (batchIds.size > 1 || !records[0]?.batchId) { |
| | | message.warning("请选择同一批次下的袋码进行替换"); |
| | | return; |
| | | } |
| | | if ( |
| | | records.some( |
| | | (record) => |
| | | record.status !== MesProBagCodeStatusEnum.GENERATED && |
| | | record.status !== MesProBagCodeStatusEnum.PRINTED, |
| | | ) |
| | | ) { |
| | | message.warning("仅已生成或已导出印刷的袋码允许替换"); |
| | | return; |
| | | } |
| | | if (records.some((record) => !record.id)) { |
| | | message.warning("所选袋码缺少编号,无法替换"); |
| | | return; |
| | | } |
| | | try { |
| | | await confirm(`确认作废所选 ${records.length} 个袋码并生成等量新码吗?`); |
| | | } catch { |
| | | return; |
| | | } |
| | | const first = records[0]!; |
| | | replaceFormModalApi |
| | | .setData({ |
| | | batchId: first.batchId!, |
| | | batchCode: first.batchCode, |
| | | ids: records.map((record) => record.id!), |
| | | }) |
| | | .open(); |
| | | } |
| | | |
| | | /** 批量绑定托盘 */ |
| | |
| | | <Page auto-content-height> |
| | | <GenerateFormModal @success="handleRefresh" /> |
| | | <BindPalletFormModal @success="handleRefresh" /> |
| | | <ReplaceFormModal @success="handleReplaceSuccess" /> |
| | | <QrTraceQueryModal /> |
| | | <Grid table-title="袋码列表(一袋一码)"> |
| | | <template #toolbar-tools> |
| | |
| | | onClick: handleBindPallet, |
| | | }, |
| | | { |
| | | label: '破损替换', |
| | | type: 'primary', |
| | | auth: ['mes:pro-bag-code:replace'], |
| | | onClick: handleReplace, |
| | | }, |
| | | { |
| | | label: '解绑托盘', |
| | | auth: ['mes:pro-bag-code:update'], |
| | | onClick: handleUnbindPallet, |