refactor(物料管理): 优化API调用链式处理并统一错误处理

重构物料管理相关页面的API调用,使用链式Promise处理替代原有嵌套方式
统一添加finally处理隐藏加载状态,确保加载状态正确关闭
移除调试用的console.log语句,保持代码整洁
This commit is contained in:
赵正易 2025-08-06 17:23:14 +08:00
parent 8fc9532f4b
commit dda9b03e44
2 changed files with 120 additions and 101 deletions

View File

@ -105,20 +105,22 @@ export default {
methods: { methods: {
// 线 // 线
getLineOptions() { getLineOptions() {
getLineOptions().then(res => { getLineOptions()
if (res.code === 200 && res.data) { .then(res => {
// 线uni-data-select if (res.code === 200 && res.data) {
this.lineOptions = res.data.map(item => ({ // 线uni-data-select
text: item.groupName, // this.lineOptions = res.data.map(item => ({
value: item.groupCode // text: item.groupName, //
})); value: item.groupCode //
} else { }));
} else {
this.$modal.showToast('获取线体数据失败');
}
})
.catch(err => {
console.error('获取线体数据失败', err);
this.$modal.showToast('获取线体数据失败'); this.$modal.showToast('获取线体数据失败');
} });
}).catch(err => {
console.error('获取线体数据失败', err);
this.$modal.showToast('获取线体数据失败');
});
}, },
// MRP // MRP
@ -142,21 +144,24 @@ export default {
}); });
// APIMRP // APIMRP
queryCallMaterialMRPList(params).then(res => { queryCallMaterialMRPList(params)
uni.hideLoading(); .then(res => {
if (res.code === 200 && res.data) { if (res.code === 200 && res.data) {
this.mrpList = res.data.result; this.mrpList = res.data.result;
console.log('MRP数据:', res.data.result); //console.log('MRP:', res.data.result);
} else { } else {
this.mrpList = [];
this.$modal.showToast(res.message || '获取MRP数据失败');
}
})
.catch(err => {
console.error('获取MRP数据失败', err);
this.mrpList = []; this.mrpList = [];
this.$modal.showToast(res.message || '获取MRP数据失败'); this.$modal.showToast('获取MRP数据失败');
} })
}).catch(err => { .finally(() => {
uni.hideLoading(); uni.hideLoading();
console.error('获取MRP数据失败', err); });
this.mrpList = [];
this.$modal.showToast('获取MRP数据失败');
});
}, },
@ -195,26 +200,29 @@ export default {
}); });
// API // API
doLineCallMaterial(params).then(res => { doLineCallMaterial(params)
uni.hideLoading(); .then(res => {
if (res.code === 200) { if (res.code === 200) {
this.$modal.showToast(`成功叫料 ${quantity}${this.currentMaterial.materialName}`); this.$modal.showToast(`成功叫料 ${quantity}${this.currentMaterial.materialName}`);
// //
this.currentMaterial.quantity -= quantity; this.currentMaterial.quantity -= quantity;
// 0 // 0
if (this.currentMaterial.quantity <= 0) { if (this.currentMaterial.quantity <= 0) {
this.mrpList = this.mrpList.filter(m => m.id !== this.currentMaterial.id); this.mrpList = this.mrpList.filter(m => m.id !== this.currentMaterial.id);
}
//
this.$refs.popup.close();
} else {
this.$modal.showToast(res.message || '叫料失败');
} }
// })
this.$refs.popup.close(); .catch(err => {
} else { console.error('叫料失败', err);
this.$modal.showToast(res.message || '叫料失败'); this.$modal.showToast('叫料失败');
} })
}).catch(err => { .finally(() => {
uni.hideLoading(); uni.hideLoading();
console.error('叫料失败', err); });
this.$modal.showToast('叫料失败');
});
}, },
// //

View File

@ -75,20 +75,22 @@ export default {
methods: { methods: {
// 线 // 线
getLineOptions() { getLineOptions() {
getLineOptions().then(res => { getLineOptions()
if (res.code === 200 && res.data) { .then(res => {
// 线uni-data-select if (res.code === 200 && res.data) {
this.lineOptions = res.data.map(item => ({ // 线uni-data-select
text: item.groupName, // this.lineOptions = res.data.map(item => ({
value: item.groupCode // text: item.groupName, //
})); value: item.groupCode //
} else { }));
} else {
this.$modal.showToast('获取线体数据失败');
}
})
.catch(err => {
console.error('获取线体数据失败', err);
this.$modal.showToast('获取线体数据失败'); this.$modal.showToast('获取线体数据失败');
} });
}).catch(err => {
console.error('获取线体数据失败', err);
this.$modal.showToast('获取线体数据失败');
});
}, },
// //
@ -112,21 +114,24 @@ export default {
}); });
// API // API
queryCallReceiveList(params).then(res => { queryCallReceiveList(params)
uni.hideLoading(); .then(res => {
if (res.code === 200 && res.data) { if (res.code === 200 && res.data) {
this.receiveList = res.data.result; this.receiveList = res.data.result;
console.log('收料数据:', res.data.result); //console.log(':', res.data.result);
} else { } else {
this.receiveList = [];
this.$modal.showToast(res.message || '获取收料数据失败');
}
})
.catch(err => {
console.error('获取收料数据失败', err);
this.receiveList = []; this.receiveList = [];
this.$modal.showToast(res.message || '获取收料数据失败'); this.$modal.showToast('获取收料数据失败');
} })
}).catch(err => { .finally(() => {
uni.hideLoading(); uni.hideLoading();
console.error('获取收料数据失败', err); });
this.receiveList = [];
this.$modal.showToast('获取收料数据失败');
});
}, },
// //
@ -155,20 +160,23 @@ export default {
}); });
// API // API
doLineReceiveMaterial(params).then(res => { doLineReceiveMaterial(params)
uni.hideLoading(); .then(res => {
if (res.code === 200) { if (res.code === 200) {
this.$modal.showToast(`成功收料 ${item.waitingQuantity}${item.materialName}`); this.$modal.showToast(`成功收料 ${item.quantity}${item.materialName}`);
// //
this.getReceiveList(); this.getReceiveList();
} else { } else {
this.$modal.showToast(res.message || '收料失败'); this.$modal.showToast(res.message || '收料失败');
} }
}).catch(err => { })
uni.hideLoading(); .catch(err => {
console.error('收料失败', err); console.error('收料失败', err);
this.$modal.showToast('收料失败'); this.$modal.showToast('收料失败');
}); })
.finally(() => {
uni.hideLoading();
});
} }
} }
}); });
@ -200,20 +208,23 @@ export default {
}); });
// 退API // 退API
doLineReturnBackMaterial(params).then(res => { doLineReturnBackMaterial(params)
uni.hideLoading(); .then(res => {
if (res.code === 200) { if (res.code === 200) {
this.$modal.showToast(`成功退料 ${item.waitingQuantity}${item.materialName}`); this.$modal.showToast(`成功退料 ${item.quantity}${item.materialName}`);
// //
this.getReceiveList(); this.getReceiveList();
} else { } else {
this.$modal.showToast(res.message || '退料失败'); this.$modal.showToast(res.message || '退料失败');
} }
}).catch(err => { })
uni.hideLoading(); .catch(err => {
console.error('退料失败', err); console.error('退料失败', err);
this.$modal.showToast('退料失败'); this.$modal.showToast('退料失败');
}); })
.finally(() => {
uni.hideLoading();
});
} }
} }
}); });