feat: 国际出港组装分配
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user