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; + }); } } });