From 8565ab55431c06fcc3010be8aaf499b1801b01f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AD=A3=E6=98=93?= Date: Sun, 24 Aug 2025 18:31:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(outWarehouse):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=87=BA=E5=BA=93=E5=8D=95=E5=AE=8C=E6=88=90=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E9=80=BB=E8=BE=91=E5=B9=B6=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复出库单完成按钮禁用条件,当还有库存未出库时禁用按钮 简化出库单完成处理逻辑,直接调用完成接口而非先提交再完成 --- pages/outWarehouse/outWarehouseV2.vue | 172 ++++++-------------------- 1 file changed, 37 insertions(+), 135 deletions(-) diff --git a/pages/outWarehouse/outWarehouseV2.vue b/pages/outWarehouse/outWarehouseV2.vue index 3722978..5ee93b0 100644 --- a/pages/outWarehouse/outWarehouseV2.vue +++ b/pages/outWarehouse/outWarehouseV2.vue @@ -65,7 +65,7 @@ 货物出库 - 出库单完成 @@ -180,6 +180,16 @@ export default { // 当历史出库数大于等于计划出库数时,禁用按钮 return this.actualOutPackage >= this.passedPlanData.planOutPackage || this.actualOutNumber >= this.passedPlanData.planOutNumber; + }, + // 判断是否应该禁用出库单完成按钮 + isCompleteOrderDisabled() { + // 如果没有传递计划数据,则禁用 + if (!this.passedPlanData) return true; + + // 当还有库存未出库时,禁用按钮 + // 即当历史出库数小于计划出库数时,禁用按钮 + return this.actualOutPackage < this.passedPlanData.planOutPackage && + this.actualOutNumber < this.passedPlanData.planOutNumber; } }, methods: { @@ -587,148 +597,40 @@ export default { }, // 出库单完成 handlerSubmit() { - const length = this.newMaterialList.length; - - // 性能优化:提前返回 - if (length === 0) { - uni.showModal({ - title: '提示', - content: '当前未扫描货物!', - showCancel: false, - confirmText: '确定' - }); - return; - } - + // 直接调用出库单完成接口 + const outInfo = this.outInfo; + + // 显示确认对话框 uni.showModal({ title: '操作', - content: `当前已扫描:${length}箱货物,是否确认提交出库单?`, + content: '是否确认完成此出库单?', showCancel: true, cancelText: '取消', - confirmText: '确认提交', + confirmText: '确认完成', success: (res) => { if (res.confirm) { this.loading = true; - - // 构造提交数据 - const packageCodeList = []; - - // 性能优化:缓存常用值 - const subsectionCurrent = this.subsectionCurrent; - const newMaterialList = this.newMaterialList; - - if (subsectionCurrent === 0) { - packageCodeList.push(newMaterialList[0].patchCode); - } else if (subsectionCurrent === 1) { - // 提取货物patchCode - // 性能优化:使用更高效的数组方法 - const hasInvalidCode = newMaterialList.some(item => { - if (!item.patchCode) { - this.showBoxDataError(item.originalCode); - this.loading = false; - return true; - } - packageCodeList.push(item.patchCode); - return false; - }); - - // 如果发现无效代码,直接返回 - if (hasInvalidCode) { - return; - } - } - - // 性能优化:提前检查 - if (packageCodeList.length === 0) { - uni.showModal({ - title: '提示', - content: '无出库箱,不可提交!', - showCancel: false, - confirmText: '确认' - }); - this.loading = false; - return; - } - - // 从store获取操作员信息 - const userName = this.$store.getters.name; - const operator = userName && userName !== '' ? userName : 'PDA出库'; - - // 性能优化:缓存常用值 - const outInfo = this.outInfo; - const materialId = this.material_id; - const passedPlanData = this.passedPlanData; - const quantityTotal = this.quantityTotal; - - // 构造提交数据 - const submitData = { - shipmentNum: outInfo.shipmentNum, - materialCode: materialId, - batchCode: passedPlanData ? passedPlanData.batchCode : '', - currentOutPackage: newMaterialList.length, - currentOutNumber: quantityTotal, - planOutPackage: passedPlanData ? passedPlanData.planOutPackage : 0, - planOutNumber: passedPlanData ? passedPlanData.planOutNumber : 0, - packageCodeList: packageCodeList, - operator: operator - }; - - // 定义提交函数 - const submitOrder = () => { - // 添加日志以便调试 - // this.logInfo(`开始提交: ${JSON.stringify(submitData)}`); - - pdaOutboundByOutOrderPlan(submitData).then((res) => { - if (res.code !== 200) { - this.showOutError('提交异常: ' + (res.msg || '')); - this.loading = false; - // this.logInfo(`提交失败: ${res.msg || ''}`); - return; - } else { - // 提交成功 - this.showOutSuccess(res.data || length); - this.newMaterialList = []; - this.loading = false; - // this.logInfo('提交成功'); - - // 调用出库单完成接口 - completeOutOrder(outInfo.shipmentNum).then((completeRes) => { - if (completeRes.code !== 200 || !completeRes.data) { - console.error('出库单完成失败:', completeRes.msg || ''); - // this.logInfo(`出库单完成失败: ${completeRes.msg || ''}`); - } else { - // this.logInfo('出库单完成成功'); - // 重新获取实际出库数据 - this.getActualOutData(); - } - }).catch((error) => { - console.error('出库单完成请求失败:', error); - // this.logInfo(`出库单完成请求失败: ${error.message}`); - }); - - // 跳转到出库单列表页面 - uni.redirectTo({ - url: '/pages/outWarehouse/outboundList' - }); - } - }).catch((error) => { - // 处理请求失败的情况,确保loading状态被重置 - console.error('提交请求失败:', error); - uni.showToast({ - title: '请求失败,请重试!' + + // 调用出库单完成接口 + completeOutOrder(outInfo.shipmentNum).then((completeRes) => { + if (completeRes.code !== 200 || !completeRes.data) { + console.error('出库单完成失败:', completeRes.msg || ''); + this.showSubmitError(); + } else { + this.showSubmitSuccess(); + // 重新获取实际出库数据 + this.getActualOutData(); + // 跳转到出库单列表页面 + uni.redirectTo({ + url: '/pages/outWarehouse/outboundList' }); - this.loading = false; - // this.logInfo(`提交请求失败: ${error.message}`); - }); - }; - - // 使用防抖函数避免重复提交 - const debouncedSubmit = debounce(submitOrder, 1000); - - // 调用防抖函数 - debouncedSubmit(); - } else { - this.loading = false; + } + }).catch((error) => { + console.error('出库单完成请求失败:', error); + this.showSubmitError(); + }).finally(() => { + this.loading = false; + }); } } });