|
|
@@ -937,14 +937,14 @@ export default {
|
|
|
*/
|
|
|
async handleSave() {
|
|
|
if (this.saveLoading) {
|
|
|
- return // 防止重复提交
|
|
|
+ return null // 防止重复提交
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
// 表单验证
|
|
|
const isValid = await this.validateForm()
|
|
|
if (!isValid) {
|
|
|
- return
|
|
|
+ return null
|
|
|
}
|
|
|
|
|
|
// 库存校验:订单数量不得超过可用数量(可用数量=storeInventory 映射而来)
|
|
|
@@ -985,6 +985,15 @@ export default {
|
|
|
const successMessage = this.isEdit ? '订单更新成功' : '订单创建成功'
|
|
|
this.$message.success(successMessage)
|
|
|
|
|
|
+ // 尽早同步ID到本地表单,便于新增态后续操作(如导入)使用
|
|
|
+ const responseData = response && response.data ? response.data.data : null
|
|
|
+ const savedId = (typeof responseData === 'string' || typeof responseData === 'number')
|
|
|
+ ? responseData
|
|
|
+ : (responseData && responseData.id)
|
|
|
+ if (savedId) {
|
|
|
+ this.formData.id = String(savedId)
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存成功事件
|
|
|
* @event typeof ORDER_FORM_EVENTS.SAVE_SUCCESS
|
|
|
@@ -1001,23 +1010,21 @@ export default {
|
|
|
// 新增模式:保存成功后使用返回的订单ID加载订单详情并切换到编辑模式
|
|
|
// 编辑模式:保存成功后刷新订单详情,已保存的物料置为不可删除
|
|
|
if (this.isEdit) {
|
|
|
- const savedId = (response && response.data && response.data.data && response.data.data.id) || this.orderId || (this.formData && this.formData.id)
|
|
|
- if (savedId) {
|
|
|
- await this.loadOrderDetail(String(savedId))
|
|
|
+ const targetId = savedId || this.orderId || (this.formData && this.formData.id)
|
|
|
+ if (targetId) {
|
|
|
+ await this.loadOrderDetail(String(targetId))
|
|
|
}
|
|
|
} else {
|
|
|
// 新增模式:使用接口返回的订单ID加载订单详情并切换到编辑模式
|
|
|
- const newOrderId = response && response.data && response.data.data
|
|
|
- if (newOrderId) {
|
|
|
- // 设置订单ID,触发编辑模式
|
|
|
- this.orderId = String(newOrderId)
|
|
|
- // 加载订单详情数据
|
|
|
- await this.loadOrderDetail(String(newOrderId))
|
|
|
+ if (savedId) {
|
|
|
+ // 加载订单详情数据(父组件会基于 save-success 切换到编辑模式并回传 orderId)
|
|
|
+ await this.loadOrderDetail(String(savedId))
|
|
|
// 可选:显示成功提示,告知用户已切换到编辑模式
|
|
|
this.$message.success('订单创建成功,已自动切换到编辑模式')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ return savedId ? String(savedId) : null
|
|
|
} catch (error) {
|
|
|
const errorMessage = this.isEdit ? '订单更新失败,请重试' : '订单创建失败,请重试'
|
|
|
this.$message.error(errorMessage)
|
|
|
@@ -1028,6 +1035,19 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 确保已获取订单ID(用于新增态导入前自动保存)
|
|
|
+ * @returns {Promise<string|number|null>}
|
|
|
+ * @this {import('./types').OrderFormMixinComponent}
|
|
|
+ */
|
|
|
+ async ensureOrderIdForImport() {
|
|
|
+ const existing = this.orderId || (this.formData && this.formData.id)
|
|
|
+ if (existing) return existing
|
|
|
+
|
|
|
+ const createdId = await this.handleSave()
|
|
|
+ return createdId || this.orderId || (this.formData && this.formData.id) || null
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 判断订单是否可以提交到U9
|
|
|
* @description 仅草稿(0)和未提交(1)状态允许提交
|
|
|
* @param {import('./types').OrderFormModel | any} row - 订单数据对象
|