feat: 国际出港-开始组装-组装人 auto select
This commit is contained in:
@@ -12,6 +12,9 @@ import com.lukouguoji.gjc.viewModel.IntExpAssembleStartViewModel
|
|||||||
import com.lukouguoji.module_base.base.BaseBindingActivity
|
import com.lukouguoji.module_base.base.BaseBindingActivity
|
||||||
import com.lukouguoji.module_base.base.CommonAdapter
|
import com.lukouguoji.module_base.base.CommonAdapter
|
||||||
import com.lukouguoji.module_base.common.Constant
|
import com.lukouguoji.module_base.common.Constant
|
||||||
|
import com.lukouguoji.module_base.common.ConstantEvent
|
||||||
|
import com.lukouguoji.module_base.impl.FlowBus
|
||||||
|
import com.lukouguoji.module_base.impl.observe
|
||||||
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
|
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
|
||||||
import com.lukouguoji.module_base.ktx.addOnItemClickListener
|
import com.lukouguoji.module_base.ktx.addOnItemClickListener
|
||||||
import com.lukouguoji.module_base.ktx.setUpperCaseAlphanumericFilter
|
import com.lukouguoji.module_base.ktx.setUpperCaseAlphanumericFilter
|
||||||
@@ -60,6 +63,11 @@ class IntExpAssembleStartActivity :
|
|||||||
// 加载组装人列表
|
// 加载组装人列表
|
||||||
viewModel.loadAssemblerList()
|
viewModel.loadAssemblerList()
|
||||||
|
|
||||||
|
// 监听登出事件,清空缓存
|
||||||
|
FlowBus.with<Any>(ConstantEvent.LOGOUT).observe(this) {
|
||||||
|
viewModel.clearCachedOperator()
|
||||||
|
}
|
||||||
|
|
||||||
// 观察数据变化
|
// 观察数据变化
|
||||||
observeData()
|
observeData()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,14 @@ import dev.utils.app.info.KeyValue
|
|||||||
*/
|
*/
|
||||||
class IntExpAssembleStartViewModel : BaseViewModel() {
|
class IntExpAssembleStartViewModel : BaseViewModel() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* 缓存用户上次选择的组装人
|
||||||
|
* 生命周期:本次App打开期间有效,退出登录后清空
|
||||||
|
*/
|
||||||
|
var lastSelectedOperator: String? = null
|
||||||
|
}
|
||||||
|
|
||||||
// ========== 搜索条件 ==========
|
// ========== 搜索条件 ==========
|
||||||
val searchText = MutableLiveData("")
|
val searchText = MutableLiveData("")
|
||||||
val uldSearchText = MutableLiveData("") // ULD搜索框
|
val uldSearchText = MutableLiveData("") // ULD搜索框
|
||||||
@@ -57,6 +65,9 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
// ========== 运单信息 ==========
|
// ========== 运单信息 ==========
|
||||||
val waybillInfo = MutableLiveData(WaybillInfoBean())
|
val waybillInfo = MutableLiveData(WaybillInfoBean())
|
||||||
|
|
||||||
|
// ========== 组装人(独立的LiveData,用于监听变化并更新缓存)==========
|
||||||
|
val operator = MutableLiveData<String>("")
|
||||||
|
|
||||||
// ========== 组装人列表 ==========
|
// ========== 组装人列表 ==========
|
||||||
val assemblerList = MutableLiveData<List<KeyValue>>(emptyList())
|
val assemblerList = MutableLiveData<List<KeyValue>>(emptyList())
|
||||||
|
|
||||||
@@ -68,6 +79,40 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
*/
|
*/
|
||||||
val isUldNoLocked = MutableLiveData(false)
|
val isUldNoLocked = MutableLiveData(false)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 装货按钮启用状态(非编辑模式时启用)
|
||||||
|
*/
|
||||||
|
val isLoadEnabled = MutableLiveData(true)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卸货按钮启用状态(编辑模式时启用)
|
||||||
|
*/
|
||||||
|
val isUnloadEnabled = MutableLiveData(false)
|
||||||
|
|
||||||
|
init {
|
||||||
|
// 监听组装人变化,自动更新缓存和waybillInfo
|
||||||
|
operator.observeForever { value ->
|
||||||
|
if (!value.isNullOrEmpty()) {
|
||||||
|
lastSelectedOperator = value
|
||||||
|
// 同步到 waybillInfo
|
||||||
|
waybillInfo.value?.operator = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听ULD锁定状态,自动更新按钮启用状态
|
||||||
|
isUldNoLocked.observeForever { isLocked ->
|
||||||
|
if (isLocked == true) {
|
||||||
|
// 编辑模式:只能卸货
|
||||||
|
isLoadEnabled.value = false
|
||||||
|
isUnloadEnabled.value = true
|
||||||
|
} else {
|
||||||
|
// 非编辑模式:只能装货
|
||||||
|
isLoadEnabled.value = true
|
||||||
|
isUnloadEnabled.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载组装位置列表
|
* 加载组装位置列表
|
||||||
@@ -137,8 +182,8 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
assembleFlightNo.value = selectedWaybill.fno
|
assembleFlightNo.value = selectedWaybill.fno
|
||||||
assembleFlightDate.value = selectedWaybill.fdate
|
assembleFlightDate.value = selectedWaybill.fdate
|
||||||
|
|
||||||
// 保存当前的组装人(始终保留)
|
// 保存当前的组装人(始终保留,从operator LiveData读取)
|
||||||
val previousOperator = waybillInfo.value?.operator ?: ""
|
val previousOperator = operator.value ?: ""
|
||||||
|
|
||||||
// 判断是否需要保留组装件数和重量
|
// 判断是否需要保留组装件数和重量
|
||||||
val previousAssembleCount: String
|
val previousAssembleCount: String
|
||||||
@@ -164,7 +209,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
waybillWeight = selectedWaybill.weight
|
waybillWeight = selectedWaybill.weight
|
||||||
assembleCount = previousAssembleCount
|
assembleCount = previousAssembleCount
|
||||||
assembleWeight = previousAssembleWeight
|
assembleWeight = previousAssembleWeight
|
||||||
operator = previousOperator
|
operator = previousOperator // 从operator LiveData获取的值
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +269,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo }
|
val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo }
|
||||||
if (!existsInNewList) {
|
if (!existsInNewList) {
|
||||||
// 当前运单不在新列表中,清空表单
|
// 当前运单不在新列表中,清空表单
|
||||||
val previousOperator = waybillInfo.value?.operator ?: ""
|
val previousOperator = operator.value ?: ""
|
||||||
waybillInfo.value = WaybillInfoBean().apply {
|
waybillInfo.value = WaybillInfoBean().apply {
|
||||||
operator = previousOperator
|
operator = previousOperator
|
||||||
}
|
}
|
||||||
@@ -273,7 +318,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo }
|
val existsInNewList = waybillBeanList.any { it.waybillNo == currentWaybillNo }
|
||||||
if (!existsInNewList) {
|
if (!existsInNewList) {
|
||||||
// 当前运单不在新列表中,清空表单
|
// 当前运单不在新列表中,清空表单
|
||||||
val previousOperator = waybillInfo.value?.operator ?: ""
|
val previousOperator = operator.value ?: ""
|
||||||
waybillInfo.value = WaybillInfoBean().apply {
|
waybillInfo.value = WaybillInfoBean().apply {
|
||||||
operator = previousOperator
|
operator = previousOperator
|
||||||
}
|
}
|
||||||
@@ -302,15 +347,11 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
val keyValueList = list.map { KeyValue(it, it) }
|
val keyValueList = list.map { KeyValue(it, it) }
|
||||||
assemblerList.value = keyValueList
|
assemblerList.value = keyValueList
|
||||||
|
|
||||||
// 获取当前登录用户名
|
// 使用缓存的组装人,如果缓存存在且在列表中则自动填充
|
||||||
val currentUserName = SharedPreferenceUtil.getString(Constant.Share.userName)
|
if (!lastSelectedOperator.isNullOrEmpty() && list.contains(lastSelectedOperator)) {
|
||||||
|
operator.value = lastSelectedOperator // 设置到operator LiveData,会自动触发observer更新缓存和waybillInfo
|
||||||
// 如果当前用户名在列表中,设置为默认值;否则保持为空(显示 hint)
|
|
||||||
if (currentUserName.isNotEmpty() && list.contains(currentUserName)) {
|
|
||||||
waybillInfo.value?.operator = currentUserName
|
|
||||||
waybillInfo.value = waybillInfo.value // 触发LiveData更新
|
|
||||||
}
|
}
|
||||||
// 注意:不匹配时不需要显式设置为空,因为初始值已经是空字符串
|
// 如果缓存为空或不在列表中,保持为空(显示hint "请选择组装人")
|
||||||
}
|
}
|
||||||
onFailed = { code, message ->
|
onFailed = { code, message ->
|
||||||
showToast("加载组装人列表失败: $message")
|
showToast("加载组装人列表失败: $message")
|
||||||
@@ -409,8 +450,8 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
val assembleWeight = waybillInfo.value?.assembleWeight?.trim() ?: ""
|
val assembleWeight = waybillInfo.value?.assembleWeight?.trim() ?: ""
|
||||||
// 组装重量为非必填,不进行验证
|
// 组装重量为非必填,不进行验证
|
||||||
|
|
||||||
val operator = waybillInfo.value?.operator?.trim() ?: ""
|
val operatorValue = operator.value?.trim() ?: ""
|
||||||
if (operator.isEmpty()) {
|
if (operatorValue.isEmpty()) {
|
||||||
showToast("请选择组装人")
|
showToast("请选择组装人")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -475,7 +516,7 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
"abPc" to assembleCount.toLongOrNull(),
|
"abPc" to assembleCount.toLongOrNull(),
|
||||||
"abWeight" to assembleWeight.toDoubleOrNull(),
|
"abWeight" to assembleWeight.toDoubleOrNull(),
|
||||||
"consumeWeight" to materialWeight.toDoubleOrNull(),
|
"consumeWeight" to materialWeight.toDoubleOrNull(),
|
||||||
"ldId" to operator,
|
"ldId" to operatorValue,
|
||||||
"loadArea" to loadArea,
|
"loadArea" to loadArea,
|
||||||
"useInfo" to useInfo,
|
"useInfo" to useInfo,
|
||||||
"wbInfo" to wbInfo,
|
"wbInfo" to wbInfo,
|
||||||
@@ -664,8 +705,8 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
// 耗材重量、ULD状态保持不变
|
// 耗材重量、ULD状态保持不变
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存当前的组装人(在创建新对象前)
|
// 保存当前的组装人(在创建新对象前,从operator LiveData读取)
|
||||||
val previousOperator = waybillInfo.value?.operator ?: ""
|
val previousOperator = operator.value ?: ""
|
||||||
|
|
||||||
// 2. 填充运单信息
|
// 2. 填充运单信息
|
||||||
waybillInfo.value = WaybillInfoBean().apply {
|
waybillInfo.value = WaybillInfoBean().apply {
|
||||||
@@ -799,12 +840,19 @@ class IntExpAssembleStartViewModel : BaseViewModel() {
|
|||||||
* 清空表单并退出编辑模式
|
* 清空表单并退出编辑模式
|
||||||
*/
|
*/
|
||||||
private fun clearForm() {
|
private fun clearForm() {
|
||||||
// 保留组装人的值(用户期望保留上一次的选择)
|
// 保留组装人的值(用户期望保留上一次的选择,从operator LiveData读取)
|
||||||
val previousOperator = waybillInfo.value?.operator ?: ""
|
val previousOperator = operator.value ?: ""
|
||||||
|
|
||||||
waybillInfo.value = WaybillInfoBean().apply {
|
waybillInfo.value = WaybillInfoBean().apply {
|
||||||
operator = previousOperator // 恢复组装人
|
operator = previousOperator // 恢复组装人
|
||||||
}
|
}
|
||||||
isUldNoLocked.value = false
|
isUldNoLocked.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空缓存的组装人(登出时调用)
|
||||||
|
*/
|
||||||
|
fun clearCachedOperator() {
|
||||||
|
lastSelectedOperator = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,7 +384,7 @@
|
|||||||
type="@{DataLayoutType.SPINNER}"
|
type="@{DataLayoutType.SPINNER}"
|
||||||
hint='@{"请选择组装人"}'
|
hint='@{"请选择组装人"}'
|
||||||
list="@{viewModel.assemblerList}"
|
list="@{viewModel.assemblerList}"
|
||||||
value="@={viewModel.waybillInfo.operator}"
|
value="@={viewModel.operator}"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
@@ -406,7 +406,9 @@
|
|||||||
android:layout_width="120dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="44dp"
|
android:layout_height="44dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
|
android:alpha="@{viewModel.isUnloadEnabled ? 1.0f : 0.5f}"
|
||||||
android:background="@drawable/bg_blue_radius_4"
|
android:background="@drawable/bg_blue_radius_4"
|
||||||
|
android:enabled="@{viewModel.isUnloadEnabled}"
|
||||||
android:onClick="@{() -> viewModel.onUnloadClick()}"
|
android:onClick="@{() -> viewModel.onUnloadClick()}"
|
||||||
android:text="卸货"
|
android:text="卸货"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
@@ -416,7 +418,9 @@
|
|||||||
android:layout_width="120dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="44dp"
|
android:layout_height="44dp"
|
||||||
android:layout_marginStart="32dp"
|
android:layout_marginStart="32dp"
|
||||||
|
android:alpha="@{viewModel.isLoadEnabled ? 1.0f : 0.5f}"
|
||||||
android:background="@drawable/bg_red_radius_4"
|
android:background="@drawable/bg_red_radius_4"
|
||||||
|
android:enabled="@{viewModel.isLoadEnabled}"
|
||||||
android:onClick="@{() -> viewModel.onLoadClick()}"
|
android:onClick="@{() -> viewModel.onLoadClick()}"
|
||||||
android:text="装货"
|
android:text="装货"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|||||||
Reference in New Issue
Block a user