|
|
@@ -422,7 +422,7 @@ export default {
|
|
|
* @param {OrderItem} orderData - 保存后的订单数据
|
|
|
* @returns {void}
|
|
|
*/
|
|
|
- handleFormSaveSuccess(orderData) {
|
|
|
+ async handleFormSaveSuccess(orderData) {
|
|
|
if (this.isEditMode) {
|
|
|
// 编辑模式:保持在表单页,不返回列表
|
|
|
this.orderFormVisible = true
|
|
|
@@ -434,10 +434,43 @@ export default {
|
|
|
// 新增模式:保存后停留当前页并切换到编辑模式,显示提交按钮
|
|
|
this.orderFormVisible = true
|
|
|
this.isEditMode = true
|
|
|
- // 设置新创建订单的ID,确保子组件处于编辑态并加载详情
|
|
|
- this.editOrderId = orderData && orderData.id ? String(orderData.id) : this.editOrderId
|
|
|
- // 刷新列表数据,保持数据最新
|
|
|
- this.onLoad(this.page)
|
|
|
+ // 尝试从响应数据拿ID;若无则从列表首条获取ID
|
|
|
+ const respId = orderData && orderData.id ? String(orderData.id) : null
|
|
|
+ if (respId) {
|
|
|
+ this.editOrderId = respId
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ const latestId = await this.fetchLatestOrderId()
|
|
|
+ if (latestId) {
|
|
|
+ this.editOrderId = String(latestId)
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ // 获取最新ID失败,保留当前状态,用户仍可手动返回列表
|
|
|
+ // eslint-disable-next-line no-console
|
|
|
+ console.warn('获取最新订单ID失败:', e)
|
|
|
+ } finally {
|
|
|
+ // 刷新列表数据,保持数据最新
|
|
|
+ this.onLoad(this.page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最新创建的订单ID(列表第一页第一条)
|
|
|
+ * @returns {Promise<string|number|null>}
|
|
|
+ */
|
|
|
+ async fetchLatestOrderId() {
|
|
|
+ try {
|
|
|
+ const res = await getOrderList(1, 1, {})
|
|
|
+ const data = res && res.data && res.data.data
|
|
|
+ const records = data && Array.isArray(data.records) ? data.records : []
|
|
|
+ const first = records[0]
|
|
|
+ return (first && first.id) ? first.id : null
|
|
|
+ } catch (error) {
|
|
|
+ // eslint-disable-next-line no-console
|
|
|
+ console.error('fetchLatestOrderId error:', error)
|
|
|
+ return null
|
|
|
}
|
|
|
},
|
|
|
|