diff --git a/src/views/wms/linkage/index.vue b/src/views/wms/linkage/index.vue index b85b259..fad999d 100644 --- a/src/views/wms/linkage/index.vue +++ b/src/views/wms/linkage/index.vue @@ -18,17 +18,10 @@ 新增 - 删除 - - - @@ -39,8 +32,6 @@ - @@ -60,18 +51,6 @@ - @@ -79,9 +58,9 @@ - - - + + 查看 + @@ -115,18 +94,12 @@ - + - - 创建任务 - - - 删除任务 + 分包打印 查看任务 @@ -143,6 +116,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 平均分包 + 自定义每包数量 + + + + + + + + 第{{index + 1}}包: + {{qty}}个 + + + 总计:{{allocateAverageTotal}} / {{allocateOrderQty}} + - 必须分配完所有调拨数量 + + + + + + + + + 第{{index + 1}}包: + + + + 总计:{{allocateTotalPackageQty}} / {{allocateOrderQty}} + - 必须分配完所有调拨数量 + + + + + + + + + + + + + @@ -689,10 +742,6 @@ const partntTableSelectCell = ref({}) // 打印相关变量 const printDialogVisible = ref(false) -const taskDialogVisible = ref(false) -const editTaskDialogVisible = ref(false) -const taskList = ref([]) -const currentTasksMap = ref(new Map()) // 存储各个调拨明细的任务列表 const printForm = ref({ aoDId: null, allocateCode: '', @@ -704,12 +753,50 @@ const printForm = ref({ printCopies: 1, packageQtyList: [] }) + + +// 调拨分包打印相关变量 +const allocatePrintDialogVisible = ref(false) +const taskDialogVisible = ref(false) +const editTaskDialogVisible = ref(false) +const taskList = ref([]) +const currentTasksMap = ref(new Map()) // 存储各个调拨明细的任务列表 +const allocatePrintForm = ref({ + aoDId: null, + allocateCode: '', + materialCode: '', + materialName: '', + allocateOrderQty: 0, + outSum: 0, + printedQty: 0, + splitPackageCount: 1, + printCopies: 1, + packageQtyList: [] +}) const editTaskForm = ref({ allocateTaskId: null, batchCode: '', materialQty: 1 }) +// 调拨分包相关的响应式数据 +const allocatePackageQtyList = ref([]) +const allocatePackageMode = ref('average') // 分包模式:'average' 或 'custom' +const allocateTotalPackageQty = computed(() => { + return allocatePackageQtyList.value.reduce((sum, qty) => sum + (Number(qty) || 0), 0) +}) + +// 平均分包的数量列表和总数 +const allocateAveragePackageList = ref([]) +const allocateAverageTotal = computed(() => { + return allocateAveragePackageList.value.reduce((sum, qty) => sum + (Number(qty) || 0), 0) +}) + +// 调拨数量(用于分包计算) +const allocateOrderQty = computed(() => { + return Number(allocatePrintForm.value.allocateOrderQty) || 0 +}) + // 获取仓库 let baseStoreList = ref([]); getBaseWarehouseList(null).then(e => { @@ -1208,18 +1295,6 @@ const childrenTablePrint = async (row) => { } } -/** 查看任务按钮点击事件 */ -const viewPrintTasks = async (row) => { - try { - const result = await queryTasksByDetailId(row.aoDId); - taskList.value = result.data || []; - taskDialogVisible.value = true; - } catch (error) { - console.error('查询任务错误:', error); - ElMessage.error('查询任务失败'); - } -} - /** 打印模式变化事件 */ const onPrintModeChange = () => { if (printForm.value.printMode === 'package') { @@ -1313,54 +1388,7 @@ const deleteAllTasks = async (row) => { } } -/** 任务打印按钮点击 */ -const handleTaskPrint = async (task) => { - try { - await triggerPrint(task.allocateTaskId); - ElMessage.success('打印成功'); - } catch (error) { - console.error('打印错误:', error); - ElMessage.error('打印失败:' + ((error as any).response?.data?.msg || (error as any).message || '未知错误')); - } -} -/** 任务编辑按钮点击 */ -const handleTaskEdit = (task) => { - editTaskForm.value = { - allocateTaskId: task.allocateTaskId, - batchCode: task.batchCode, - materialQty: task.materialQty - }; - editTaskDialogVisible.value = true; -} - -/** 任务更新 */ -const handleTaskUpdate = async () => { - try { - if (!editTaskForm.value.batchCode) { - ElMessage.error('请输入批次码'); - return; - } - if (!editTaskForm.value.materialQty || editTaskForm.value.materialQty <= 0) { - ElMessage.error('请输入正确的数量'); - return; - } - - await updateTaskBarcode(editTaskForm.value); - ElMessage.success('修改成功'); - editTaskDialogVisible.value = false; - - // 刷新任务列表 - const currentDetailId = taskList.value[0]?.aoDId; - if (currentDetailId) { - const result = await queryTasksByDetailId(currentDetailId); - taskList.value = result.data || []; - } - } catch (error) { - console.error('修改任务错误:', error); - ElMessage.error('修改失败:' + ((error as any).response?.data?.msg || (error as any).message || '未知错误')); - } -} const handlePrintSubmit = async () => { try { if (!isValidPackage.value) { @@ -1414,6 +1442,202 @@ const canDelete = (row) => { // outSum是double类型,allocateOrderQty是BigDecimal类型,需要进行数值比较 return Number(row.outSum) === Number(row.allocateOrderQty); } + +/** 判断是否可以打印 */ +const canPrint = (row) => { + // 只有出库数量等于调拨数量时才能打印 + return Number(row.outSum) === Number(row.allocateOrderQty); +} + +/** 调拨分包打印按钮点击事件 */ +const handleAllocatePrint = (row) => { + // 检查打印条件 + if (!canPrint(row)) { + ElMessage.error(`只有出库数量等于调拨数量时才能打印,当前出库数量:${row.outSum},调拨数量:${row.allocateOrderQty}`); + return; + } + + // 初始化打印表单 + allocatePrintForm.value = { + aoDId: row.aoDId, + allocateCode: row.allocateCode, + materialCode: row.materialCode, + materialName: row.materialName || '', + allocateOrderQty: Number(row.allocateOrderQty), + outSum: Number(row.outSum), + printedQty: Number(row.printedQty || 0), + splitPackageCount: 1, + printCopies: 1, + packageQtyList: [] + }; + + allocatePrintDialogVisible.value = true; +} + +/** 分包数量变化时的处理函数 */ +const onAllocateSplitPackageCountChange = (count) => { + if (count > 1) { + // 默认使用平均分包模式 + allocatePackageMode.value = 'average' + + // 初始化数组 + allocatePackageQtyList.value = new Array(count).fill(1) + allocateAveragePackageList.value = new Array(count).fill(1) + + // 计算平均分包 + calculateAllocateAveragePackage(count) + + // 同时初始化自定义数量为平均值(作为备用) + allocatePackageQtyList.value = [...allocateAveragePackageList.value] + } else { + allocatePackageQtyList.value = [] + allocateAveragePackageList.value = [] + allocatePackageMode.value = 'average' + } +} + +/** 计算平均分包数量 */ +const calculateAllocateAveragePackage = (count) => { + const totalQty = allocateOrderQty.value // 使用调拨数量 + if (totalQty > 0 && count > 0) { + const avgQty = Math.floor(totalQty / count) + const remainder = totalQty % count + + allocateAveragePackageList.value = [] + for (let i = 0; i < count; i++) { + // 前面的包分配 avgQty + 1(如果有余数),后面的包分配 avgQty + allocateAveragePackageList.value[i] = avgQty + (i < remainder ? 1 : 0) + } + } +} + +/** 分包模式变化时的处理 */ +const onAllocatePackageModeChange = (mode) => { + if (mode === 'custom') { + // 切换到自定义模式时,使用平均分包的结果作为初始值 + allocatePackageQtyList.value = [...allocateAveragePackageList.value] + } + // 切换到平均模式时不需要特殊处理,因为平均值已经计算好了 +} + +/** 验证总数量是否超出限制 */ +const validateAllocateTotalQty = () => { + const total = allocateTotalPackageQty.value + const totalQty = allocateOrderQty.value + + if (total > totalQty) { + ElMessage.warning(`每包数量总计不能超过调拨数量 ${totalQty}`) + } + + // 分包数量大于1时,必须分配完所有调拨数量 + if (allocatePrintForm.value.splitPackageCount > 1 && total !== totalQty) { + ElMessage.warning(`分包数量大于1时,每包数量总计必须等于调拨数量 ${totalQty}`) + } +} + +/** 计算属性:验证分包是否有效 */ +const isValidAllocatePackage = computed(() => { + if (allocatePrintForm.value.splitPackageCount === 1) { + return allocatePrintForm.value.printCopies > 0; + } else { + return allocateAverageTotal.value === allocateOrderQty.value && + allocateAveragePackageList.value.every(qty => Number(qty) > 0); + } +}) + +/** 提交调拨分包打印 */ +const submitAllocatePrintForm = async () => { + try { + if (!isValidAllocatePackage.value) { + ElMessage.error('请正确设置打印参数'); + return; + } + + const params = { + aoDId: allocatePrintForm.value.aoDId, + allocateCode: allocatePrintForm.value.allocateCode, + splitPackageCount: allocatePrintForm.value.splitPackageCount, + printCopies: allocatePrintForm.value.printCopies || 1, + packageQtyList: allocatePrintForm.value.splitPackageCount > 1 + ? (allocatePackageMode.value === 'average' ? allocateAveragePackageList.value : allocatePackageQtyList.value) + : null + }; + + await allocatePackagePrint(params); + ElMessage.success('分包打印成功'); + allocatePrintDialogVisible.value = false; + + // 刷新子表数据 + if (partntTableSelectCell.value?.allocateOrderCode) { + await getChildrenTable({allocateCode: partntTableSelectCell.value.allocateOrderCode}); + } + } catch (error) { + console.error('分包打印错误:', error); + ElMessage.error('分包打印失败:' + ((error as any).response?.data?.msg || (error as any).message || '未知错误')); + } +} + +/** 查看任务按钮点击事件 */ +const viewPrintTasks = async (row) => { + try { + const result = await queryTasksByDetailId(row.aoDId); + taskList.value = result.data || []; + taskDialogVisible.value = true; + } catch (error) { + console.error('查询任务错误:', error); + ElMessage.error('查询任务失败'); + } +} + +/** 任务打印按钮点击 */ +const handleTaskPrint = async (task) => { + try { + await triggerPrint(task.allocateTaskId); + ElMessage.success('打印成功'); + } catch (error) { + console.error('打印错误:', error); + ElMessage.error('打印失败:' + ((error as any).response?.data?.msg || (error as any).message || '未知错误')); + } +} + +/** 任务编辑按钮点击 */ +const handleTaskEdit = (task) => { + editTaskForm.value = { + allocateTaskId: task.allocateTaskId, + batchCode: task.batchCode, + materialQty: task.materialQty + }; + editTaskDialogVisible.value = true; +} + +/** 任务更新 */ +const handleTaskUpdate = async () => { + try { + if (!editTaskForm.value.batchCode) { + ElMessage.error('请输入批次码'); + return; + } + if (!editTaskForm.value.materialQty || editTaskForm.value.materialQty <= 0) { + ElMessage.error('请输入正确的数量'); + return; + } + + await updateTaskBarcode(editTaskForm.value); + ElMessage.success('修改成功'); + editTaskDialogVisible.value = false; + + // 刷新任务列表 + const currentDetailId = taskList.value[0]?.aoDId; + if (currentDetailId) { + const result = await queryTasksByDetailId(currentDetailId); + taskList.value = result.data || []; + } + } catch (error) { + console.error('修改任务错误:', error); + ElMessage.error('修改失败:' + ((error as any).response?.data?.msg || (error as any).message || '未知错误')); + } +} +