feat: ui
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.lukouguoji.gjc.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemIntExpMoveBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcMove
|
||||
|
||||
/**
|
||||
* 国际出港移库列表项ViewHolder
|
||||
*/
|
||||
class IntExpMoveViewHolder(view: View) :
|
||||
BaseViewHolder<GjcMove, ItemIntExpMoveBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position
|
||||
|
||||
// 点击整个item切换选中状态
|
||||
binding.root.setOnClickListener {
|
||||
bean.isSelected = !bean.isSelected
|
||||
binding.bean = bean // 触发DataBinding更新
|
||||
}
|
||||
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.lukouguoji.gjc.page.move
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.databinding.ActivityIntExpMoveBinding
|
||||
import com.lukouguoji.gjc.viewModel.IntExpMoveViewModel
|
||||
import com.lukouguoji.module_base.base.BaseBindingActivity
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
import com.lukouguoji.module_base.ktx.addOnItemClickListener
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.model.ScanModel
|
||||
import com.lukouguoji.module_base.router.ARouterConstants
|
||||
|
||||
/**
|
||||
* 国际出港-出港移库
|
||||
*/
|
||||
@Route(path = ARouterConstants.ACTIVITY_URL_INT_EXP_MOVE)
|
||||
class IntExpMoveActivity : BaseBindingActivity<ActivityIntExpMoveBinding, IntExpMoveViewModel>() {
|
||||
|
||||
override fun layoutId() = R.layout.activity_int_exp_move
|
||||
override fun viewModelClass() = IntExpMoveViewModel::class.java
|
||||
|
||||
override fun initOnCreate(savedInstanceState: Bundle?) {
|
||||
setBackArrow("出港移库")
|
||||
binding.viewModel = viewModel
|
||||
binding.activity = this
|
||||
|
||||
initRecyclerView()
|
||||
initListeners()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化RecyclerView
|
||||
*/
|
||||
private fun initRecyclerView() {
|
||||
viewModel.pageModel.bindSmartRefreshLayout(
|
||||
binding.srl,
|
||||
binding.rv,
|
||||
viewModel,
|
||||
this
|
||||
)
|
||||
binding.rv.addOnItemClickListener(viewModel)
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化监听器
|
||||
*/
|
||||
private fun initListeners() {
|
||||
// 移库按钮
|
||||
binding.btnMove.setOnClickListener {
|
||||
showMoveConfirmDialog()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码运单号
|
||||
*/
|
||||
fun scanWaybill() {
|
||||
ScanModel.startScan(this, Constant.RequestCode.WAYBILL)
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示移库确认对话框
|
||||
*/
|
||||
private fun showMoveConfirmDialog() {
|
||||
val selectedItems = viewModel.getSelectedItems()
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
showToast("请至少选择一条运单")
|
||||
return
|
||||
}
|
||||
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle("移库确认")
|
||||
.setMessage("确定要移库选中的 ${selectedItems.size} 条记录吗?")
|
||||
.setPositiveButton("确定") { _, _ ->
|
||||
viewModel.submitMove()
|
||||
}
|
||||
.setNegativeButton("取消", null)
|
||||
.show()
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码回调
|
||||
*/
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == Constant.RequestCode.WAYBILL && resultCode == Activity.RESULT_OK) {
|
||||
val code = data?.getStringExtra(Constant.Result.CODED_CONTENT)
|
||||
viewModel.waybillNo.value = code
|
||||
viewModel.searchClick()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun start(context: Context) {
|
||||
val starter = Intent(context, IntExpMoveActivity::class.java)
|
||||
context.startActivity(starter)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.lukouguoji.gjc.viewModel
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.holder.IntExpMoveViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
import com.lukouguoji.module_base.bean.GjcMove
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
|
||||
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.noNull
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
import dev.utils.app.info.KeyValue
|
||||
|
||||
/**
|
||||
* 国际出港移库ViewModel
|
||||
*/
|
||||
class IntExpMoveViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
|
||||
// ========== 搜索字段 ==========
|
||||
val awbType = MutableLiveData("") // 运单类型
|
||||
val by1 = MutableLiveData("") // 承运人
|
||||
val dest1 = MutableLiveData("") // 卸货站
|
||||
val moveState = MutableLiveData("") // 移库状态
|
||||
val waybillNo = MutableLiveData("") // 运单号
|
||||
|
||||
// ========== 运单类型下拉数据 ==========
|
||||
val awbTypeList = MutableLiveData<List<KeyValue>>().apply {
|
||||
value = listOf(
|
||||
KeyValue("", "全部"),
|
||||
KeyValue("IOCO", "国际出港(经国内航班出境)"),
|
||||
KeyValue("IOSO", "国际出港(国际航班出境)")
|
||||
)
|
||||
}
|
||||
|
||||
// ========== 移库状态下拉数据 ==========
|
||||
val moveStateList = MutableLiveData<List<KeyValue>>().apply {
|
||||
value = listOf(
|
||||
KeyValue("", "全部"),
|
||||
KeyValue("0", "未移交"),
|
||||
KeyValue("1", "已移交")
|
||||
)
|
||||
}
|
||||
|
||||
// ========== 底部统计 ==========
|
||||
val totalCount = MutableLiveData("0") // 合计票数
|
||||
val totalPieces = MutableLiveData("0") // 总件数
|
||||
val totalWeight = MutableLiveData("0") // 总重量
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntExpMoveViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_exp_move
|
||||
|
||||
/**
|
||||
* 搜索按钮点击
|
||||
*/
|
||||
fun searchClick() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码运单号(在Activity中实现)
|
||||
*/
|
||||
fun scanWaybill() {
|
||||
// 由Activity处理扫码逻辑
|
||||
}
|
||||
|
||||
/**
|
||||
* 全选/取消全选
|
||||
*/
|
||||
fun toggleSelectAll() {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return
|
||||
val list = adapter.items.filterIsInstance<GjcMove>()
|
||||
val allSelected = list.all { it.isSelected }
|
||||
|
||||
list.forEach { it.isSelected = !allSelected }
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的运单
|
||||
*/
|
||||
fun getSelectedItems(): List<GjcMove> {
|
||||
val adapter = pageModel.rv?.commonAdapter() ?: return emptyList()
|
||||
return adapter.items.filterIsInstance<GjcMove>().filter { it.isSelected }
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交移库(在Activity中显示确认对话框后调用)
|
||||
*/
|
||||
fun submitMove() {
|
||||
val selectedItems = getSelectedItems()
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
showToast("请至少选择一条运单")
|
||||
return
|
||||
}
|
||||
|
||||
val params = selectedItems.toRequestBody()
|
||||
|
||||
launchLoadingCollect({ NetApply.api.submitIntExpMove(params) }) {
|
||||
onSuccess = {
|
||||
showToast("移库成功")
|
||||
refresh() // 刷新列表
|
||||
}
|
||||
onFailed = { _, msg ->
|
||||
showToast(msg.noNull("移库失败"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表数据
|
||||
*/
|
||||
override fun getData() {
|
||||
// 构建筛选参数
|
||||
val filterParams = mapOf(
|
||||
"awbType" to awbType.value.noNull(),
|
||||
"by1" to by1.value.noNull(),
|
||||
"dest1" to dest1.value.noNull(),
|
||||
"moveState" to moveState.value.noNull(),
|
||||
"likeNo" to waybillNo.value.noNull()
|
||||
)
|
||||
|
||||
// 列表参数(含分页)
|
||||
val listParams = (filterParams + mapOf(
|
||||
"pageNum" to pageModel.page,
|
||||
"pageSize" to pageModel.limit
|
||||
)).toRequestBody()
|
||||
|
||||
// 统计参数(无分页)
|
||||
val totalParams = filterParams.toRequestBody()
|
||||
|
||||
// 获取列表(显示loading)
|
||||
launchLoadingCollect({ NetApply.api.getIntExpMoveList(listParams) }) {
|
||||
onSuccess = { pageModel.handleListBean(it) }
|
||||
}
|
||||
|
||||
// 获取统计(后台调用)
|
||||
getTotalData(totalParams)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统计数据(无Loading)
|
||||
*/
|
||||
private fun getTotalData(params: okhttp3.RequestBody) {
|
||||
launchCollect({ NetApply.api.getIntExpMoveTotal(params) }) {
|
||||
onSuccess = { result ->
|
||||
val data = result.data
|
||||
totalCount.value = (data?.wbNumber ?: 0).toString()
|
||||
totalPieces.value = (data?.totalPc ?: 0L).toString()
|
||||
totalWeight.value = (data?.totalWeight ?: 0.0).toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item点击事件处理(用于单选CheckBox)
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
val bean = pageModel.rv?.commonAdapter()?.getItem(position) as? GjcMove ?: return
|
||||
bean.isSelected = !bean.isSelected
|
||||
pageModel.rv?.commonAdapter()?.notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user