feat: opt 开始装载

This commit is contained in:
2025-12-18 15:28:37 +08:00
parent 222ae8a0f5
commit 3df9a9f73f
3 changed files with 122 additions and 37 deletions

View File

@@ -76,11 +76,6 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
*/
private var editMode: Pair<String, String>? = null // Pair<ULD编号, 运单号>
/**
* 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. 构建useInfoULD信息
@@ -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
}
}

View File

@@ -249,7 +249,6 @@
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:id="@+id/uldNoInput"
enable="@{!viewModel.isUldNoLocked}"
required="@{false}"
setRefreshCallBack="@{viewModel::onUldNoInputComplete}"
title='@{"ULD编号"}'