fix: 开始组装新增模式支持连续组装多票

新增模式对全新 ULD 首票装货后,服务端才生成 useId,
而装货/卸货接口返回值不含 useId,未回填导致后续票仍以
useId=null 提交、被当作新 use 处理,无法继续多票。
每次操作成功后重拉 getUld 回填 useId,并在航班为空时
用运单航班兜底刷新组装信息列表。仅在 useId 为 0、航班
为空时生效,修改模式及已过磅 ULD 保持原逻辑不变。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 14:03:25 +08:00
parent 30532386fb
commit 7d5b3b2438

View File

@@ -456,6 +456,33 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
} }
} }
/**
* 重新查询 ULD 信息,仅回填最新的 useId 与 ULD 状态。
*
* 用途:以"新增"形式进入页面、对全新 ULD 首次装货时,服务端在首票成功后才生成
* 该 ULD 的 use 记录useId。装货/卸货接口返回值GjcWarehouse不含 useId
* 若不回填,后续票仍以 useId=null 提交,会被服务端当作新的 use 处理,
* 导致无法继续往同一 ULD 组装多票。此处在每次操作成功后回填最新 useId
* 保证多票组装提交到同一 ULD use 记录。
*
* 不在此处刷新航班/组装信息列表,避免与 loadAssembledList 的航班兜底逻辑相互覆盖。
*/
private fun reloadUldUseId(uldNo: String) {
if (uldNo.isEmpty()) return
launchCollect({ NetApply.api.getUldWithConsumeWeight(uldNo) }) {
onSuccess = { result ->
val uldBean = result.data
if (uldBean != null) {
// 仅回填 useId用于后续装货/卸货提交到同一 ULD use 记录),
// 不改动 ULD 状态/耗材重量/航班等其它字段,避免影响表单现有逻辑。
uldInfo.value = uldInfo.value?.apply {
useId = uldBean.useId
}
}
}
}
}
/** /**
* 卸货按钮点击 * 卸货按钮点击
*/ */
@@ -589,6 +616,10 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
// 3. 【修改】区分 wbInfo 构建 // 3. 【修改】区分 wbInfo 构建
val wbInfo: Map<String, Any?> val wbInfo: Map<String, Any?>
// 记录本次操作运单的航班信息(用于操作成功后刷新组装信息列表)
var operationFno = ""
var operationFdate = ""
if (isLoad) { if (isLoad) {
// 装货:从运单列表获取 // 装货:从运单列表获取
val currentWaybillList = waybillList.value val currentWaybillList = waybillList.value
@@ -615,6 +646,9 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
selectedWaybill.weight.toDoubleOrNull() selectedWaybill.weight.toDoubleOrNull()
} }
operationFno = selectedWaybill.fno
operationFdate = selectedWaybill.fdate
wbInfo = mapOf( wbInfo = mapOf(
"wbNo" to selectedWaybill.waybillNo, "wbNo" to selectedWaybill.waybillNo,
"pc" to waybillPc, "pc" to waybillPc,
@@ -631,6 +665,9 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
return return
} }
operationFno = assembleWaybill.fno
operationFdate = assembleWaybill.fdate
wbInfo = mapOf( wbInfo = mapOf(
"wbNo" to assembleWaybill.waybillNo, "wbNo" to assembleWaybill.waybillNo,
"pc" to assembleWaybill.pieces.toLongOrNull(), // 运单件数 "pc" to assembleWaybill.pieces.toLongOrNull(), // 运单件数
@@ -665,7 +702,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
}) { }) {
onSuccess = { result -> onSuccess = { result ->
// 接口成功后才显示成功提示并刷新列表 // 接口成功后才显示成功提示并刷新列表
handleOperationSuccess(operationName, isLoad, uldNo, assembleCount, assembleWeight) handleOperationSuccess(operationName, uldNo, operationFno, operationFdate)
} }
onFailed = { code, message -> onFailed = { code, message ->
showToast("${operationName}失败: $message") showToast("${operationName}失败: $message")
@@ -678,10 +715,9 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
*/ */
private fun handleOperationSuccess( private fun handleOperationSuccess(
operationName: String, operationName: String,
isLoad: Boolean,
uldNo: String, uldNo: String,
assembleCount: String, operationFno: String,
assembleWeight: String operationFdate: String
) { ) {
showToast("${operationName}成功") showToast("${operationName}成功")
@@ -693,6 +729,26 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
// 清空表单(在刷新数据前清空,避免刷新时的状态冲突) // 清空表单(在刷新数据前清空,避免刷新时的状态冲突)
clearForm() clearForm()
// 回填最新 useId关键以"新增"形式进入、对全新 ULD 首票装货时,
// 服务端在首票成功后才生成该 ULD 的 use 记录,而装货/卸货接口返回值不含 useId。
// 若不回填,后续票仍以 useId=null 提交,会被服务端当作新的 use 处理,
// 导致无法继续往同一 ULD 组装多票。
// 仅在本地 useId 尚未生成(为 0时回填"修改"模式及已过磅 ULD 本就带 useId保持原逻辑不变。
if ((uldInfo.value?.useId ?: 0L) == 0L) {
reloadUldUseId(uldNo)
}
// 添加形式(全新 ULD时航班可能未从 ULD 查询接口获取,导致组装信息列表查不出;
// 仅在航班为空时用本次操作运单的航班信息兜底补全ULD 已带航班时保持原值不变。
if (assembleFlightNo.value.isNullOrEmpty() || assembleFlightDate.value.isNullOrEmpty()) {
if (operationFno.isNotEmpty() && operationFdate.isNotEmpty()) {
assembleFlightNo.value = operationFno
// 与 ULD 查询保持一致,只取年月日(去掉时间部分)
assembleFlightDate.value =
if (operationFdate.contains(" ")) operationFdate.split(" ")[0] else operationFdate
}
}
// 清除防抖标记,强制刷新组装信息列表 // 清除防抖标记,强制刷新组装信息列表
lastQueriedAssembledParams = "" lastQueriedAssembledParams = ""
loadAssembledList() loadAssembledList()