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

View File

@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="com.lukouguoji.module_base.ui.weight.search.layout.SearchLayoutType" />
<variable
name="viewModel"
type="com.lukouguoji.gjc.viewModel.GjcAssembleAllocateViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_f2"
android:orientation="vertical">
<include layout="@layout/title_tool_bar" />
<!-- 搜索区域 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<!-- 航班日期 -->
<com.lukouguoji.module_base.ui.weight.search.layout.PadSearchLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
hint='@{"请选择航班日期"}'
icon="@{@drawable/img_date}"
type="@{SearchLayoutType.DATE}"
value="@={viewModel.flightDate}" />
<!-- 航班号 -->
<com.lukouguoji.module_base.ui.weight.search.layout.PadSearchLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
hint='@{"请输入航班号"}'
type="@{SearchLayoutType.INPUT}"
value="@={viewModel.flightNo}" />
<!-- 目的站 -->
<com.lukouguoji.module_base.ui.weight.search.layout.PadSearchLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
hint='@{"请输入目的站"}'
type="@{SearchLayoutType.INPUT}"
value="@={viewModel.destAirport}" />
<!-- 组装人 -->
<com.lukouguoji.module_base.ui.weight.search.layout.PadSearchLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
hint='@{"请选择组装人"}'
type="@{SearchLayoutType.INPUT}"
value="@={viewModel.assembler}" />
<!-- 分配人 -->
<com.lukouguoji.module_base.ui.weight.search.layout.PadSearchLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
hint='@{"请输入分配人"}'
type="@{SearchLayoutType.INPUT}"
value="@={viewModel.allocator}" />
<!-- 搜索按钮 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
style="@style/iv_search_action"
android:onClick="@{()-> viewModel.searchClick()}"
android:src="@drawable/img_search" />
</LinearLayout>
</LinearLayout>
<!-- 列表 -->
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
itemLayoutId="@{viewModel.itemLayoutId}"
viewHolder="@{viewModel.itemViewHolder}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_gjc_assemble_allocate" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
<!-- 底部统计和操作按钮 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/color_bottom_layout"
android:gravity="center_vertical"
android:paddingHorizontal="15dp">
<!-- 全选按钮区域 -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:onClick="@{()->viewModel.checkAllClick()}">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="全选"
android:textColor="@color/white"
android:textSize="16sp" />
<ImageView
android:id="@+id/checkIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="5dp"
android:src="@drawable/img_check_all" />
</LinearLayout>
<!-- 统计信息 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{"合计:"+viewModel.totalCount+"票"}'
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="合计1票" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text='@{"总件数:"+viewModel.totalPc}'
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="总件数100" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text='@{"总重量:"+viewModel.totalWeight}'
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold"
tools:text="总重量100" />
</LinearLayout>
<!-- 分配按钮 -->
<TextView
style="@style/tv_bottom_btn"
android:onClick="@{()-> viewModel.allocateClick()}"
android:text="分配" />
</LinearLayout>
</LinearLayout>
</layout>

View File

@@ -0,0 +1,185 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="bean"
type="com.lukouguoji.module_base.bean.GjcAssembleAllocate" />
</data>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp"
android:layout_marginVertical="5dp"
android:background="@drawable/bg_item"
android:orientation="horizontal"
android:padding="10dp">
<!-- 选中图标 -->
<ImageView
android:id="@+id/iv_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
loadImage="@{bean.checked.get() ? @drawable/img_plane_s : @drawable/img_plane}"
android:src="@drawable/img_plane" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<!-- 第一行数据 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 航班日期 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{5}"
android:text="航班日期:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{bean.fdate}"
android:textColor="@color/colorPrimary"
tools:text="2025-09-05" />
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- 航班号 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{4}"
android:text="航班号:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{bean.fno}'
android:textColor="@color/colorPrimary"
tools:text="MU2023" />
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- 航程 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{4}"
android:text="航程:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{bean.range ?? (bean.fdep + "-" + bean.fdest)}'
tools:text="HFE - LAX" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- 第二行数据 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<!-- 组装人 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.2"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{4}"
android:text="组装人:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{bean.abName ?? ``}"
tools:text="徵远" />
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- 分配人 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{4}"
android:text="分配人:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='@{bean.acName ?? ``}'
tools:text="张三" />
</androidx.appcompat.widget.LinearLayoutCompat>
<!-- 分配时间 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
completeSpace="@{5}"
android:text="分配时间:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{bean.acDate ?? ``}"
tools:text="2024-01-15 14:27:12" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</layout>