feat: 国际出港 出港组装 列表
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.lukouguoji.gjc.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.databinding.ItemIntExpAssembleBinding
|
||||
import com.lukouguoji.module_base.adapter.setCommonAdapter
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcUldUseBean
|
||||
import com.lukouguoji.module_base.ktx.refresh
|
||||
|
||||
/**
|
||||
* 国际出港-出港组装 列表项ViewHolder
|
||||
* 参考出港运抵页面的实现
|
||||
*/
|
||||
class IntExpAssembleItemViewHolder(view: View) :
|
||||
BaseViewHolder<GjcUldUseBean, ItemIntExpAssembleBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 添加图标点击事件 - 切换选择状态
|
||||
binding.ivIcon.setOnClickListener {
|
||||
// 反转checked状态
|
||||
bean.checked.set(!bean.checked.get())
|
||||
|
||||
// 立即更新UI(图片自动切换)
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
// ========== 展开按钮点击事件 ==========
|
||||
// 通过回调通知ViewModel处理展开逻辑(需要加载数据)
|
||||
binding.ivShow.setOnClickListener {
|
||||
clickListener?.onItemClick(position, 1000) // type=1000表示展开操作
|
||||
}
|
||||
|
||||
// ========== 初始化子列表 RecyclerView ==========
|
||||
setCommonAdapter(
|
||||
binding.rvSub,
|
||||
IntExpAssembleSubViewHolder::class.java,
|
||||
R.layout.item_int_exp_assemble_sub
|
||||
)
|
||||
|
||||
// 刷新子列表数据
|
||||
binding.rvSub.refresh(bean.waybillDetails ?: emptyList())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.lukouguoji.gjc.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemIntExpAssembleSubBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcWarehouse
|
||||
|
||||
/**
|
||||
* 国际出港-出港组装 子列表ViewHolder
|
||||
* 显示运单明细信息
|
||||
*/
|
||||
class IntExpAssembleSubViewHolder(view: View) :
|
||||
BaseViewHolder<GjcWarehouse, ItemIntExpAssembleSubBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position + 1 // 序号从1开始
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.holder.IntExpAssembleViewHolder
|
||||
import com.lukouguoji.gjc.holder.IntExpAssembleItemViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
import com.lukouguoji.module_base.bean.GjcUldUseBean
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
@@ -20,7 +20,7 @@ import com.lukouguoji.module_base.ktx.verifyNullOrEmpty
|
||||
import com.lukouguoji.module_base.router.ARouterConstants
|
||||
import dev.utils.app.info.KeyValue
|
||||
import dev.utils.common.DateUtils
|
||||
import com.lukouguoji.module_base.ktx.formatDate
|
||||
import com.lukouguoji.module_base.ktx.formatDate
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@@ -45,8 +45,8 @@ class IntExpAssembleViewModel : BasePageViewModel() {
|
||||
val assemblerList = MutableLiveData<List<KeyValue>>(emptyList()) // 组装人列表
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntExpAssembleViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_assemble_uld
|
||||
val itemViewHolder = IntExpAssembleItemViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_assemble
|
||||
|
||||
// ========== 底部统计 ==========
|
||||
val totalCount = MutableLiveData("0") // 合计票数
|
||||
@@ -77,33 +77,54 @@ class IntExpAssembleViewModel : BasePageViewModel() {
|
||||
|
||||
/**
|
||||
* 切换展开/收起状态
|
||||
* 首次展开时加载运单明细数据
|
||||
*/
|
||||
fun toggleExpand(position: Int) {
|
||||
val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjcUldUseBean ?: return
|
||||
bean.isExpanded = !bean.isExpanded
|
||||
val isCurrentlyExpanded = bean.showMore.get()
|
||||
|
||||
if (bean.isExpanded && bean.waybillDetails == null) {
|
||||
// 首次展开,加载运单明细
|
||||
loadWaybillDetails(position, bean)
|
||||
if (isCurrentlyExpanded) {
|
||||
// 当前是展开状态,收起
|
||||
bean.showMore.set(false)
|
||||
} else {
|
||||
// 已有数据,直接刷新item显示/隐藏
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
// 当前是收起状态,展开
|
||||
bean.showMore.set(true)
|
||||
// 如果未加载过数据,则加载
|
||||
if (!bean.waybillDetailsLoaded) {
|
||||
loadWaybillDetails(position, bean)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载运单明细
|
||||
* 使用接口: /IntExpAssemble/queryAssembledByUld
|
||||
*/
|
||||
private fun loadWaybillDetails(position: Int, bean: GjcUldUseBean) {
|
||||
val params = mapOf("useId" to bean.useId).toRequestBody()
|
||||
// 设置加载中状态
|
||||
bean.isLoading.set(true)
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
|
||||
launchCollect({ NetApply.api.getIntExpAssembleWaybillDetails(params) }) {
|
||||
// 构建请求参数 - 传递完整的GjcUldUseBean信息
|
||||
val params = mapOf(
|
||||
"useId" to bean.useId,
|
||||
"uld" to bean.uld,
|
||||
"fdate" to bean.fdate,
|
||||
"fno" to bean.fno
|
||||
).toRequestBody()
|
||||
|
||||
launchCollect({ NetApply.api.getAssembledWaybillsByUld(params) }) {
|
||||
onSuccess = { result ->
|
||||
bean.waybillDetails = result.data ?: mutableListOf()
|
||||
bean.waybillDetails = result.data?.toMutableList()
|
||||
bean.waybillDetailsLoaded = true
|
||||
bean.isLoading.set(false)
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
}
|
||||
onFailed = { _, msg ->
|
||||
bean.isExpanded = false // 加载失败,恢复展开状态
|
||||
bean.waybillDetailsLoaded = true // 标记为已加载(即使失败也显示暂无数据)
|
||||
bean.waybillDetails = mutableListOf() // 设置空列表
|
||||
bean.isLoading.set(false)
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
showToast(msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user