feat: 国际进港舱单主分单独立选择及分离删除接口
主分单选择解除联动,删除操作使用独立接口,先删分单再删主单 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package com.lukouguoji.gjj.holder
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lukouguoji.gjj.databinding.ItemIntImpManifestSubBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjjHaWb
|
||||
import com.lukouguoji.module_base.bean.GjjManifest
|
||||
|
||||
/**
|
||||
* 国际进港舱单 - 分单子列表 ViewHolder
|
||||
@@ -24,13 +22,6 @@ class IntImpManifestSubViewHolder(view: View) :
|
||||
val newCheckedState = !bean.checked.get()
|
||||
bean.checked.set(newCheckedState)
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 反向联动主列表项(勾选子项时自动勾选父项)
|
||||
if (newCheckedState) {
|
||||
val recyclerView = itemView.parent as? RecyclerView ?: return@setOnClickListener
|
||||
val parentBean = recyclerView.tag as? GjjManifest ?: return@setOnClickListener
|
||||
parentBean.checked.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,7 @@ class IntImpManifestViewHolder(view: View) :
|
||||
binding.ivIcon.setOnClickListener {
|
||||
val newCheckedState = !bean.checked.get()
|
||||
bean.checked.set(newCheckedState)
|
||||
// 联动子列表选中状态
|
||||
bean.haWbList?.forEach { sub -> sub.checked.set(newCheckedState) }
|
||||
binding.executePendingBindings()
|
||||
binding.rvSub.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
// 整卡点击 - 跳转详情页
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.lukouguoji.gjj.activity.GjjManifestAddActivity
|
||||
import com.lukouguoji.gjj.activity.IntImpManifestSubEditActivity
|
||||
import com.lukouguoji.gjj.holder.IntImpManifestViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
import com.lukouguoji.module_base.bean.GjjHaWb
|
||||
import com.lukouguoji.module_base.bean.GjjManifest
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
import com.lukouguoji.module_base.common.ConstantEvent
|
||||
@@ -121,18 +122,6 @@ class IntImpManifestViewModel : BasePageViewModel() {
|
||||
// ========== 分单管理模式 ==========
|
||||
val isSubManagementMode = MutableLiveData(false)
|
||||
|
||||
init {
|
||||
// 监听全选状态,自动更新所有列表项(联动子列表)
|
||||
isAllChecked.observeForever { checked ->
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjjManifest> ?: return@observeForever
|
||||
list.forEach {
|
||||
it.checked.set(checked)
|
||||
it.haWbList?.forEach { sub -> sub.checked.set(checked) }
|
||||
}
|
||||
pageModel.rv?.commonAdapter()?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntImpManifestViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_imp_manifest
|
||||
@@ -312,7 +301,7 @@ class IntImpManifestViewModel : BasePageViewModel() {
|
||||
message = "确定要删除运单号 ${bean.getWaybillNo()} 的舱单吗?",
|
||||
title = "提示"
|
||||
) {
|
||||
doDeleteByIds(listOf(bean.mfId))
|
||||
doDelete(listOf(bean), emptyList())
|
||||
}.show()
|
||||
}
|
||||
|
||||
@@ -321,37 +310,67 @@ class IntImpManifestViewModel : BasePageViewModel() {
|
||||
*/
|
||||
fun onDeleteClick() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjjManifest> ?: return
|
||||
val selectedItems = list.filter { it.isSelected }
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
val selectedManifests = list.filter { it.isSelected }
|
||||
val selectedHawbs = list.flatMap { it.haWbList?.filter { hawb -> hawb.isSelected } ?: emptyList() }
|
||||
|
||||
if (selectedManifests.isEmpty() && selectedHawbs.isEmpty()) {
|
||||
showToast("请选择要删除的记录")
|
||||
return
|
||||
}
|
||||
|
||||
// 构建确认提示信息
|
||||
val msgParts = mutableListOf<String>()
|
||||
if (selectedManifests.isNotEmpty()) {
|
||||
msgParts.add("${selectedManifests.size} 条主单")
|
||||
}
|
||||
if (selectedHawbs.isNotEmpty()) {
|
||||
msgParts.add("${selectedHawbs.size} 条分单")
|
||||
}
|
||||
|
||||
ConfirmDialogModel(
|
||||
message = "确定要删除选中的 ${selectedItems.size} 条舱单吗?",
|
||||
message = "确定要删除选中的 ${msgParts.joinToString("和")} 吗?",
|
||||
title = "批量删除确认"
|
||||
) {
|
||||
doDeleteByIds(selectedItems.map { it.mfId })
|
||||
doDelete(selectedManifests, selectedHawbs)
|
||||
}.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行批量删除(统一接口,请求体为 mfId 数组)
|
||||
* 执行删除:先删分单,再删主单(串行执行)
|
||||
*/
|
||||
private fun doDeleteByIds(mfIds: List<Long>) {
|
||||
launchLoadingCollect({ NetApply.api.gjjManifestDeleteBatch(mfIds.toRequestBody()) }) {
|
||||
onSuccess = {
|
||||
if (it.verifySuccess()) {
|
||||
showToast("删除成功")
|
||||
isAllChecked.value = false
|
||||
viewModelScope.launch {
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
private fun doDelete(manifests: List<GjjManifest>, hawbs: List<GjjHaWb>) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
showLoading()
|
||||
|
||||
// 第一步:删除分单(如果有选中的分单)
|
||||
if (hawbs.isNotEmpty()) {
|
||||
val hawbResult = NetApply.api.intImpManifestDeleteHawb(hawbs.toRequestBody())
|
||||
if (!hawbResult.verifySuccess()) {
|
||||
showToast(hawbResult.msg.noNull("分单删除失败"))
|
||||
refresh()
|
||||
return@launch
|
||||
}
|
||||
refresh()
|
||||
} else {
|
||||
showToast(it.msg.noNull("删除失败"))
|
||||
}
|
||||
|
||||
// 第二步:删除主单(分单删除成功后才执行)
|
||||
if (manifests.isNotEmpty()) {
|
||||
val manifestResult = NetApply.api.intImpManifestDeleteManifest(manifests.toRequestBody())
|
||||
if (!manifestResult.verifySuccess()) {
|
||||
showToast(manifestResult.msg.noNull("分单已删除,但主单删除失败"))
|
||||
refresh()
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
|
||||
showToast("删除成功")
|
||||
isAllChecked.value = false
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
} catch (e: Exception) {
|
||||
showToast("删除失败:${e.message}")
|
||||
} finally {
|
||||
dismissLoading()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user