feat: 国际进港装机单编辑页面及列表侧滑优化
- 新增装机单编辑页面(Activity/ViewModel/布局) - 装机单列表项添加侧滑编辑按钮,点击跳转编辑页 - 修复舱单列表项侧滑按钮未覆盖展开按钮的问题 - 修复装机单列表项两行同列completeSpace不一致 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.lukouguoji.gjj.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.google.gson.Gson
|
||||
import com.lukouguoji.gjj.R
|
||||
import com.lukouguoji.gjj.databinding.ActivityIntImpLoadingListEditBinding
|
||||
import com.lukouguoji.gjj.viewModel.IntImpLoadingListEditViewModel
|
||||
import com.lukouguoji.module_base.base.BaseBindingActivity
|
||||
import com.lukouguoji.module_base.bean.GjjManifest
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
|
||||
/**
|
||||
* 国际进港-装机单编辑页面
|
||||
*/
|
||||
class IntImpLoadingListEditActivity :
|
||||
BaseBindingActivity<ActivityIntImpLoadingListEditBinding, IntImpLoadingListEditViewModel>() {
|
||||
|
||||
override fun layoutId() = R.layout.activity_int_imp_loading_list_edit
|
||||
override fun viewModelClass() = IntImpLoadingListEditViewModel::class.java
|
||||
|
||||
override fun initOnCreate(savedInstanceState: Bundle?) {
|
||||
setBackArrow("装机单编辑")
|
||||
binding.viewModel = viewModel
|
||||
viewModel.initOnCreated(intent)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun start(context: Context, bean: GjjManifest) {
|
||||
val starter = Intent(context, IntImpLoadingListEditActivity::class.java)
|
||||
.putExtra(Constant.Key.DATA, Gson().toJson(bean))
|
||||
context.startActivity(starter)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,11 @@ class IntImpLoadingListViewHolder(view: View) :
|
||||
bean.checked.set(!bean.checked.get())
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
// 侧滑菜单 - 编辑按钮
|
||||
binding.btnEdit.setOnClickListener {
|
||||
binding.swipeMenu.quickClose()
|
||||
clickListener?.onItemClick(position, 2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.lukouguoji.gjj.viewModel
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.google.gson.Gson
|
||||
import com.lukouguoji.module_base.base.BaseViewModel
|
||||
import com.lukouguoji.module_base.bean.GjjManifest
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
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.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 国际进港装机单编辑 ViewModel
|
||||
*/
|
||||
class IntImpLoadingListEditViewModel : BaseViewModel() {
|
||||
|
||||
val dataBean = MutableLiveData(GjjManifest())
|
||||
|
||||
// 可编辑数值字段(String 用于双向绑定)
|
||||
val location = MutableLiveData("")
|
||||
val totalPcStr = MutableLiveData("")
|
||||
val pcStr = MutableLiveData("")
|
||||
val weightStr = MutableLiveData("")
|
||||
val cashWeightStr = MutableLiveData("")
|
||||
|
||||
fun initOnCreated(intent: Intent) {
|
||||
val jsonData = intent.getStringExtra(Constant.Key.DATA) ?: ""
|
||||
if (jsonData.isNotEmpty()) {
|
||||
try {
|
||||
val bean = Gson().fromJson(jsonData, GjjManifest::class.java)
|
||||
dataBean.value = bean
|
||||
// 初始化可编辑字段
|
||||
location.value = bean.location
|
||||
totalPcStr.value = bean.totalPc.toString()
|
||||
pcStr.value = bean.pc.toString()
|
||||
weightStr.value = bean.weight.toString()
|
||||
cashWeightStr.value = bean.cashWeight.toString()
|
||||
} catch (e: Exception) {
|
||||
showToast("数据解析失败")
|
||||
getTopActivity().finish()
|
||||
}
|
||||
} else {
|
||||
showToast("未接收到数据")
|
||||
getTopActivity().finish()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存修改
|
||||
*/
|
||||
fun submit() {
|
||||
val bean = dataBean.value ?: return
|
||||
|
||||
// 同步可编辑字段回 bean
|
||||
bean.location = location.value ?: ""
|
||||
bean.totalPc = totalPcStr.value?.toLongOrNull() ?: 0
|
||||
bean.pc = pcStr.value?.toLongOrNull() ?: 0
|
||||
bean.weight = weightStr.value?.toDoubleOrNull() ?: 0.0
|
||||
bean.cashWeight = cashWeightStr.value?.toDoubleOrNull() ?: 0.0
|
||||
|
||||
launchLoadingCollect({
|
||||
NetApply.api.modifyIntImpLoadingList(bean.toRequestBody())
|
||||
}) {
|
||||
onSuccess = {
|
||||
showToast("修改成功")
|
||||
viewModelScope.launch {
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
}
|
||||
getTopActivity().finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消
|
||||
*/
|
||||
fun cancel() {
|
||||
getTopActivity().finish()
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.lukouguoji.module_base.common.Constant
|
||||
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.interfaces.IOnItemClickListener
|
||||
import com.lukouguoji.module_base.ktx.commonAdapter
|
||||
import com.lukouguoji.module_base.ktx.launchCollect
|
||||
import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
@@ -23,7 +24,7 @@ import kotlinx.coroutines.launch
|
||||
/**
|
||||
* 国际进港装机单 ViewModel
|
||||
*/
|
||||
class IntImpLoadingListViewModel : BasePageViewModel() {
|
||||
class IntImpLoadingListViewModel : BasePageViewModel(), IOnItemClickListener {
|
||||
|
||||
// ========== 搜索条件 ==========
|
||||
val flightDate = MutableLiveData("") // 航班日期
|
||||
@@ -278,6 +279,20 @@ class IntImpLoadingListViewModel : BasePageViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表项点击回调(侧滑菜单)
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
when (type) {
|
||||
2000 -> {
|
||||
// 编辑操作
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<GjjManifest> ?: return
|
||||
val bean = list.getOrNull(position) ?: return
|
||||
com.lukouguoji.gjj.activity.IntImpLoadingListEditActivity.start(getTopActivity(), bean)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据(重写BasePageViewModel)
|
||||
* 查询参数与父页面(国际进港舱单)保持一致:使用FID和FDGP
|
||||
|
||||
Reference in New Issue
Block a user