feat: 国际出港 组装分配

This commit is contained in:
2025-12-11 19:06:06 +08:00
parent a81567f10b
commit 82fc593497
8 changed files with 205 additions and 32 deletions

View File

@@ -2,11 +2,14 @@ package com.lukouguoji.gjc.viewModel
import android.app.AlertDialog
import android.widget.EditText
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.dialog.GjcAssembleAllocateDialogModel
import com.lukouguoji.gjc.holder.GjcAssembleAllocateViewHolder
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.AssembleCompanyBean
import com.lukouguoji.module_base.bean.GjcAssembleAllocate
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.http.net.NetApply
@@ -17,6 +20,7 @@ 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 dev.utils.app.info.KeyValue
import kotlinx.coroutines.launch
/**
@@ -43,6 +47,10 @@ class GjcAssembleAllocateViewModel : BasePageViewModel() {
// 全选状态
val isAllChecked = MutableLiveData(false)
// 分配人列表(从接口获取,存储 KeyValue 格式)
private val _assembleCompanyList = MutableLiveData<List<KeyValue>>(emptyList())
val assembleCompanyList: LiveData<List<KeyValue>> = _assembleCompanyList
///////////////////////////////////////////////////////////////////////////
// 方法区
///////////////////////////////////////////////////////////////////////////
@@ -129,6 +137,19 @@ class GjcAssembleAllocateViewModel : BasePageViewModel() {
updateCheckAllStatus()
}
/**
* 获取分配人列表
* 在 Activity 初始化时调用
*/
fun getAssembleCompanyList() {
launchCollect({ NetApply.api.getAssembleCompanyList() }) {
onSuccess = { result ->
val list = result.data?.map { it.toKeyValue() } ?: emptyList()
_assembleCompanyList.value = list
}
}
}
/**
* 分配按钮点击
*/
@@ -141,45 +162,45 @@ class GjcAssembleAllocateViewModel : BasePageViewModel() {
return
}
// 显示分配人输入对话框
showAllocatorInputDialog(selectedItems)
// 检查分配人列表是否为空
if (_assembleCompanyList.value.isNullOrEmpty()) {
showToast("分配人列表为空,请稍后重试")
return
}
// 显示分配人选择对话框
showAllocatorSelectDialog(selectedItems)
}
/**
* 显示分配人输入对话框
* 显示分配人选择对话框
*/
private fun showAllocatorInputDialog(items: List<GjcAssembleAllocate>) {
val activity = getTopActivity()
val editText = EditText(activity)
editText.hint = "请输入分配人姓名"
private fun showAllocatorSelectDialog(items: List<GjcAssembleAllocate>) {
// 构建航班信息字符串例如CA1234、MU5678
val flightInfo = items.joinToString("") { it.fno ?: "" }
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()
GjcAssembleAllocateDialogModel(
flightInfo = flightInfo,
assembleCompanyList = _assembleCompanyList.value ?: emptyList()
) { dialog ->
// 回调:用户点击确定后执行分配操作
// dialog.allocator.value 存储的是选中的 code例如 "ATR"
val allocatorCode = dialog.allocator.value ?: ""
performAllocate(items, allocatorCode)
}.show(getTopActivity())
}
/**
* 执行分配操作
* @param items 选中的航班列表
* @param allocatorCode 分配人代码(例如 "ATR",而非 "ATR:马道"
*/
private fun performAllocate(items: List<GjcAssembleAllocate>, allocatorName: String) {
private fun performAllocate(items: List<GjcAssembleAllocate>, allocatorCode: String) {
val fidList = items.mapNotNull { it.fid }
val requestData = mapOf(
"fidList" to fidList, // 航班ID列表
"acName" to allocatorName // 分配人姓名
"abId" to allocatorCode // 分配人代码(传递 code 而非 name
).toRequestBody()
launchLoadingCollect({ NetApply.api.allocateAssemble(requestData) }) {