Commit a937c331 by chenwq

refactor(调拨新增): 提取保存操作为独立方法

将原 saveAllocate 方法中的 API 调用和结果处理逻辑提取为独立的 saveApi 方法,简化主方法逻辑。现在 save 操作直接调用 saveApi,而审核和作废操作仍保留确认弹窗后再调用。提高代码复用性和可维护性。
1 parent cb682dc6
...@@ -618,6 +618,37 @@ export default { ...@@ -618,6 +618,37 @@ export default {
}) })
}, },
saveApi(params, btnType = 'save') {
const tipTxtObj = {
save: '保存成功',
review: '提交审核成功',
invalid: '作废成功'
}
this.loading = true
this.$apis.stockManage[this.routeInfo.id ? 'updateStockAllocate' : 'saveStockAllocate'](params)
.then(res => {
this.$notify({
type: res.code == 0 ? 'success' : 'error',
title: res.code == 0 ? (tipTxtObj[btnType] || '操作成功') : res.message
})
if (res.code == 0) {
if (btnType == 'save') {
this.routeInfo.allocateCode = res.data
this.oprType = 'edit'
this.editFirst = true
this.editMerFirst = true
// this.isDisabled = true
this.getDetail()
} else {
this.handleAddClose()
}
}
})
.finally(() => {
this.loading = false
})
},
/** 保存/作废/审核提交,弹窗提示不一样 /** 保存/作废/审核提交,弹窗提示不一样
* 按钮类型 - 单据状态 * 按钮类型 - 单据状态
* 保存按钮(save) - 创建 - 0:待提交 * 保存按钮(save) - 创建 - 0:待提交
...@@ -628,44 +659,23 @@ export default { ...@@ -628,44 +659,23 @@ export default {
if (this.loading) { if (this.loading) {
return true return true
} }
const tipTxtObj = {
save: '保存成功',
review: '提交审核成功',
invalid: '作废成功'
}
const btnObj = this.btnTypeMap[btnType] const btnObj = this.btnTypeMap[btnType]
params.billStatus = btnObj.billStatus params.billStatus = btnObj.billStatus
this.$confirm(btnObj.confirmMsg, btnObj.title, { if (btnType == 'save') {
confirmButtonText: '确定', this.saveApi(params, btnType)
cancelButtonText: '取消', } else {
type: 'warning' this.$confirm(btnObj.confirmMsg, btnObj.title, {
}) confirmButtonText: '确定',
.then(() => { cancelButtonText: '取消',
this.loading = true type: 'warning'
this.$apis.stockManage[this.routeInfo.id ? 'updateStockAllocate' : 'saveStockAllocate'](params).then(res => {
this.$notify({
type: res.code == 0 ? 'success' : 'error',
title: res.code == 0 ? (tipTxtObj[btnType] || '操作成功') : res.message
})
if (res.code == 0) {
if (btnType == 'save') {
this.routeInfo.allocateCode = res.data
this.oprType = 'edit'
this.editFirst = true
this.editMerFirst = true
// this.isDisabled = true
this.getDetail()
} else {
this.handleAddClose()
}
}
})
})
.catch(err => {
console.log(err)
}).finally(() => {
this.loading = false
}) })
.then(() => {
this.saveApi(params, btnType)
})
.catch(err => {
console.log(err)
})
}
}, },
handleAddClose(isRefresh = false) { handleAddClose(isRefresh = false) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!