feat: 国际出港 出港组装 列表
This commit is contained in:
@@ -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