feat: opt 出港计重 计重明细 update
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package com.lukouguoji.module_base.bean
|
package com.lukouguoji.module_base.bean
|
||||||
|
|
||||||
|
import androidx.databinding.BaseObservable
|
||||||
|
import androidx.databinding.Bindable
|
||||||
|
import androidx.databinding.library.baseAdapters.BR
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 国际出港计重记录明细Bean
|
* 国际出港计重记录明细Bean
|
||||||
* 用于:加载运单的所有计重记录 + 批量更新
|
* 用于:加载运单的所有计重记录 + 批量更新
|
||||||
@@ -18,18 +22,34 @@ data class GjcCheckInRecord(
|
|||||||
var weight: Double = 0.0, // 运抵重量
|
var weight: Double = 0.0, // 运抵重量
|
||||||
var volume: Double = 0.0, // 运抵体积
|
var volume: Double = 0.0, // 运抵体积
|
||||||
var whId: Long = 0 // GJC_WAREHOUSE.ID
|
var whId: Long = 0 // GJC_WAREHOUSE.ID
|
||||||
) {
|
) : BaseObservable() {
|
||||||
|
|
||||||
|
// 数据变化回调
|
||||||
|
var onDataChanged: (() -> Unit)? = null
|
||||||
|
|
||||||
// 件数的字符串表示(用于双向绑定)
|
// 件数的字符串表示(用于双向绑定)
|
||||||
|
@get:Bindable
|
||||||
var pcStr: String
|
var pcStr: String
|
||||||
get() = if (pc == 0L) "" else pc.toString()
|
get() = if (pc == 0L) "" else pc.toString()
|
||||||
set(value) {
|
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
|
var weightStr: String
|
||||||
get() = if (weight == 0.0) "" else weight.toString()
|
get() = if (weight == 0.0) "" else weight.toString()
|
||||||
set(value) {
|
set(value) {
|
||||||
weight = value.toDoubleOrNull() ?: 0.0
|
val newWeight = value.toDoubleOrNull() ?: 0.0
|
||||||
|
if (weight != newWeight) {
|
||||||
|
weight = newWeight
|
||||||
|
notifyPropertyChanged(BR.weightStr)
|
||||||
|
onDataChanged?.invoke()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.lukouguoji.gjc.activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.alibaba.android.arouter.facade.annotation.Route
|
import com.alibaba.android.arouter.facade.annotation.Route
|
||||||
import com.lukouguoji.gjc.R
|
import com.lukouguoji.gjc.R
|
||||||
@@ -24,6 +25,9 @@ class GjcWeighingRecordDetailsActivity :
|
|||||||
|
|
||||||
private lateinit var adapter: CommonAdapter
|
private lateinit var adapter: CommonAdapter
|
||||||
|
|
||||||
|
// 当前编辑模式(供ViewHolder获取)
|
||||||
|
var currentEditMode = false
|
||||||
|
|
||||||
override fun layoutId() = R.layout.activity_gjc_weighing_record_details
|
override fun layoutId() = R.layout.activity_gjc_weighing_record_details
|
||||||
|
|
||||||
override fun viewModelClass() = GjcWeighingRecordDetailsViewModel::class.java
|
override fun viewModelClass() = GjcWeighingRecordDetailsViewModel::class.java
|
||||||
@@ -34,7 +38,13 @@ class GjcWeighingRecordDetailsActivity :
|
|||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
// 初始化RecyclerView
|
// 初始化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(
|
adapter = CommonAdapter(
|
||||||
this,
|
this,
|
||||||
R.layout.item_gjc_check_in_record,
|
R.layout.item_gjc_check_in_record,
|
||||||
@@ -47,17 +57,13 @@ class GjcWeighingRecordDetailsActivity :
|
|||||||
adapter.refresh(records)
|
adapter.refresh(records)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听编辑模式变化,更新所有ViewHolder的编辑状态
|
// 监听编辑模式变化,更新当前编辑模式并刷新列表
|
||||||
viewModel.isEditMode.observe(this) { isEditMode ->
|
viewModel.isEditMode.observe(this) { isEditMode ->
|
||||||
val layoutManager = binding.recyclerView.layoutManager as? LinearLayoutManager
|
// 更新当前编辑模式状态
|
||||||
layoutManager?.let {
|
currentEditMode = isEditMode
|
||||||
for (i in 0 until adapter.itemCount) {
|
|
||||||
val holder = binding.recyclerView.findViewHolderForAdapterPosition(i)
|
// 刷新所有可见的 ViewHolder
|
||||||
as? GjcCheckInRecordViewHolder
|
adapter.notifyDataSetChanged()
|
||||||
holder?.updateEditMode(isEditMode)
|
|
||||||
adapter.notifyItemChanged(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.lukouguoji.gjc.holder
|
package com.lukouguoji.gjc.holder
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import com.lukouguoji.gjc.activity.GjcWeighingRecordDetailsActivity
|
||||||
import com.lukouguoji.gjc.databinding.ItemGjcCheckInRecordBinding
|
import com.lukouguoji.gjc.databinding.ItemGjcCheckInRecordBinding
|
||||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||||
import com.lukouguoji.module_base.bean.GjcCheckInRecord
|
import com.lukouguoji.module_base.bean.GjcCheckInRecord
|
||||||
@@ -11,14 +12,13 @@ import com.lukouguoji.module_base.bean.GjcCheckInRecord
|
|||||||
class GjcCheckInRecordViewHolder(view: View) :
|
class GjcCheckInRecordViewHolder(view: View) :
|
||||||
BaseViewHolder<GjcCheckInRecord, ItemGjcCheckInRecordBinding>(view) {
|
BaseViewHolder<GjcCheckInRecord, ItemGjcCheckInRecordBinding>(view) {
|
||||||
|
|
||||||
private var isEditMode: Boolean = false
|
|
||||||
|
|
||||||
fun updateEditMode(editMode: Boolean) {
|
|
||||||
this.isEditMode = editMode
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBind(item: Any?, position: Int) {
|
override fun onBind(item: Any?, position: Int) {
|
||||||
val record = getItemBean(item)!!
|
val record = getItemBean(item)!!
|
||||||
|
|
||||||
|
// 从Activity获取当前编辑模式
|
||||||
|
val activity = itemView.context as? GjcWeighingRecordDetailsActivity
|
||||||
|
val isEditMode = activity?.currentEditMode ?: false
|
||||||
|
|
||||||
binding.record = record
|
binding.record = record
|
||||||
binding.isEditMode = isEditMode
|
binding.isEditMode = isEditMode
|
||||||
binding.position = position // 传入位置用于显示序号
|
binding.position = position // 传入位置用于显示序号
|
||||||
|
|||||||
@@ -108,6 +108,15 @@ class GjcWeighingRecordDetailsViewModel : BaseViewModel() {
|
|||||||
launchLoadingCollect({ NetApply.api.getGjcCheckInRecordList(params) }) {
|
launchLoadingCollect({ NetApply.api.getGjcCheckInRecordList(params) }) {
|
||||||
onSuccess = { result ->
|
onSuccess = { result ->
|
||||||
val list = result.data ?: emptyList()
|
val list = result.data ?: emptyList()
|
||||||
|
|
||||||
|
// 为每个记录设置数据变化回调
|
||||||
|
list.forEach { record ->
|
||||||
|
record.onDataChanged = {
|
||||||
|
// 数据变化时重新计算统计
|
||||||
|
calculateStatistics()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
recordList.value = list
|
recordList.value = list
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
|
|||||||
@@ -166,15 +166,14 @@
|
|||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
<com.google.android.material.divider.MaterialDivider
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp" />
|
android:background="#e7e7e7"
|
||||||
|
android:layout_height="1px" />
|
||||||
|
|
||||||
<!-- 第二部分:计重记录列表 -->
|
<!-- 第二部分:计重记录列表 -->
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerView"
|
android:id="@+id/recyclerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingStart="15dp"
|
|
||||||
android:paddingEnd="15dp"
|
|
||||||
tools:listitem="@layout/item_gjc_check_in_record" />
|
tools:listitem="@layout/item_gjc_check_in_record" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@@ -227,7 +226,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@{`总件数:` + viewModel.totalPc}"
|
android:text="@{`总件数:` + viewModel.totalPc}"
|
||||||
android:textColor="@color/text_gray"
|
android:textColor="@color/text_gray"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
@@ -236,7 +235,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="20dp"
|
||||||
android:text="@{`总重量:` + viewModel.totalWeight}"
|
android:text="@{`总重量:` + viewModel.totalWeight}"
|
||||||
android:textColor="@color/text_gray"
|
android:textColor="@color/text_gray"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
@@ -245,7 +244,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="20dp"
|
android:layout_marginStart="20dp"
|
||||||
android:text="@{`重量误差: ` + viewModel.weightError}"
|
android:text="@{`重量误差:` + viewModel.weightError}"
|
||||||
android:textColor="@color/text_red"
|
android:textColor="@color/text_red"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user