feat: 出港组装 list
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package com.lukouguoji.gjc.viewModel
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.holder.IntExpAssembleViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
import com.lukouguoji.module_base.bean.GjcUldUseBean
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
import com.lukouguoji.module_base.ktx.commonAdapter
|
||||
import com.lukouguoji.module_base.ktx.launchCollect
|
||||
import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
import dev.utils.app.info.KeyValue
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 国际出港-出港组装ViewModel
|
||||
*/
|
||||
class IntExpAssembleViewModel : BasePageViewModel() {
|
||||
|
||||
// ========== 搜索条件 ==========
|
||||
val flightDate = MutableLiveData("") // 航班日期
|
||||
val flightNo = MutableLiveData("") // 航班号
|
||||
val uldNo = MutableLiveData("") // ULD编号
|
||||
val reweighStatus = MutableLiveData("全部") // 复磅状态
|
||||
val reweighStatusList = MutableLiveData( // 复磅状态选项
|
||||
listOf(
|
||||
KeyValue("全部", "全部"),
|
||||
KeyValue("未复磅", "未复磅"),
|
||||
KeyValue("已复磅", "已复磅")
|
||||
)
|
||||
)
|
||||
val assembler = MutableLiveData("") // 组装人
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntExpAssembleViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_assemble_uld
|
||||
|
||||
// ========== 底部统计 ==========
|
||||
val totalCount = MutableLiveData("0") // 合计票数
|
||||
val totalPieces = MutableLiveData("0") // 总件数
|
||||
val totalWeight = MutableLiveData("0") // 总重量
|
||||
|
||||
/**
|
||||
* 搜索按钮点击
|
||||
*/
|
||||
fun searchClick() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换展开/收起状态
|
||||
*/
|
||||
fun toggleExpand(position: Int) {
|
||||
val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjcUldUseBean ?: return
|
||||
bean.isExpanded = !bean.isExpanded
|
||||
|
||||
if (bean.isExpanded && bean.waybillDetails == null) {
|
||||
// 首次展开,加载运单明细
|
||||
loadWaybillDetails(position, bean)
|
||||
} else {
|
||||
// 已有数据,直接刷新item显示/隐藏
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载运单明细
|
||||
*/
|
||||
private fun loadWaybillDetails(position: Int, bean: GjcUldUseBean) {
|
||||
val params = mapOf("useId" to bean.useId).toRequestBody()
|
||||
|
||||
launchCollect({ NetApply.api.getIntExpAssembleWaybillDetails(params) }) {
|
||||
onSuccess = { result ->
|
||||
bean.waybillDetails = result.data ?: mutableListOf()
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
}
|
||||
onFailed = { _, msg ->
|
||||
bean.isExpanded = false // 加载失败,恢复展开状态
|
||||
showToast(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据(列表 + 统计)
|
||||
*/
|
||||
override fun getData() {
|
||||
// 构建筛选参数
|
||||
val filterParams = mapOf(
|
||||
"fdate" to flightDate.value!!.ifEmpty { null },
|
||||
"fno" to flightNo.value!!.ifEmpty { null },
|
||||
"uld" to uldNo.value!!.ifEmpty { null },
|
||||
"ldUserName" to assembler.value!!.ifEmpty { null }
|
||||
)
|
||||
|
||||
// 列表参数(含分页)
|
||||
val listParams = (filterParams + mapOf(
|
||||
"pageNum" to pageModel.page,
|
||||
"pageSize" to pageModel.limit
|
||||
)).toRequestBody()
|
||||
|
||||
// 统计参数(无分页)
|
||||
val totalParams = filterParams.toRequestBody()
|
||||
|
||||
// 获取列表(显示loading)
|
||||
launchLoadingCollect({ NetApply.api.getIntExpAssembleList(listParams) }) {
|
||||
onSuccess = { pageModel.handleListBean(it) }
|
||||
}
|
||||
|
||||
// 获取统计(后台调用)
|
||||
launchCollect({ NetApply.api.getIntExpAssembleTotal(totalParams) }) {
|
||||
onSuccess = { result ->
|
||||
val data = result.data
|
||||
totalCount.value = (data?.wbNumber ?: 0).toString()
|
||||
totalPieces.value = (data?.totalPc ?: 0).toString()
|
||||
totalWeight.value = (data?.totalWeight ?: 0.0).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item点击事件处理
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
if (type == 1000) { // 展开/收起操作
|
||||
toggleExpand(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user