feat: 板箱过磅列表点击进表单页(数据回填)并侧滑显示详情

- 列表项侧滑显示"详情"按钮,点击进入只读详情页
- 整行点击改为进入板箱过磅表单页,并把该条数据回填到表单
- 表单页 ViewModel 接收 Intent 中的 Bean,预填独立字段、重量及 usingUldData
- 通道号/探板收口字典加载支持 checkedValue,命中项排到首位以实现异步匹配

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-22 10:43:08 +08:00
parent 07f50fdfc7
commit 64721a6efe
4 changed files with 112 additions and 17 deletions

View File

@@ -7,6 +7,8 @@ import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityGjcBoxWeighingAddBinding import com.lukouguoji.gjc.databinding.ActivityGjcBoxWeighingAddBinding
import com.lukouguoji.gjc.viewModel.GjcBoxWeighingAddViewModel import com.lukouguoji.gjc.viewModel.GjcBoxWeighingAddViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.bean.GjcUldUseBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.ktx.setUpperCaseAlphanumericFilter import com.lukouguoji.module_base.ktx.setUpperCaseAlphanumericFilter
/** /**
@@ -22,7 +24,7 @@ class GjcBoxWeighingAddActivity :
override fun initOnCreate(savedInstanceState: Bundle?) { override fun initOnCreate(savedInstanceState: Bundle?) {
setBackArrow("板箱过磅") setBackArrow("板箱过磅")
binding.viewModel = viewModel binding.viewModel = viewModel
viewModel.initOnCreated(this) viewModel.initOnCreated(this, intent)
// 为架子车号、ULD编码、IMP代码、航班号添加大写字母和数字的输入限制 // 为架子车号、ULD编码、IMP代码、航班号添加大写字母和数字的输入限制
binding.carIdInput.et.setUpperCaseAlphanumericFilter() binding.carIdInput.et.setUpperCaseAlphanumericFilter()
@@ -37,5 +39,12 @@ class GjcBoxWeighingAddActivity :
val starter = Intent(context, GjcBoxWeighingAddActivity::class.java) val starter = Intent(context, GjcBoxWeighingAddActivity::class.java)
context.startActivity(starter) context.startActivity(starter)
} }
@JvmStatic
fun startForEdit(context: Context, bean: GjcUldUseBean) {
val starter = Intent(context, GjcBoxWeighingAddActivity::class.java)
.putExtra(Constant.Key.BEAN, bean)
context.startActivity(starter)
}
} }
} }

View File

@@ -2,6 +2,7 @@ package com.lukouguoji.gjc.holder
import android.view.View import android.view.View
import com.lukouguoji.gjc.R import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.activity.GjcBoxWeighingAddActivity
import com.lukouguoji.gjc.activity.GjcBoxWeighingDetailsActivity import com.lukouguoji.gjc.activity.GjcBoxWeighingDetailsActivity
import com.lukouguoji.gjc.databinding.ItemGjcBoxWeighingBinding import com.lukouguoji.gjc.databinding.ItemGjcBoxWeighingBinding
import com.lukouguoji.module_base.base.BaseViewHolder import com.lukouguoji.module_base.base.BaseViewHolder
@@ -26,8 +27,14 @@ class GjcBoxWeighingViewHolder(view: View) :
updateIcon(bean) updateIcon(bean)
} }
// 整行点击跳转到详情页 // 整行点击跳转到表单页(带数据回填)
binding.ll.setOnClickListener { binding.ll.setOnClickListener {
GjcBoxWeighingAddActivity.startForEdit(it.context, bean)
}
// 侧滑“详情”按钮点击跳转到只读详情页
binding.btnDetail.setOnClickListener {
binding.swipeMenu.quickClose()
GjcBoxWeighingDetailsActivity.start(it.context, bean.useId) GjcBoxWeighingDetailsActivity.start(it.context, bean.useId)
} }
} }

View File

@@ -73,7 +73,7 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
/** /**
* 初始化 * 初始化
*/ */
fun initOnCreated(activity: Activity) { fun initOnCreated(activity: Activity, intent: Intent? = null) {
// 监听地磅重量变化 - 暂时注释 // 监听地磅重量变化 - 暂时注释
// diBangModel.weight.observe(activity as LifecycleOwner) { weight -> // diBangModel.weight.observe(activity as LifecycleOwner) { weight ->
// val w = weight?.toDoubleOrNull() ?: 0.0 // val w = weight?.toDoubleOrNull() ?: 0.0
@@ -104,14 +104,52 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
calculateWeights() calculateWeights()
} }
// 加载下拉列表数据
loadPassagewayList()
loadPlCloseList()
// 初始化航班日期为今天 // 初始化航班日期为今天
val today = Date().formatDate() val today = Date().formatDate()
flightDate.value = today flightDate.value = today
dataBean.value?.fdate = today dataBean.value?.fdate = today
// 编辑模式:从 Intent 中解析列表项 Bean 并回填
val editBean = intent?.getSerializableExtra(Constant.Key.BEAN) as? GjcUldUseBean
if (editBean != null) {
prefillFromBean(editBean)
loadPassagewayList(editBean.passagewayId)
loadPlCloseList(editBean.plClose)
} else {
loadPassagewayList(null)
loadPlCloseList(null)
}
}
/**
* 编辑模式:用列表项数据回填表单
*/
private fun prefillFromBean(bean: GjcUldUseBean) {
// 整体绑定(板型/高度/IMP/探板尺寸/目的港/备注/架子车自重/ULD自重等通过 dataBean.* 自动回填)
dataBean.value = bean
// 独立字段
carId.value = bean.carId
uldNo.value = bean.uld
flightNo.value = bean.fno
flightDate.value = bean.fdate
// 计算字段
totalWeight.value = bean.totalWeight.toString()
netWeight.value = bean.netWeight.toString()
cargoWeight.value = bean.cargoWeight.toString()
diBangWeight.value = bean.totalWeight.toString()
// 通道号 Spinner 绑定到 channelKeyValue.value 即 passagewayId
channel.value = bean.passagewayId
// 抑制重复自动查询(避免回调把已填数据再次刷掉)
lastQueriedCarId = bean.carId
lastQueriedUld = bean.uld
lastQueriedFlight = "${bean.fdate}-${bean.fno}"
// confirmClick 需要 usingUldData列表项本身就是当前正在使用的记录
usingUldData = bean
} }
/** /**
@@ -191,34 +229,47 @@ class GjcBoxWeighingAddViewModel : BaseViewModel() {
/** /**
* 加载通道号列表 * 加载通道号列表
* @param checkedValue 编辑模式下需要选中的 passagewayId为空则按返回顺序展示
*/ */
private fun loadPassagewayList() { private fun loadPassagewayList(checkedValue: String?) {
launchCollect({ launchCollect({
NetApply.api.getDictList("GJPASSAGEWAY") NetApply.api.getDictList("GJPASSAGEWAY")
}) { }) {
onSuccess = { onSuccess = {
passagewayList.value = (it.data ?: emptyList()).map { b -> b.toKeyValue() } val list = (it.data ?: emptyList()).map { b -> b.toKeyValue() }
passagewayList.value = reorderChecked(list, checkedValue)
} }
} }
} }
/** /**
* 加载探板收口列表 * 加载探板收口列表
* @param checkedValue 编辑模式下需要选中的 plClose 值;为空则按返回顺序展示
*/ */
private fun loadPlCloseList() { private fun loadPlCloseList(checkedValue: String?) {
launchCollect({ launchCollect({
NetApply.api.getDictList("PICLOSE") NetApply.api.getDictList("PICLOSE")
}) { }) {
onSuccess = { onSuccess = {
// 将 DictIdValueBean 转换为 KeyValue // 将 DictIdValueBean 转换为 KeyValue
// 显示和提交都使用 value 字段 // 显示和提交都使用 value 字段
plCloseList.value = (it.data ?: emptyList()).map { b -> val list = (it.data ?: emptyList()).map { b ->
KeyValue(b.value, b.value) KeyValue(b.value, b.value)
} }
plCloseList.value = reorderChecked(list, checkedValue)
} }
} }
} }
/**
* 若 checkedValue 命中列表中某项则把该项移到首位PadDataLayoutNew SPINNER 默认显示首项)
*/
private fun reorderChecked(list: List<KeyValue>, checkedValue: String?): List<KeyValue> {
if (checkedValue.isNullOrEmpty()) return list
val matched = list.firstOrNull { it.value == checkedValue } ?: return list
return listOf(matched) + list.filter { it !== matched }
}
/** /**
* 计算重量字段 * 计算重量字段
* 装机重 = 总重 - 架子车自重 * 装机重 = 总重 - 架子车自重

View File

@@ -9,15 +9,25 @@
type="com.lukouguoji.module_base.bean.GjcUldUseBean" /> type="com.lukouguoji.module_base.bean.GjcUldUseBean" />
</data> </data>
<androidx.appcompat.widget.LinearLayoutCompat <LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp" android:layout_marginHorizontal="15dp"
android:layout_marginVertical="5dp" android:layout_marginVertical="5dp"
android:background="@drawable/bg_item" android:orientation="vertical">
android:orientation="horizontal"
android:padding="10dp"> <com.mcxtzhang.swipemenulib.SwipeMenuLayout
android:id="@+id/swipe_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_item"
android:orientation="horizontal"
android:padding="10dp">
<!-- 飞机图标 --> <!-- 飞机图标 -->
<ImageView <ImageView
@@ -290,5 +300,23 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:src="@drawable/img_pda_right" /> android:src="@drawable/img_pda_right" />
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>
<!-- 侧滑菜单区域 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/btn_detail"
style="@style/tv_item_action"
android:background="@color/colorPrimary"
android:text="详情" />
</androidx.appcompat.widget.LinearLayoutCompat>
</com.mcxtzhang.swipemenulib.SwipeMenuLayout>
</LinearLayout>
</layout> </layout>