feat: 国际进港理货报告展开子单功能及舱单展开优化
- 理货报告列表增加展开分单功能(嵌套子列表、全选联动) - 运单号搜索框增加自动查询(4位触发) - 舱单/理货展开查询传递完整主单参数 - 统一空数据展示为"暂无分单数据"UI Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,29 @@ class IntImpManifestViewHolder(view: View) :
|
||||
|
||||
// 设置父Bean引用(用于子列表反向联动)
|
||||
binding.rvSub.tag = bean
|
||||
binding.rvSub.refresh(bean.haWbList ?: emptyList())
|
||||
val subList = bean.haWbList ?: emptyList()
|
||||
binding.rvSub.refresh(subList)
|
||||
updateSubListVisibility(bean.haWbList != null, subList.isNotEmpty())
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分单数据状态,切换表头/列表与空数据提示的显隐
|
||||
* @param loaded 是否已加载过数据(haWbList != null)
|
||||
* @param hasData 是否有数据
|
||||
*/
|
||||
private fun updateSubListVisibility(loaded: Boolean, hasData: Boolean) {
|
||||
if (!loaded || hasData) {
|
||||
// 未加载或有数据:显示表头+列表,隐藏空提示
|
||||
binding.llHeader.visibility = View.VISIBLE
|
||||
binding.dividerHeader.visibility = View.VISIBLE
|
||||
binding.rvSub.visibility = View.VISIBLE
|
||||
binding.tvEmpty.visibility = View.GONE
|
||||
} else {
|
||||
// 已加载但无数据:隐藏表头+列表,显示空提示
|
||||
binding.llHeader.visibility = View.GONE
|
||||
binding.dividerHeader.visibility = View.GONE
|
||||
binding.rvSub.visibility = View.GONE
|
||||
binding.tvEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.lukouguoji.gjj.holder
|
||||
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lukouguoji.gjj.databinding.ItemIntImpTallySubBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjjImportTally
|
||||
|
||||
/**
|
||||
* 国际进港理货报告 分单子列表 ViewHolder
|
||||
*/
|
||||
class IntImpTallySubViewHolder(view: View) :
|
||||
BaseViewHolder<GjjImportTally, ItemIntImpTallySubBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 单选框点击切换选择状态(反向联动主列表)
|
||||
binding.ivCheckbox.setOnClickListener {
|
||||
val newCheckedState = !bean.checked.get()
|
||||
bean.checked.set(newCheckedState)
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 反向联动主列表项(勾选时联动主项也勾选)
|
||||
updateParentCheckState(newCheckedState)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新父列表项的选择状态
|
||||
*/
|
||||
private fun updateParentCheckState(newCheckedState: Boolean) {
|
||||
val recyclerView = itemView.parent as? RecyclerView ?: return
|
||||
val parentBean = recyclerView.tag as? GjjImportTally ?: return
|
||||
|
||||
if (newCheckedState) {
|
||||
parentBean.checked.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package com.lukouguoji.gjj.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjj.R
|
||||
import com.lukouguoji.gjj.databinding.ItemIntImpTallyBinding
|
||||
import com.lukouguoji.module_base.adapter.setCommonAdapter
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjjImportTally
|
||||
import com.google.gson.Gson
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
import com.lukouguoji.module_base.ktx.launchCollect
|
||||
import com.lukouguoji.module_base.ktx.refresh
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
|
||||
/**
|
||||
* 国际进港理货报告 ViewHolder
|
||||
@@ -17,10 +24,79 @@ class IntImpTallyViewHolder(view: View) :
|
||||
binding.position = position
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 选中图标点击 - 切换选择状态
|
||||
// 选中图标点击 - 切换选择状态(联动子列表)
|
||||
binding.ivIcon.setOnClickListener {
|
||||
bean.checked.set(!bean.checked.get())
|
||||
val newCheckedState = !bean.checked.get()
|
||||
bean.checked.set(newCheckedState)
|
||||
|
||||
// 联动勾选/取消所有子列表项
|
||||
bean.haWbList?.forEach { sub ->
|
||||
sub.checked.set(newCheckedState)
|
||||
}
|
||||
|
||||
binding.executePendingBindings()
|
||||
binding.rvSub.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
// 展开按钮点击事件
|
||||
binding.ivShow.setOnClickListener {
|
||||
if (bean.haWbList != null) {
|
||||
// 已加载过数据,直接切换显隐
|
||||
bean.showMore.set(!bean.showMore.get())
|
||||
} else {
|
||||
// 首次展开,调用接口加载分单数据
|
||||
loadSubList(bean)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化分单子列表 RecyclerView
|
||||
setCommonAdapter(
|
||||
binding.rvSub,
|
||||
IntImpTallySubViewHolder::class.java,
|
||||
R.layout.item_int_imp_tally_sub
|
||||
)
|
||||
|
||||
// 刷新分单数据(传递父Bean引用用于反向联动)
|
||||
binding.rvSub.tag = bean
|
||||
val subList = bean.haWbList ?: emptyList()
|
||||
binding.rvSub.refresh(subList)
|
||||
updateSubListVisibility(subList.isNotEmpty())
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载分单列表数据(将主单整体作为请求参数)
|
||||
*/
|
||||
private fun loadSubList(bean: GjjImportTally) {
|
||||
// 将 bean 转为 Map 并补充 wbNo 字段(prefix + no)
|
||||
val map = Gson().fromJson(Gson().toJson(bean), HashMap::class.java) as HashMap<String, Any?>
|
||||
map["wbNo"] = bean.getWaybillNo()
|
||||
val params = map.toRequestBody()
|
||||
|
||||
launchCollect({ NetApply.api.getIntImpTallySubList(params) }) {
|
||||
onSuccess = { result ->
|
||||
val list = result.data?.toMutableList() ?: mutableListOf()
|
||||
bean.haWbList = list
|
||||
bean.showMore.set(true)
|
||||
binding.rvSub.refresh(list)
|
||||
updateSubListVisibility(list.isNotEmpty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分单数据是否为空,切换表头/列表与空数据提示的显隐
|
||||
*/
|
||||
private fun updateSubListVisibility(hasData: Boolean) {
|
||||
if (hasData) {
|
||||
binding.llHeader.visibility = View.VISIBLE
|
||||
binding.dividerHeader.visibility = View.VISIBLE
|
||||
binding.rvSub.visibility = View.VISIBLE
|
||||
binding.tvEmpty.visibility = View.GONE
|
||||
} else {
|
||||
binding.llHeader.visibility = View.GONE
|
||||
binding.dividerHeader.visibility = View.GONE
|
||||
binding.rvSub.visibility = View.GONE
|
||||
binding.tvEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user