feat: opt 出港计重 计重明细 update
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
// 初始化数据
|
||||
|
||||
@@ -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 // 传入位置用于显示序号
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user