feat: 国际出港理货新增分单全选功能
底部栏新增「分单全选」按钮,与主单全选相互独立。 依据分页接口新增的 allTally 字段判断:主单存在分批申报(allTally=0)时跳过其分单, 只有主单全部申报完毕(allTally=1)才允许全选该主单下的分单,跳过时 toast 提示。 分单单个勾选后同步刷新分单全选状态。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,7 @@ data class GjcMaWb(
|
||||
var reviewStatus: String? = null, // 审核状态(0:未审核;1:通过;2:退回)
|
||||
var tranFlag: String? = null, // 转运标志
|
||||
var clearNormal: String? = null, // 清仓正常(0:否,1:是)
|
||||
var allTally: String? = null, // 运单理货申报全部通过(0:否;1:是),为 1 时才允许全选该主单下的分单
|
||||
|
||||
// ==================== 操作信息 ====================
|
||||
var opDate: String? = null, // 操作时间(入库时间)
|
||||
@@ -132,6 +133,13 @@ data class GjcMaWb(
|
||||
get() = checked.get()
|
||||
set(value) = checked.set(value)
|
||||
|
||||
/**
|
||||
* 是否允许全选该主单下的分单
|
||||
* 主单存在分批申报(未全部申报完毕)时接口返回 allTally=0,此时不允许全选其分单
|
||||
*/
|
||||
val canCheckAllHaWb: Boolean
|
||||
get() = allTally == "1"
|
||||
|
||||
// ==================== 状态转换扩展属性 ====================
|
||||
/**
|
||||
* 计重状态中文
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemIntExpTallySubBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcHaWb
|
||||
import com.lukouguoji.module_base.common.ConstantEvent
|
||||
import com.lukouguoji.module_base.impl.FlowBus
|
||||
|
||||
/**
|
||||
* 国际出港-出港理货 子订单(分单) ViewHolder
|
||||
@@ -20,6 +22,8 @@ class IntExpTallySubViewHolder(view: View) :
|
||||
// checkbox点击切换选择状态
|
||||
binding.ivCheckbox.setOnClickListener {
|
||||
bean.checked.set(!bean.checked.get())
|
||||
// 通知页面刷新分单全选状态
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).tryEmit("check_changed")
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ class IntExpTallyViewModel : BasePageViewModel() {
|
||||
val totalWeight = MutableLiveData("0") // 总重量
|
||||
|
||||
// ========== 全选状态 ==========
|
||||
val isAllChecked = MutableLiveData(false)
|
||||
val isAllChecked = MutableLiveData(false) // 主单全选状态
|
||||
val isAllHaWbChecked = MutableLiveData(false) // 分单全选状态(仅统计允许全选的主单下的分单)
|
||||
|
||||
fun onItemCheckChanged() {
|
||||
updateCheckAllStatus()
|
||||
@@ -51,6 +52,10 @@ class IntExpTallyViewModel : BasePageViewModel() {
|
||||
fun updateCheckAllStatus() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjcMaWb> ?: return
|
||||
isAllChecked.value = list.isNotEmpty() && list.all { it.checked.get() }
|
||||
|
||||
// 分单全选状态:只看允许全选的主单下的分单
|
||||
val eligibleHaWbList = list.filter { it.canCheckAllHaWb }.flatMap { it.haWbList ?: emptyList() }
|
||||
isAllHaWbChecked.value = eligibleHaWbList.isNotEmpty() && eligibleHaWbList.all { it.checked.get() }
|
||||
}
|
||||
|
||||
// ========== 全局展开状态 ==========
|
||||
@@ -86,6 +91,43 @@ class IntExpTallyViewModel : BasePageViewModel() {
|
||||
pageModel.rv?.commonAdapter()?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 分单全选按钮点击 (只切换分单的选中状态,主单选择独立)
|
||||
* 规则:主单存在分批申报(接口 allTally=0)时,不允许选中该主单下的分单;
|
||||
* 只有主单全部申报完毕(allTally=1)才允许全选其分单。
|
||||
*/
|
||||
fun checkAllHaWbClick() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjcMaWb> ?: return
|
||||
|
||||
val shouldCheckAll = !isAllHaWbChecked.value!!
|
||||
var eligibleCount = 0 // 允许全选的分单数
|
||||
var skippedMaWbCount = 0 // 因未全部申报而跳过的主单数
|
||||
|
||||
list.forEach { maWb ->
|
||||
val haWbList = maWb.haWbList
|
||||
if (haWbList.isNullOrEmpty()) return@forEach
|
||||
if (maWb.canCheckAllHaWb) {
|
||||
eligibleCount += haWbList.size
|
||||
haWbList.forEach { it.checked.set(shouldCheckAll) }
|
||||
} else if (shouldCheckAll) {
|
||||
// 主单未全部申报完毕,跳过其分单(保持原有选中状态不变)
|
||||
skippedMaWbCount++
|
||||
}
|
||||
}
|
||||
|
||||
isAllHaWbChecked.value = shouldCheckAll && eligibleCount > 0
|
||||
|
||||
if (shouldCheckAll) {
|
||||
if (eligibleCount == 0) {
|
||||
showToast("暂无可全选的分单,主单需全部申报完毕后才可全选其分单")
|
||||
} else if (skippedMaWbCount > 0) {
|
||||
showToast("有${skippedMaWbCount}票主单未全部申报完毕,其分单未选中")
|
||||
}
|
||||
}
|
||||
|
||||
pageModel.rv?.commonAdapter()?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换全局展开/收起状态
|
||||
*/
|
||||
|
||||
@@ -167,6 +167,32 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 分单全选按钮(仅选中已全部申报完毕的主单下的分单) -->
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:onClick="@{()-> viewModel.checkAllHaWbClick()}"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
setIVCheckAllImage="@{viewModel.isAllHaWbChecked}"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:src="@drawable/img_check_all_unchecked" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="分单全选"
|
||||
android:textColor="@color/color_66"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 统计信息 -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
|
||||
Reference in New Issue
Block a user