fix: 国际出港板箱过磅重进页面时自动选中上次通道号
原实现只把上次通道号排到字典列表首位,但带 hint 的 Spinner 默认停在 hint 项, 导致退出再进入(含从列表点 ULD 进入的编辑模式)时通道号始终显示「请选择通道号」。 改为字典加载完成后按「本条记录通道号 → 上次记住的通道号」优先级显式赋值。 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -120,12 +120,12 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
|||||||
val editBean = intent?.getSerializableExtra(Constant.Key.BEAN) as? GjcUldUseBean
|
val editBean = intent?.getSerializableExtra(Constant.Key.BEAN) as? GjcUldUseBean
|
||||||
if (editBean != null) {
|
if (editBean != null) {
|
||||||
prefillFromBean(editBean)
|
prefillFromBean(editBean)
|
||||||
loadPassagewayList(editBean.passagewayId)
|
// 优先本条记录自带的通道号,没有则回退到上一次称重记住的通道号(App 级持久化)
|
||||||
|
loadPassagewayList(editBean.passagewayId.ifEmpty { null })
|
||||||
loadPlCloseList(editBean.plClose)
|
loadPlCloseList(editBean.plClose)
|
||||||
} else {
|
} else {
|
||||||
// 新增模式:默认选中上一次称重使用的通道号
|
// 新增模式:默认选中上一次称重使用的通道号
|
||||||
val lastPassagewayId = SharedPreferenceUtil.getString(KEY_LAST_PASSAGEWAY_ID)
|
loadPassagewayList(null)
|
||||||
loadPassagewayList(lastPassagewayId.ifEmpty { null })
|
|
||||||
loadPlCloseList(null)
|
loadPlCloseList(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,15 +239,27 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载通道号列表
|
* 加载通道号列表
|
||||||
* @param checkedValue 编辑模式下需要选中的 passagewayId;为空则按返回顺序展示
|
* @param preferredId 编辑模式下本条记录自带的 passagewayId;为空则回退到上一次称重记住的通道号
|
||||||
|
*
|
||||||
|
* 注意:Spinner 带 hint 时默认停在 hint 项,并不会显示列表首项,
|
||||||
|
* 所以必须显式给 channel 赋值才能选中,只调列表顺序无效。
|
||||||
*/
|
*/
|
||||||
private fun loadPassagewayList(checkedValue: String?) {
|
private fun loadPassagewayList(preferredId: String?) {
|
||||||
launchCollect({
|
launchCollect({
|
||||||
NetApply.api.getDictList("GJPASSAGEWAY")
|
NetApply.api.getDictList("GJPASSAGEWAY")
|
||||||
}) {
|
}) {
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
val list = (it.data ?: emptyList()).map { b -> b.toKeyValue() }
|
val list = (it.data ?: emptyList()).map { b -> b.toKeyValue() }
|
||||||
passagewayList.value = reorderChecked(list, checkedValue)
|
passagewayList.value = list
|
||||||
|
|
||||||
|
// 选中优先级:本条记录的通道号 → 上一次称重记住的通道号(SharedPreference,跨页面、跨启动保留)
|
||||||
|
val lastPassagewayId = SharedPreferenceUtil.getString(KEY_LAST_PASSAGEWAY_ID)
|
||||||
|
val selected = listOf(preferredId, lastPassagewayId).firstOrNull { id ->
|
||||||
|
!id.isNullOrEmpty() && list.any { kv -> kv.value == id }
|
||||||
|
}
|
||||||
|
if (selected != null) {
|
||||||
|
channel.value = selected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user