feat: 出港组装 list

This commit is contained in:
2025-11-27 13:11:33 +08:00
parent bea8a8c8c8
commit 29b1875fa5
16 changed files with 1058 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
package com.lukouguoji.gjc.holder
import android.view.View
import com.lukouguoji.gjc.databinding.ItemAssembleWaybillDetailBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcWarehouse
/**
* 国际出港组装-运单明细ViewHolder
*/
class AssembleWaybillDetailViewHolder(view: View) :
BaseViewHolder<GjcWarehouse, ItemAssembleWaybillDetailBinding>(view) {
override fun onBind(item: Any?, position: Int) {
val bean = getItemBean(item) ?: return
binding.bean = bean
binding.position = position // 用于显示序号
binding.executePendingBindings()
}
}

View File

@@ -0,0 +1,137 @@
package com.lukouguoji.gjc.holder
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.Transformation
import androidx.recyclerview.widget.LinearLayoutManager
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ItemIntExpAssembleUldBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.bean.GjcUldUseBean
import com.lukouguoji.module_base.bean.GjcWarehouse
/**
* 国际出港组装-ULD列表ViewHolder
* 支持展开/收起运单明细
*/
class IntExpAssembleViewHolder(view: View) :
BaseViewHolder<GjcUldUseBean, ItemIntExpAssembleUldBinding>(view) {
private var waybillAdapter: CommonAdapter? = null
override fun onBind(item: Any?, position: Int) {
val bean = getItemBean(item) ?: return
binding.bean = bean
binding.position = position
// 初始化运单明细子列表
setupWaybillRecyclerView(bean)
// 更新展开状态(初次绑定不需要动画)
updateExpandState(bean, animate = false)
// 展开按钮点击事件
binding.btnExpand.setOnClickListener {
clickListener?.onItemClick(position, 1000) // type=1000表示展开操作
}
binding.executePendingBindings()
}
/**
* 初始化运单明细RecyclerView
*/
private fun setupWaybillRecyclerView(bean: GjcUldUseBean) {
if (binding.rvWaybillDetails.adapter == null) {
binding.rvWaybillDetails.layoutManager = LinearLayoutManager(itemView.context)
waybillAdapter = CommonAdapter(
itemView.context,
R.layout.item_assemble_waybill_detail,
AssembleWaybillDetailViewHolder::class.java
)
binding.rvWaybillDetails.adapter = waybillAdapter
}
// 刷新运单明细数据
waybillAdapter?.refresh(bean.waybillDetails ?: mutableListOf())
}
/**
* 更新展开状态
* @param bean ULD数据
* @param animate 是否显示动画
*/
private fun updateExpandState(bean: GjcUldUseBean, animate: Boolean = true) {
if (bean.isExpanded) {
// 展开
if (animate) {
expand(binding.llWaybillDetails)
} else {
binding.llWaybillDetails.visibility = View.VISIBLE
}
binding.btnExpand.text = "收起"
} else {
// 收起
if (animate) {
collapse(binding.llWaybillDetails)
} else {
binding.llWaybillDetails.visibility = View.GONE
}
binding.btnExpand.text = "展开"
}
}
/**
* 展开动画高度从0到wrap_content
*/
private fun expand(view: View) {
// 测量目标高度
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val targetHeight = view.measuredHeight
// 初始高度设为0
view.layoutParams.height = 0
view.visibility = View.VISIBLE
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
view.layoutParams.height = if (interpolatedTime == 1f) {
ViewGroup.LayoutParams.WRAP_CONTENT
} else {
(targetHeight * interpolatedTime).toInt()
}
view.requestLayout()
}
override fun willChangeBounds() = true
}
animation.duration = 300 // 动画时长300ms
view.startAnimation(animation)
}
/**
* 收起动画高度从当前到0
*/
private fun collapse(view: View) {
val initialHeight = view.measuredHeight
val animation = object : Animation() {
override fun applyTransformation(interpolatedTime: Float, t: Transformation?) {
if (interpolatedTime == 1f) {
view.visibility = View.GONE
} else {
view.layoutParams.height = initialHeight - (initialHeight * interpolatedTime).toInt()
view.requestLayout()
}
}
override fun willChangeBounds() = true
}
animation.duration = 300 // 动画时长300ms
view.startAnimation(animation)
}
}

View File

@@ -0,0 +1,40 @@
package com.lukouguoji.gjc.page.assemble
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityIntExpAssembleBinding
import com.lukouguoji.gjc.viewModel.IntExpAssembleViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.impl.observe
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.router.ARouterConstants
/**
* 国际出港-出港组装Activity
*/
@Route(path = ARouterConstants.ACTIVITY_URL_INT_EXP_ASSEMBLE)
class IntExpAssembleActivity :
BaseBindingActivity<ActivityIntExpAssembleBinding, IntExpAssembleViewModel>() {
override fun layoutId() = R.layout.activity_int_exp_assemble
override fun viewModelClass() = IntExpAssembleViewModel::class.java
override fun initOnCreate(savedInstanceState: Bundle?) {
setBackArrow("出港组装")
binding.viewModel = viewModel
// 绑定分页
viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)
// 设置item点击监听
binding.rv.addOnItemClickListener(viewModel)
// 监听刷新事件
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).observe(this) {
viewModel.refresh()
}
}
}

View File

@@ -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)
}
}
}