feat: opt ui
This commit is contained in:
@@ -13,6 +13,7 @@ import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.ktx.noNull
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
import com.lukouguoji.module_base.util.CheckUtil
|
||||
import dev.utils.app.info.KeyValue
|
||||
|
||||
/**
|
||||
@@ -50,6 +51,9 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
val totalPieces = MutableLiveData("0") // 总件数
|
||||
val totalWeight = MutableLiveData("0") // 总重量
|
||||
|
||||
// ========== 全选状态 ==========
|
||||
val isAllChecked = MutableLiveData(false)
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntExpMoveViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_move
|
||||
@@ -74,18 +78,44 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
fun toggleSelectAll() {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val list = adapter.items.filterIsInstance<GjcMove>()
|
||||
val allSelected = list.all { it.isSelected }
|
||||
|
||||
list.forEach { it.isSelected = !allSelected }
|
||||
// 使用CheckUtil处理全选逻辑
|
||||
CheckUtil.handleAllCheck(list)
|
||||
|
||||
// 更新全选状态
|
||||
updateCheckAllStatus()
|
||||
|
||||
// 刷新UI
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新全选状态
|
||||
*/
|
||||
fun updateCheckAllStatus() {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val list = adapter.items.filterIsInstance<GjcMove>()
|
||||
|
||||
if (list.isNotEmpty()) {
|
||||
isAllChecked.value = list.all { it.checked.get() }
|
||||
} else {
|
||||
isAllChecked.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个item选择变化时调用(从Activity接收事件)
|
||||
*/
|
||||
fun onItemCheckChanged() {
|
||||
updateCheckAllStatus()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的运单
|
||||
*/
|
||||
fun getSelectedItems(): List<GjcMove> {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return emptyList()
|
||||
return adapter.items.filterIsInstance<GjcMove>().filter { it.isSelected }
|
||||
return adapter.items.filterIsInstance<GjcMove>().filter { it.checked.get() }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,11 +188,9 @@ class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Item点击事件处理(用于单选CheckBox)
|
||||
* Item点击事件处理(现已改为图标点击,此方法暂时保留兼容)
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjcMove ?: return
|
||||
bean.isSelected = !bean.isSelected
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
// 图标点击已在ViewHolder中处理,此处不再需要
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user