feat: 国际出港组装分配

This commit is contained in:
2025-12-04 14:12:30 +08:00
parent 18e6258a40
commit 266fafb898
12 changed files with 745 additions and 9 deletions

View File

@@ -0,0 +1,66 @@
package com.lukouguoji.gjc.activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityGjcAssembleAllocateBinding
import com.lukouguoji.gjc.viewModel.GjcAssembleAllocateViewModel
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.getLifecycleOwner
import com.lukouguoji.module_base.router.ARouterConstants
/**
* 国际出港组装分配列表页
*/
@Route(path = ARouterConstants.ACTIVITY_URL_GJC_ASSEMBLE_ALLOCATE)
class GjcAssembleAllocateActivity :
BaseBindingActivity<ActivityGjcAssembleAllocateBinding, GjcAssembleAllocateViewModel>() {
override fun layoutId() = R.layout.activity_gjc_assemble_allocate
override fun viewModelClass() = GjcAssembleAllocateViewModel::class.java
override fun initOnCreate(savedInstanceState: Bundle?) {
setBackArrow("组装分配")
binding.viewModel = viewModel
// 绑定分页逻辑
viewModel.pageModel
.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, getLifecycleOwner())
// 监听刷新事件
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH)
.observe(this) {
viewModel.refresh()
}
// 监听checkbox状态变化事件
FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED)
.observe(this) {
viewModel.onItemCheckChanged()
}
// 监听全选状态变化,更新图标
viewModel.isAllChecked.observe(this) { isAllChecked ->
// 通过alpha值表示全选状态全选时alpha=1.0未全选时alpha=0.5
binding.checkIcon.alpha = if (isAllChecked) 1.0f else 0.5f
}
// 初始加载
viewModel.refresh()
}
companion object {
@JvmStatic
fun start(context: Context) {
val starter = Intent(context, GjcAssembleAllocateActivity::class.java)
context.startActivity(starter)
}
}
}

View File

@@ -0,0 +1,26 @@
package com.lukouguoji.gjc.holder
import android.view.View
import com.lukouguoji.gjc.databinding.ItemGjcAssembleAllocateBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcAssembleAllocate
/**
* 国际出港组装分配列表ViewHolder
*/
class GjcAssembleAllocateViewHolder(view: View) :
BaseViewHolder<GjcAssembleAllocate, ItemGjcAssembleAllocateBinding>(view) {
override fun onBind(item: Any?, position: Int) {
val bean = getItemBean(item) ?: return
binding.bean = bean
binding.executePendingBindings()
// 选中图标点击事件
binding.ivIcon.setOnClickListener {
bean.checked.set(!bean.checked.get())
// 通知adapter刷新item
binding.executePendingBindings()
}
}
}

View File

