feat: visa delete/detail
This commit is contained in:
@@ -57,13 +57,21 @@ class IntImpAccidentVisaActivity :
|
||||
}
|
||||
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
val bean = binding.rv.commonAdapter()?.getItem(position) as? IntImpAccidentVisaBean
|
||||
?: return
|
||||
when (type) {
|
||||
1000 -> {
|
||||
// 点击列表项 - 查看详情
|
||||
IntImpAccidentVisaEditActivity.start(this, bean.id, isDetail = true)
|
||||
}
|
||||
2000 -> {
|
||||
// 侧滑菜单 - 修改
|
||||
val bean = binding.rv.commonAdapter()?.getItem(position) as? IntImpAccidentVisaBean
|
||||
?: return
|
||||
IntImpAccidentVisaEditActivity.start(this, bean.id)
|
||||
}
|
||||
3000 -> {
|
||||
// 侧滑菜单 - 删除
|
||||
viewModel.singleDelete(bean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,17 +34,24 @@ class IntImpAccidentVisaEditActivity :
|
||||
viewModel.initOnCreate(intent)
|
||||
|
||||
viewModel.pageType.observe(this) {
|
||||
val title = if (it == DetailsPageType.Add) "国际事故签证新增" else "国际事故签证修改"
|
||||
val title = when (it) {
|
||||
DetailsPageType.Add -> "国际事故签证新增"
|
||||
DetailsPageType.Details -> "国际事故签证详情"
|
||||
else -> "国际事故签证修改"
|
||||
}
|
||||
setBackArrow(title)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_IS_DETAIL = "is_detail"
|
||||
|
||||
@JvmStatic
|
||||
fun start(context: Context, id: Long = 0) {
|
||||
fun start(context: Context, id: Long = 0, isDetail: Boolean = false) {
|
||||
context.startActivity(
|
||||
Intent(context, IntImpAccidentVisaEditActivity::class.java)
|
||||
.putExtra(Constant.Key.ID, id)
|
||||
.putExtra(KEY_IS_DETAIL, isDetail)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,21 @@ class IntImpAccidentVisaViewHolder(view: View) :
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
|
||||
// 点击列表项 - 进入详情
|
||||
binding.ll.setOnClickListener {
|
||||
clickListener?.onItemClick(position, 1000) // type=1000表示查看详情
|
||||
}
|
||||
|
||||
// 侧滑菜单 - 修改按钮
|
||||
binding.btnEdit.setOnClickListener {
|
||||
binding.swipeMenu.quickClose()
|
||||
clickListener?.onItemClick(position, 2000) // type=2000表示修改操作
|
||||
}
|
||||
|
||||
// 侧滑菜单 - 删除按钮
|
||||
binding.btnDelete.setOnClickListener {
|
||||
binding.swipeMenu.quickClose()
|
||||
clickListener?.onItemClick(position, 3000) // type=3000表示删除操作
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +69,19 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
// 初始化
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// 是否为详情模式(只读)
|
||||
val isDetailMode = MutableLiveData(false)
|
||||
|
||||
fun initOnCreate(intent: Intent) {
|
||||
id = intent.getLongExtra(Constant.Key.ID, 0)
|
||||
pageType.value = if (id == 0L) DetailsPageType.Add else DetailsPageType.Modify
|
||||
val isDetail = intent.getBooleanExtra("is_detail", false)
|
||||
|
||||
pageType.value = when {
|
||||
isDetail && id != 0L -> DetailsPageType.Details
|
||||
id == 0L -> DetailsPageType.Add
|
||||
else -> DetailsPageType.Modify
|
||||
}
|
||||
isDetailMode.value = pageType.value == DetailsPageType.Details
|
||||
|
||||
// 新增模式下默认航班日期为今天
|
||||
if (pageType.value == DetailsPageType.Add) {
|
||||
@@ -86,8 +96,11 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
loadDetail()
|
||||
}
|
||||
|
||||
rv?.post {
|
||||
rv?.commonAdapter()?.addItem(FileBean())
|
||||
// 详情模式不添加空白占位图片
|
||||
if (!isDetail) {
|
||||
rv?.post {
|
||||
rv?.commonAdapter()?.addItem(FileBean())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +276,9 @@ class IntImpAccidentVisaEditViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
// 详情模式下不允许长按删除操作
|
||||
if (isDetailMode.value == true) return
|
||||
|
||||
val adapter = rv!!.commonAdapter()!!
|
||||
val bean = adapter.getItem(position) as FileBean
|
||||
when (type) {
|
||||
|
||||
@@ -17,6 +17,7 @@ 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 com.lukouguoji.module_base.model.ConfirmDialogModel
|
||||
import com.lukouguoji.module_base.model.ScanModel
|
||||
import dev.utils.app.info.KeyValue
|
||||
import dev.utils.common.DateUtils
|
||||
@@ -146,7 +147,25 @@ class IntImpAccidentVisaViewModel : BasePageViewModel() {
|
||||
showToast("请选择要删除的数据")
|
||||
return
|
||||
}
|
||||
launchLoadingCollect({ NetApply.api.deleteIntImpAccidentVisa(selected.toRequestBody()) }) {
|
||||
ConfirmDialogModel(
|
||||
message = "确定要删除选中的 ${selected.size} 条数据吗?",
|
||||
title = "提示"
|
||||
) {
|
||||
doDelete(selected)
|
||||
}.show()
|
||||
}
|
||||
|
||||
fun singleDelete(bean: IntImpAccidentVisaBean) {
|
||||
ConfirmDialogModel(
|
||||
message = "确定要删除运单号 ${bean.wbNo} 的事故签证吗?",
|
||||
title = "提示"
|
||||
) {
|
||||
doDelete(listOf(bean))
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun doDelete(list: List<IntImpAccidentVisaBean>) {
|
||||
launchLoadingCollect({ NetApply.api.deleteIntImpAccidentVisa(list.toRequestBody()) }) {
|
||||
onSuccess = {
|
||||
showToast("删除成功")
|
||||
viewModelScope.launch {
|
||||
|
||||
Reference in New Issue
Block a user