fix(outWarehouse): 修复出库单完成按钮禁用逻辑并简化提交流程
修复出库单完成按钮禁用条件,当还有库存未出库时禁用按钮 简化出库单完成处理逻辑,直接调用完成接口而非先提交再完成
This commit is contained in:
@@ -65,7 +65,7 @@
|
|||||||
<view class="button-box">
|
<view class="button-box">
|
||||||
<u-button style="width: 40%" type="primary" @click="handlerDoOut" :disabled="loading || isOutboundDisabled"
|
<u-button style="width: 40%" type="primary" @click="handlerDoOut" :disabled="loading || isOutboundDisabled"
|
||||||
:loading="loading">货物出库</u-button>
|
:loading="loading">货物出库</u-button>
|
||||||
<u-button style="width: 40%" type="success" @click="handlerSubmit" :disabled="loading"
|
<u-button style="width: 40%" type="success" @click="handlerSubmit" :disabled="loading || isCompleteOrderDisabled"
|
||||||
:loading="loading">出库单完成</u-button>
|
:loading="loading">出库单完成</u-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -180,6 +180,16 @@ export default {
|
|||||||
// 当历史出库数大于等于计划出库数时,禁用按钮
|
// 当历史出库数大于等于计划出库数时,禁用按钮
|
||||||
return this.actualOutPackage >= this.passedPlanData.planOutPackage ||
|
return this.actualOutPackage >= this.passedPlanData.planOutPackage ||
|
||||||
this.actualOutNumber >= this.passedPlanData.planOutNumber;
|
this.actualOutNumber >= this.passedPlanData.planOutNumber;
|
||||||
|
},
|
||||||
|
// 判断是否应该禁用出库单完成按钮
|
||||||
|
isCompleteOrderDisabled() {
|
||||||
|
// 如果没有传递计划数据,则禁用
|
||||||
|
if (!this.passedPlanData) return true;
|
||||||
|
|
||||||
|
// 当还有库存未出库时,禁用按钮
|
||||||
|
// 即当历史出库数小于计划出库数时,禁用按钮
|
||||||
|
return this.actualOutPackage < this.passedPlanData.planOutPackage &&
|
||||||
|
this.actualOutNumber < this.passedPlanData.planOutNumber;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -587,148 +597,40 @@ export default {
|
|||||||
},
|
},
|
||||||
// 出库单完成
|
// 出库单完成
|
||||||
handlerSubmit() {
|
handlerSubmit() {
|
||||||
const length = this.newMaterialList.length;
|
// 直接调用出库单完成接口
|
||||||
|
const outInfo = this.outInfo;
|
||||||
// 性能优化:提前返回
|
|
||||||
if (length === 0) {
|
|
||||||
uni.showModal({
|
|
||||||
title: '提示',
|
|
||||||
content: '当前未扫描货物!',
|
|
||||||
showCancel: false,
|
|
||||||
confirmText: '确定'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 显示确认对话框
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '操作',
|
title: '操作',
|
||||||
content: `当前已扫描:${length}箱货物,是否确认提交出库单?`,
|
content: '是否确认完成此出库单?',
|
||||||
showCancel: true,
|
showCancel: true,
|
||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
confirmText: '确认提交',
|
confirmText: '确认完成',
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
// 构造提交数据
|
// 调用出库单完成接口
|
||||||
const packageCodeList = [];
|
completeOutOrder(outInfo.shipmentNum).then((completeRes) => {
|
||||||
|
if (completeRes.code !== 200 || !completeRes.data) {
|
||||||
// 性能优化:缓存常用值
|
console.error('出库单完成失败:', completeRes.msg || '');
|
||||||
const subsectionCurrent = this.subsectionCurrent;
|
this.showSubmitError();
|
||||||
const newMaterialList = this.newMaterialList;
|
} else {
|
||||||
|
this.showSubmitSuccess();
|
||||||
if (subsectionCurrent === 0) {
|
// 重新获取实际出库数据
|
||||||
packageCodeList.push(newMaterialList[0].patchCode);
|
this.getActualOutData();
|
||||||
} else if (subsectionCurrent === 1) {
|
// 跳转到出库单列表页面
|
||||||
// 提取货物patchCode
|
uni.redirectTo({
|
||||||
// 性能优化:使用更高效的数组方法
|
url: '/pages/outWarehouse/outboundList'
|
||||||
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: '请求失败,请重试!'
|
|
||||||
});
|
});
|
||||||
this.loading = false;
|
}
|
||||||
// this.logInfo(`提交请求失败: ${error.message}`);
|
}).catch((error) => {
|
||||||
});
|
console.error('出库单完成请求失败:', error);
|
||||||
};
|
this.showSubmitError();
|
||||||
|
}).finally(() => {
|
||||||
// 使用防抖函数避免重复提交
|
this.loading = false;
|
||||||
const debouncedSubmit = debounce(submitOrder, 1000);
|
});
|
||||||
|
|
||||||
// 调用防抖函数
|
|
||||||
debouncedSubmit();
|
|
||||||
} else {
|
|
||||||
this.loading = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user