@@ -0,0 +1,195 @@
package com.lukouguoji.gjc.viewModel
import android.app.AlertDialog
import android.widget.EditText
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.holder.GjcAssembleAllocateViewHolder
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.GjcAssembleAllocate
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.impl.FlowBus
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 com.lukouguoji.module_base.util.CheckUtil
import kotlinx.coroutines.launch
/**
* 国际出港组装分配 ViewModel
*/
class GjcAssembleAllocateViewModel : BasePageViewModel() {
// 搜索条件
val flightDate = MutableLiveData("") // 航班日期
val flightNo = MutableLiveData("") // 航班号
val destAirport = MutableLiveData("") // 目的站
val assembler = MutableLiveData("") // 组装人
val allocator = MutableLiveData("") // 分配人
// 适配器配置
val itemViewHolder = GjcAssembleAllocateViewHolder::class.java
val itemLayoutId = R.layout.item_gjc_assemble_allocate
// 统计数据
val totalCount = MutableLiveData("0") // 合计票数
val totalPc = MutableLiveData("0") // 总件数
val totalWeight = MutableLiveData("0") // 总重量
// 全选状态
val isAllChecked = MutableLiveData(false)
///////////////////////////////////////////////////////////////////////////
// 方法区
///////////////////////////////////////////////////////////////////////////
/**
* 搜索按钮点击
*/
fun searchClick() {
refresh()
}
/**
* 获取列表数据
*/
override fun getData() {
// 构建查询参数(列表接口)
val listParams = mapOf(
"page" to pageModel.page,
"limit" to pageModel.limit,
"fdate" to flightDate.value!!.ifEmpty { null },
"fno" to flightNo.value!!.ifEmpty { null },
"dest" to destAirport.value!!.ifEmpty { null },
"abId" to assembler.value!!.ifEmpty { null },
"acName" to allocator.value!!.ifEmpty { null }
).toRequestBody()
// 构建查询参数(统计接口 - 使用相同的搜索条件)
val totalParams = mapOf(
"fdate" to flightDate.value!!.ifEmpty { null },
"fno" to flightNo.value!!.ifEmpty { null },
"dest" to destAirport.value!!.ifEmpty { null },
"abId" to assembler.value!!.ifEmpty { null },
"acName" to allocator.value!!.ifEmpty { null }
).toRequestBody()
// 获取列表数据显示loading
launchLoadingCollect({
NetApply.api.getGjcAssembleAllocateList(listParams)
}) {
onSuccess = { result ->
// 将 PageInfo 转换为 BaseListBean
result.data?.let { pageModel.handleListBean(it.toBaseListBean()) }
}
}
// 获取统计数据后台调用不显示loading
launchCollect({
NetApply.api.getGjcAssembleAllocateTotal(totalParams)
}) {
onSuccess = { result ->
val data = result.data
totalCount.value = (data?.wbNumber ?: 0).toString()
totalPc.value = (data?.totalPc ?: 0).toString()
totalWeight.value = (data?.totalWeight ?: 0.0).toString()
}
}
}
/**
* 全选/全不选
*/
fun checkAllClick() {
val list = pageModel.rv!!.commonAdapter()!!.items as List<GjcAssembleAllocate>
CheckUtil.handleAllCheck(list)
updateCheckAllStatus()
}
/**
* 更新全选状态
*/
fun updateCheckAllStatus() {
val list = pageModel.rv?.commonAdapter()?.items as? List<GjcAssembleAllocate>
if (list != null && list.isNotEmpty()) {
isAllChecked.value = list.all { it.checked.get() }
} else {
isAllChecked.value = false
}
}
/**
* 单个item点击事件用于更新全选状态
*/
fun onItemCheckChanged() {
updateCheckAllStatus()
}
/**
* 分配按钮点击
*/
fun allocateClick() {
val list = pageModel.rv!!.commonAdapter()!!.items as List<GjcAssembleAllocate>
val selectedItems = list.filter { it.checked.get() }
if (selectedItems.isEmpty()) {
showToast("请选择要分配的航班")
return
}
// 显示分配人输入对话框
showAllocatorInputDialog(selectedItems)
}
/**
* 显示分配人输入对话框
*/
private fun showAllocatorInputDialog(items: List<GjcAssembleAllocate>) {
val activity = getTopActivity()
val editText = EditText(activity)
editText.hint = "请输入分配人姓名"
AlertDialog.Builder(activity)
.setTitle("分配人员")
.setView(editText)
.setPositiveButton("确定") { dialog, _ ->
val allocatorName = editText.text.toString().trim()
if (allocatorName.isEmpty()) {
showToast("请输入分配人姓名")
} else {
performAllocate(items, allocatorName)
dialog.dismiss()
}
}
.setNegativeButton("取消") { dialog, _ ->
dialog.dismiss()
}
.show()
}
/**
* 执行分配操作
*/
private fun performAllocate(items: List<GjcAssembleAllocate>, allocatorName: String) {
val fidList = items.mapNotNull { it.fid }
val requestData = mapOf(
"fidList" to fidList, // 航班ID列表
"acName" to allocatorName // 分配人姓名
).toRequestBody()
launchLoadingCollect({ NetApply.api.allocateAssemble(requestData) }) {
onSuccess = {
showToast("分配成功")
viewModelScope.launch {
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
}
refresh()
}
}
}
}