diff --git a/module_base/src/main/java/com/lukouguoji/module_base/bean/AssembleWaybillBean.kt b/module_base/src/main/java/com/lukouguoji/module_base/bean/AssembleWaybillBean.kt index b961f33..d8c9b44 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/bean/AssembleWaybillBean.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/bean/AssembleWaybillBean.kt @@ -7,14 +7,18 @@ import androidx.databinding.ObservableBoolean */ class AssembleWaybillBean { var waybillNo: String = "" // 运单号 - var pieces: String = "" // 件数 - var weight: String = "" // 重量 + var pieces: String = "" // 件数(累积的组装件数) + var weight: String = "" // 重量(累积的组装重量) var flight: String = "" // 配载航班 var isMarked: Boolean = false // 是否标记(红色显示) var fno: String = "" var fdate: String = "" var whId: Long = 0 // 运单ID(用于接口调用) + // ========== 原始运单信息(用于编辑模式回显) ========== + var originalPieces: String = "" // 原始运单件数 + var originalWeight: String = "" // 原始运单重量 + val fLightInfo: String get() = "$fno/${fdate.replace("-", "")}" diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleStartViewModel.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleStartViewModel.kt index 80c8628..ecfba79 100644 --- a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleStartViewModel.kt +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleStartViewModel.kt @@ -76,11 +76,6 @@ class IntExpAssembleStartViewModel : BaseViewModel() { */ private var editMode: Pair? = null // Pair - /** - * ULD编号锁定状态 - */ - val isUldNoLocked = MutableLiveData(false) - /** * 加载组装位置列表 @@ -130,25 +125,46 @@ class IntExpAssembleStartViewModel : BaseViewModel() { fun onWaybillItemClick(position: Int) { val list = waybillList.value ?: return + // 选中新运单前,先检查是否切换了运单 + val previousWaybillNo = waybillInfo.value?.waybillNo ?: "" + val selectedWaybill = if (position in list.indices) list[position] else null + val isWaybillChanged = selectedWaybill != null && previousWaybillNo.isNotEmpty() + && selectedWaybill.waybillNo != previousWaybillNo + // 取消所有运单的选中状态 list.forEach { it.isSelected.set(false) } // 选中当前运单 - if (position in list.indices) { - val selectedWaybill = list[position] + if (selectedWaybill != null) { selectedWaybill.isSelected.set(true) - // 保存当前的组装件数、组装重量、组装人(在创建新对象前) - val previousAssembleCount = waybillInfo.value?.assembleCount ?: "" - val previousAssembleWeight = waybillInfo.value?.assembleWeight ?: "" + // 保存当前的组装人(始终保留) val previousOperator = waybillInfo.value?.operator ?: "" + // 判断是否需要保留组装件数和重量 + val previousAssembleCount: String + val previousAssembleWeight: String + + if (isWaybillChanged) { + // 运单切换了:清空组装件数和组装重量 + previousAssembleCount = "" + previousAssembleWeight = "" + + // 如果在编辑模式,退出编辑模式 + if (editMode != null) { + editMode = null + } + } else { + // 同一个运单:保留组装件数和组装重量 + previousAssembleCount = waybillInfo.value?.assembleCount ?: "" + previousAssembleWeight = waybillInfo.value?.assembleWeight ?: "" + } + // 同步运单信息到表单 waybillInfo.value = WaybillInfoBean().apply { waybillNo = selectedWaybill.waybillNo waybillPieces = selectedWaybill.pieces waybillWeight = selectedWaybill.weight - // 保留当前的组装件数、组装重量、组装人 assembleCount = previousAssembleCount assembleWeight = previousAssembleWeight operator = previousOperator @@ -199,6 +215,22 @@ class IntExpAssembleStartViewModel : BaseViewModel() { // 更新列表 waybillList.value = waybillBeanList + // 检查当前填充的运单是否在新列表中 + val currentWaybillNo = waybillInfo.value?.waybillNo ?: "" + if (currentWaybillNo.isNotEmpty()) { + val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo } + if (!existsInNewList) { + // 当前运单不在新列表中,清空表单并退出编辑模式 + val previousOperator = waybillInfo.value?.operator ?: "" + waybillInfo.value = WaybillInfoBean().apply { + operator = previousOperator + } + if (editMode != null) { + editMode = null + } + } + } + // 结果反馈 if (waybillBeanList.isEmpty()) { showToast("未找到待组装运单") @@ -235,6 +267,22 @@ class IntExpAssembleStartViewModel : BaseViewModel() { waybillList.value = waybillBeanList + // 检查当前填充的运单是否在新列表中 + val currentWaybillNo = waybillInfo.value?.waybillNo ?: "" + if (currentWaybillNo.isNotEmpty()) { + val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo } + if (!existsInNewList) { + // 当前运单不在新列表中,清空表单并退出编辑模式 + val previousOperator = waybillInfo.value?.operator ?: "" + waybillInfo.value = WaybillInfoBean().apply { + operator = previousOperator + } + if (editMode != null) { + editMode = null + } + } + } + if (waybillBeanList.isEmpty()) { showToast("暂无待组装运单") } @@ -374,12 +422,35 @@ class IntExpAssembleStartViewModel : BaseViewModel() { return } - // 2. 获取选中的运单Bean - val currentWaybillList = waybillList.value ?: return - val selectedWaybill = currentWaybillList.firstOrNull { it.isSelected.get() } - if (selectedWaybill == null) { - showToast("请选择运单") - return + // 2. 获取或构建运单Bean + val selectedWaybill: AssembleWaybillBean = if (editMode != null) { + // 编辑模式:从本地存储中获取运单数据 + val uldNoInEdit = editMode!!.first + val waybillNoInEdit = editMode!!.second + val storedList = assembledCargoMap[uldNoInEdit] + val storedWaybill = storedList?.firstOrNull { it.waybillNo == waybillNoInEdit } + + if (storedWaybill == null) { + showToast("未找到运单数据") + return + } + + // 使用存储的运单数据(包含原始件数/重量和其他字段) + storedWaybill + } else { + // 新增模式:从运单列表中获取选中的运单 + val currentWaybillList = waybillList.value + if (currentWaybillList == null) { + showToast("运单列表为空") + return + } + + val selected = currentWaybillList.firstOrNull { it.isSelected.get() } + if (selected == null) { + showToast("请选择运单") + return + } + selected } // 3. 构建useInfo(ULD信息) @@ -395,10 +466,22 @@ class IntExpAssembleStartViewModel : BaseViewModel() { ) // 4. 构建wbInfo(运单信息) + // 如果是编辑模式,使用原始运单件数/重量;否则使用当前件数/重量 + val waybillPc = if (editMode != null && selectedWaybill.originalPieces.isNotEmpty()) { + selectedWaybill.originalPieces.toLongOrNull() + } else { + selectedWaybill.pieces.toLongOrNull() + } + val waybillWeight = if (editMode != null && selectedWaybill.originalWeight.isNotEmpty()) { + selectedWaybill.originalWeight.toDoubleOrNull() + } else { + selectedWaybill.weight.toDoubleOrNull() + } + val wbInfo = mapOf( "wbNo" to selectedWaybill.waybillNo, - "pc" to selectedWaybill.pieces.toLongOrNull(), - "weight" to selectedWaybill.weight.toDoubleOrNull(), + "pc" to waybillPc, + "weight" to waybillWeight, "fdate" to selectedWaybill.fdate, "fno" to selectedWaybill.fno, "whId" to selectedWaybill.whId @@ -450,17 +533,21 @@ class IntExpAssembleStartViewModel : BaseViewModel() { ) { showToast("${operationName}成功") - // 创建一个包含组装件数和重量的运单Bean + // 创建一个包含本次操作件数和重量的运单Bean val assembleWaybill = AssembleWaybillBean() assembleWaybill.waybillNo = selectedWaybill.waybillNo - assembleWaybill.pieces = assembleCount - assembleWaybill.weight = assembleWeight + assembleWaybill.pieces = assembleCount // 本次操作的件数 + assembleWaybill.weight = assembleWeight // 本次操作的重量 assembleWaybill.flight = selectedWaybill.flight assembleWaybill.fno = selectedWaybill.fno assembleWaybill.fdate = selectedWaybill.fdate assembleWaybill.whId = selectedWaybill.whId assembleWaybill.isMarked = selectedWaybill.isMarked + // 保存原始运单件数/重量(用于编辑模式回显) + assembleWaybill.originalPieces = selectedWaybill.originalPieces.ifEmpty { selectedWaybill.pieces } + assembleWaybill.originalWeight = selectedWaybill.originalWeight.ifEmpty { selectedWaybill.weight } + // 判断是新增还是编辑模式 if (editMode != null) { // 编辑模式:更新本地存储中的对应运单 @@ -587,7 +674,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() { /** * 从二级运单行填充表单(编辑模式) * 1. 填充 ULD 信息(并锁定 ULD 编号) - * 2. 填充运单信息(只读) + * 2. 填充运单信息(使用原始运单件数/重量,只读) * 3. 保留组装件数、组装重量、组装人为可编辑 * 4. 标记编辑模式 */ @@ -606,18 +693,15 @@ class IntExpAssembleStartViewModel : BaseViewModel() { // 2. 填充运单信息 waybillInfo.value = WaybillInfoBean().apply { waybillNo = waybill.waybillNo - waybillPieces = waybill.pieces - waybillWeight = waybill.weight - // 保留可编辑字段为空(需要用户重新输入) - assembleCount = "" - assembleWeight = "" + waybillPieces = waybill.originalPieces // 使用原始运单件数 + waybillWeight = waybill.originalWeight // 使用原始运单重量 + // 填充已累积的组装件数和组装重量(可编辑) + assembleCount = waybill.pieces + assembleWeight = waybill.weight operator = previousOperator // 保留之前选择的组装人 } - // 3. 锁定 ULD 编号 - isUldNoLocked.value = true - - // 4. 标记编辑模式(存储原始 ULD 编号和运单号) + // 3. 标记编辑模式(存储原始 ULD 编号和运单号) editMode = Pair(item.parentUldNo, waybill.waybillNo) // 5. 查询 ULD 信息(如果需要) @@ -626,7 +710,6 @@ class IntExpAssembleStartViewModel : BaseViewModel() { queryUldInfo(item.parentUldNo) } - showToast("已进入编辑模式,请修改组装信息") } /** @@ -730,7 +813,6 @@ class IntExpAssembleStartViewModel : BaseViewModel() { waybillInfo.value = WaybillInfoBean().apply { operator = previousOperator // 恢复组装人 } - isUldNoLocked.value = false editMode = null } } diff --git a/module_gjc/src/main/res/layout/activity_int_exp_assemble_start.xml b/module_gjc/src/main/res/layout/activity_int_exp_assemble_start.xml index 8ae876b..4d1f8ea 100644 --- a/module_gjc/src/main/res/layout/activity_int_exp_assemble_start.xml +++ b/module_gjc/src/main/res/layout/activity_int_exp_assemble_start.xml @@ -249,7 +249,6 @@