refactor(物料管理): 优化API调用链式处理并统一错误处理
重构物料管理相关页面的API调用,使用链式Promise处理替代原有嵌套方式 统一添加finally处理隐藏加载状态,确保加载状态正确关闭 移除调试用的console.log语句,保持代码整洁
This commit is contained in:
parent
8fc9532f4b
commit
dda9b03e44
@ -105,7 +105,8 @@ export default {
|
||||
methods: {
|
||||
// 获取线体数据
|
||||
getLineOptions() {
|
||||
getLineOptions().then(res => {
|
||||
getLineOptions()
|
||||
.then(res => {
|
||||
if (res.code === 200 && res.data) {
|
||||
// 格式化线体数据为uni-data-select需要的格式
|
||||
this.lineOptions = res.data.map(item => ({
|
||||
@ -115,7 +116,8 @@ export default {
|
||||
} else {
|
||||
this.$modal.showToast('获取线体数据失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取线体数据失败', err);
|
||||
this.$modal.showToast('获取线体数据失败');
|
||||
});
|
||||
@ -142,20 +144,23 @@ export default {
|
||||
});
|
||||
|
||||
// 调用API获取MRP清单
|
||||
queryCallMaterialMRPList(params).then(res => {
|
||||
uni.hideLoading();
|
||||
queryCallMaterialMRPList(params)
|
||||
.then(res => {
|
||||
if (res.code === 200 && res.data) {
|
||||
this.mrpList = res.data.result;
|
||||
console.log('MRP数据:', res.data.result);
|
||||
//console.log('MRP数据:', res.data.result);
|
||||
} else {
|
||||
this.mrpList = [];
|
||||
this.$modal.showToast(res.message || '获取MRP数据失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取MRP数据失败', err);
|
||||
this.mrpList = [];
|
||||
this.$modal.showToast('获取MRP数据失败');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
},
|
||||
|
||||
@ -195,8 +200,8 @@ export default {
|
||||
});
|
||||
|
||||
// 调用叫料API
|
||||
doLineCallMaterial(params).then(res => {
|
||||
uni.hideLoading();
|
||||
doLineCallMaterial(params)
|
||||
.then(res => {
|
||||
if (res.code === 200) {
|
||||
this.$modal.showToast(`成功叫料 ${quantity} 个 ${this.currentMaterial.materialName}`);
|
||||
// 更新物料数量
|
||||
@ -210,10 +215,13 @@ export default {
|
||||
} else {
|
||||
this.$modal.showToast(res.message || '叫料失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('叫料失败', err);
|
||||
this.$modal.showToast('叫料失败');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -75,7 +75,8 @@ export default {
|
||||
methods: {
|
||||
// 获取线体数据
|
||||
getLineOptions() {
|
||||
getLineOptions().then(res => {
|
||||
getLineOptions()
|
||||
.then(res => {
|
||||
if (res.code === 200 && res.data) {
|
||||
// 格式化线体数据为uni-data-select需要的格式
|
||||
this.lineOptions = res.data.map(item => ({
|
||||
@ -85,7 +86,8 @@ export default {
|
||||
} else {
|
||||
this.$modal.showToast('获取线体数据失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取线体数据失败', err);
|
||||
this.$modal.showToast('获取线体数据失败');
|
||||
});
|
||||
@ -112,20 +114,23 @@ export default {
|
||||
});
|
||||
|
||||
// 调用API获取收料清单
|
||||
queryCallReceiveList(params).then(res => {
|
||||
uni.hideLoading();
|
||||
queryCallReceiveList(params)
|
||||
.then(res => {
|
||||
if (res.code === 200 && res.data) {
|
||||
this.receiveList = res.data.result;
|
||||
console.log('收料数据:', res.data.result);
|
||||
//console.log('收料数据:', res.data.result);
|
||||
} else {
|
||||
this.receiveList = [];
|
||||
this.$modal.showToast(res.message || '获取收料数据失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取收料数据失败', err);
|
||||
this.receiveList = [];
|
||||
this.$modal.showToast('获取收料数据失败');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
},
|
||||
|
||||
@ -155,19 +160,22 @@ export default {
|
||||
});
|
||||
|
||||
// 调用收料API
|
||||
doLineReceiveMaterial(params).then(res => {
|
||||
uni.hideLoading();
|
||||
doLineReceiveMaterial(params)
|
||||
.then(res => {
|
||||
if (res.code === 200) {
|
||||
this.$modal.showToast(`成功收料 ${item.waitingQuantity} 个 ${item.materialName}`);
|
||||
this.$modal.showToast(`成功收料 ${item.quantity} 个 ${item.materialName}`);
|
||||
// 刷新收料清单
|
||||
this.getReceiveList();
|
||||
} else {
|
||||
this.$modal.showToast(res.message || '收料失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('收料失败', err);
|
||||
this.$modal.showToast('收料失败');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -200,19 +208,22 @@ export default {
|
||||
});
|
||||
|
||||
// 调用退料API
|
||||
doLineReturnBackMaterial(params).then(res => {
|
||||
uni.hideLoading();
|
||||
doLineReturnBackMaterial(params)
|
||||
.then(res => {
|
||||
if (res.code === 200) {
|
||||
this.$modal.showToast(`成功退料 ${item.waitingQuantity} 个 ${item.materialName}`);
|
||||
this.$modal.showToast(`成功退料 ${item.quantity} 个 ${item.materialName}`);
|
||||
// 刷新收料清单
|
||||
this.getReceiveList();
|
||||
} else {
|
||||
this.$modal.showToast(res.message || '退料失败');
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.hideLoading();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('退料失败', err);
|
||||
this.$modal.showToast('退料失败');
|
||||
})
|
||||
.finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user