feat: opt 出港计重 计重明细 update

This commit is contained in:
2025-12-16 09:36:36 +08:00
parent d1ed050c76
commit b4238a04d0
5 changed files with 60 additions and 26 deletions

View File

@@ -1,5 +1,9 @@
package com.lukouguoji.module_base.bean
import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import androidx.databinding.library.baseAdapters.BR
/**
* 国际出港计重记录明细Bean
* 用于:加载运单的所有计重记录 + 批量更新
@@ -18,18 +22,34 @@ data class GjcCheckInRecord(
var weight: Double = 0.0, // 运抵重量
var volume: Double = 0.0, // 运抵体积
var whId: Long = 0 // GJC_WAREHOUSE.ID
) {
) : BaseObservable() {
// 数据变化回调
var onDataChanged: (() -> Unit)? = null
// 件数的字符串表示(用于双向绑定)
@get:Bindable
var pcStr: String
get() = if (pc == 0L) "" else pc.toString()
set(value) {
pc = value.toLongOrNull() ?: 0L
val newPc = value.toLongOrNull() ?: 0L
if (pc != newPc) {
pc = newPc
notifyPropertyChanged(BR.pcStr)
onDataChanged?.invoke()
}
}
// 重量的字符串表示(用于双向绑定)
@get:Bindable
var weightStr: String
get() = if (weight == 0.0) "" else weight.toString()
set(value) {
weight = value.toDoubleOrNull() ?: 0.0
val newWeight = value.toDoubleOrNull() ?: 0.0
if (weight != newWeight) {
weight = newWeight
notifyPropertyChanged(BR.weightStr)
onDataChanged?.invoke()
}
}
}

View File

@@ -3,6 +3,7 @@ package com.lukouguoji.gjc.activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
@@ -24,6 +25,9 @@ class GjcWeighingRecordDetailsActivity :
private lateinit var adapter: CommonAdapter
// 当前编辑模式供ViewHolder获取
var currentEditMode = false
override fun layoutId() = R.layout.activity_gjc_weighing_record_details
override fun viewModelClass() = GjcWeighingRecordDetailsViewModel::class.java
@@ -34,7 +38,13 @@ class GjcWeighingRecordDetailsActivity :
binding.viewModel = viewModel
// 初始化RecyclerView
binding.recyclerView.layoutManager = LinearLayoutManager(this)
val layoutManager = LinearLayoutManager(this)
binding.recyclerView.layoutManager = layoutManager
// 添加分割线
val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
binding.recyclerView.addItemDecoration(divider)
adapter = CommonAdapter(
this,
R.layout.item_gjc_check_in_record,
@@ -47,17 +57,13 @@ class GjcWeighingRecordDetailsActivity :
adapter.refresh(records)
}
// 监听编辑模式变化,更新所有ViewHolder的编辑状态
// 监听编辑模式变化,更新当前编辑模式并刷新列表
viewModel.isEditMode.observe(this) { isEditMode ->
val layoutManager = binding.recyclerView.layoutManager as? LinearLayoutManager
layoutManager?.let {
for (i in 0 until adapter.itemCount) {
val holder = binding.recyclerView.findViewHolderForAdapterPosition(i)
as? GjcCheckInRecordViewHolder
holder?.updateEditMode(isEditMode)
adapter.notifyItemChanged(i)
}
}
// 更新当前编辑模式状态
currentEditMode = isEditMode
// 刷新所有可见的 ViewHolder
adapter.notifyDataSetChanged()
}
// 初始化数据

View File

@@ -1,6 +1,7 @@
package com.lukouguoji.gjc.holder
import android.view.View
import com.lukouguoji.gjc.activity.GjcWeighingRecordDetailsActivity
import com.lukouguoji.gjc.databinding.ItemGjcCheckInRecordBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcCheckInRecord
@@ -11,14 +12,13 @@ import com.lukouguoji.module_base.bean.GjcCheckInRecord
class GjcCheckInRecordViewHolder(view: View) :
BaseViewHolder<GjcCheckInRecord, ItemGjcCheckInRecordBinding>(view) {
private var isEditMode: Boolean = false
fun updateEditMode(editMode: Boolean) {
this.isEditMode = editMode
}
override fun onBind(item: Any?, position: Int) {
val record = getItemBean(item)!!
// 从Activity获取当前编辑模式
val activity = itemView.context as? GjcWeighingRecordDetailsActivity
val isEditMode = activity?.currentEditMode ?: false
binding.record = record
binding.isEditMode = isEditMode
binding.position = position // 传入位置用于显示序号

View File

@@ -108,6 +108,15 @@ class GjcWeighingRecordDetailsViewModel : BaseViewModel() {
launchLoadingCollect({ NetApply.api.getGjcCheckInRecordList(params) }) {
onSuccess = { result ->
val list = result.data ?: emptyList()
// 为每个记录设置数据变化回调
list.forEach { record ->
record.onDataChanged = {
// 数据变化时重新计算统计
calculateStatistics()
}
}
recordList.value = list
if (list.isEmpty()) {

View File

@@ -166,15 +166,14 @@
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="1dp" />
android:background="#e7e7e7"
android:layout_height="1px" />
<!-- 第二部分:计重记录列表 -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="15dp"
android:paddingEnd="15dp"
tools:listitem="@layout/item_gjc_check_in_record" />
</LinearLayout>
@@ -227,7 +226,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{`总件数:` + viewModel.totalPc}"
android:text="@{`总件数` + viewModel.totalPc}"
android:textColor="@color/text_gray"
android:textSize="16sp" />
@@ -236,7 +235,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="@{`总重量:` + viewModel.totalWeight}"
android:text="@{`总重量` + viewModel.totalWeight}"
android:textColor="@color/text_gray"
android:textSize="16sp" />
@@ -245,7 +244,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="@{`重量误差: ` + viewModel.weightError}"
android:text="@{`重量误差` + viewModel.weightError}"
android:textColor="@color/text_red"
android:textSize="16sp" />