feat: io
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
package com.lukouguoji.gjc.viewModel
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.holder.AssembleInfoViewHolder
|
||||
import com.lukouguoji.gjc.holder.AssemblePositionViewHolder
|
||||
import com.lukouguoji.gjc.holder.AssembleWaybillViewHolder
|
||||
import com.lukouguoji.module_base.base.BaseViewModel
|
||||
import com.lukouguoji.module_base.bean.*
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
|
||||
/**
|
||||
* 国际出港-开始组装ViewModel(静态数据)
|
||||
*/
|
||||
class IntExpAssembleStartViewModel : BaseViewModel() {
|
||||
|
||||
// ========== 搜索条件 ==========
|
||||
val searchWaybillNo = MutableLiveData("")
|
||||
|
||||
// ========== 左侧组装信息列表 ==========
|
||||
val assembleInfoList = MutableLiveData<MutableList<AssembleInfoBean>>()
|
||||
val assembleInfoLayoutId = R.layout.item_assemble_info
|
||||
val assembleInfoViewHolder = AssembleInfoViewHolder::class.java
|
||||
|
||||
// ========== 左侧组装位置列表 ==========
|
||||
val assemblePositionList = MutableLiveData<MutableList<AssemblePositionBean>>()
|
||||
val assemblePositionLayoutId = R.layout.item_assemble_position
|
||||
val assemblePositionViewHolder = AssemblePositionViewHolder::class.java
|
||||
|
||||
// ========== 右侧运单列表 ==========
|
||||
val waybillList = MutableLiveData<MutableList<AssembleWaybillBean>>()
|
||||
val waybillLayoutId = R.layout.item_assemble_waybill
|
||||
val waybillViewHolder = AssembleWaybillViewHolder::class.java
|
||||
|
||||
// ========== ULD信息 ==========
|
||||
val uldInfo = MutableLiveData(UldInfoBean().apply {
|
||||
uldNo = "AKE12345HK"
|
||||
planeType = "B777"
|
||||
weightLimit = "1500"
|
||||
totalPieces = "120"
|
||||
totalWeight = "2450.5"
|
||||
status = "进行中"
|
||||
})
|
||||
|
||||
// ========== 运单信息 ==========
|
||||
val waybillInfo = MutableLiveData(WaybillInfoBean().apply {
|
||||
waybillNo = "99912345678"
|
||||
pieces = "25"
|
||||
weight = "350.5"
|
||||
destination = "LAX"
|
||||
specialCode = "GEN"
|
||||
goodsName = "ELECTRONICS"
|
||||
})
|
||||
|
||||
/**
|
||||
* 初始化模拟数据
|
||||
*/
|
||||
fun initMockData() {
|
||||
// 组装信息列表(左侧)
|
||||
assembleInfoList.value = mutableListOf(
|
||||
AssembleInfoBean().apply {
|
||||
waybillNo = "99912345678"
|
||||
pieces = "25"
|
||||
},
|
||||
AssembleInfoBean().apply {
|
||||
waybillNo = "99912345679"
|
||||
pieces = "18"
|
||||
},
|
||||
AssembleInfoBean().apply {
|
||||
waybillNo = "99912345680"
|
||||
pieces = "32"
|
||||
},
|
||||
AssembleInfoBean().apply {
|
||||
waybillNo = "99912345681"
|
||||
pieces = "15"
|
||||
}
|
||||
)
|
||||
|
||||
// 组装位置列表(左侧)
|
||||
assemblePositionList.value = mutableListOf(
|
||||
AssemblePositionBean().apply {
|
||||
positionName = "A区-01号位"
|
||||
isSelected = true
|
||||
},
|
||||
AssemblePositionBean().apply {
|
||||
positionName = "A区-02号位"
|
||||
isSelected = false
|
||||
},
|
||||
AssemblePositionBean().apply {
|
||||
positionName = "B区-01号位"
|
||||
isSelected = false
|
||||
}
|
||||
)
|
||||
|
||||
// 运单列表(右侧)
|
||||
waybillList.value = mutableListOf(
|
||||
AssembleWaybillBean().apply {
|
||||
waybillNo = "99912345678"
|
||||
pieces = "25"
|
||||
weight = "350.5"
|
||||
isMarked = false
|
||||
},
|
||||
AssembleWaybillBean().apply {
|
||||
waybillNo = "99912345679"
|
||||
pieces = "18"
|
||||
weight = "280.0"
|
||||
isMarked = true // 标记为红色
|
||||
},
|
||||
AssembleWaybillBean().apply {
|
||||
waybillNo = "99912345680"
|
||||
pieces = "32"
|
||||
weight = "520.8"
|
||||
isMarked = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码运单
|
||||
*/
|
||||
fun scanWaybill() {
|
||||
showToast("扫码功能(静态页面暂不实现)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 卸货按钮点击
|
||||
*/
|
||||
fun onUnloadClick() {
|
||||
showToast("卸货操作(静态页面暂不实现)")
|
||||
}
|
||||
|
||||
/**
|
||||
* 装货按钮点击
|
||||
*/
|
||||
fun onLoadClick() {
|
||||
showToast("装货操作(静态页面暂不实现)")
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.lukouguoji.gjc.viewModel
|
||||
|
||||
import android.text.InputType
|
||||
import android.widget.EditText
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.holder.IntExpAssembleViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
@@ -12,6 +16,8 @@ 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.ktx.verifyNullOrEmpty
|
||||
import com.lukouguoji.module_base.router.ARouterConstants
|
||||
import dev.utils.app.info.KeyValue
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -129,4 +135,119 @@ class IntExpAssembleViewModel : BasePageViewModel() {
|
||||
toggleExpand(position)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加号按钮点击 - 跳转到开始组装页面
|
||||
*/
|
||||
fun onAddClick() {
|
||||
ARouter.getInstance()
|
||||
.build(ARouterConstants.ACTIVITY_URL_INT_EXP_ASSEMBLE_START)
|
||||
.navigation()
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除按钮点击
|
||||
*/
|
||||
fun onDeleteClick() {
|
||||
// 获取选中的数据
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val allItems = adapter.items
|
||||
val selectedItems = allItems
|
||||
.filterIsInstance<GjcUldUseBean>()
|
||||
.filter { it.isSelected }
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
showToast("请选择要删除的记录")
|
||||
return
|
||||
}
|
||||
|
||||
// 显示确认对话框
|
||||
val activity = getTopActivity()
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle("删除确认")
|
||||
.setMessage("确定要删除选中的 ${selectedItems.size} 条记录吗?")
|
||||
.setPositiveButton("删除") { _, _ ->
|
||||
deleteSelectedItems(selectedItems)
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除选中项
|
||||
*/
|
||||
private fun deleteSelectedItems(items: List<GjcUldUseBean>) {
|
||||
val ids = items.mapNotNull { it.useId }.joinToString(",")
|
||||
|
||||
launchLoadingCollect({ NetApply.api.deleteIntExpAssemble(ids) }) {
|
||||
onSuccess = {
|
||||
showToast("删除成功")
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回填重量按钮点击
|
||||
*/
|
||||
fun onBackfillWeightClick() {
|
||||
// 获取选中的数据
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val allItems = adapter.items
|
||||
val selectedItems = allItems
|
||||
.filterIsInstance<GjcUldUseBean>()
|
||||
.filter { it.isSelected }
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
showToast("请选择要回填重量的记录")
|
||||
return
|
||||
}
|
||||
|
||||
// 显示输入对话框
|
||||
showBackfillWeightDialog(selectedItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示回填重量对话框
|
||||
*/
|
||||
private fun showBackfillWeightDialog(items: List<GjcUldUseBean>) {
|
||||
val activity = getTopActivity()
|
||||
|
||||
// 创建输入框
|
||||
val input = EditText(activity).apply {
|
||||
hint = "请输入重量(KG)"
|
||||
inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
setPadding(40, 40, 40, 40)
|
||||
}
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle("回填重量")
|
||||
.setMessage("共选中 ${items.size} 条记录")
|
||||
.setView(input)
|
||||
.setPositiveButton("确定") { _, _ ->
|
||||
val weight = input.text.toString()
|
||||
if (weight.verifyNullOrEmpty("请输入重量")) return@setPositiveButton
|
||||
backfillWeight(items, weight)
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* 回填重量API调用
|
||||
*/
|
||||
private fun backfillWeight(items: List<GjcUldUseBean>, weight: String) {
|
||||
val ids = items.mapNotNull { it.useId }.joinToString(",")
|
||||
val params = mapOf(
|
||||
"ids" to ids,
|
||||
"weight" to weight
|
||||
).toRequestBody()
|
||||
|
||||
launchLoadingCollect({ NetApply.api.backfillIntExpAssembleWeight(params) }) {
|
||||
onSuccess = {
|
||||
showToast("回填重量成功")
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user