feat: 国际出港移库新增详情查看与侧滑编辑

列表项右侧增加箭头,点击进入详情页;左滑显示“编辑”按钮进入编辑页。
详情与编辑复用同一表单页,编辑模式仅支持修改备注与交接图片上传/删除,
表单结构参考国内进港移交编辑。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-08 16:00:48 +08:00
parent ea298ec322
commit 51c5ac6e96
9 changed files with 559 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package com.lukouguoji.gjc.holder
import android.view.View
import com.lukouguoji.gjc.databinding.ItemIntExpMoveBinding
import com.lukouguoji.gjc.page.move.IntExpMoveEditActivity
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.GjcMove
import com.lukouguoji.module_base.common.ConstantEvent
@@ -31,6 +32,17 @@ class IntExpMoveViewHolder(view: View) :
}
}
// 点击列表项进入移库详情
binding.ll.setOnClickListener {
IntExpMoveEditActivity.startForDetails(itemView.context, bean.maWbId)
}
// 侧滑菜单 - 编辑按钮
binding.btnEdit.setOnClickListener {
binding.swipeMenu.quickClose()
IntExpMoveEditActivity.startForEdit(itemView.context, bean.maWbId)
}
binding.executePendingBindings()
}
}

View File

@@ -0,0 +1,68 @@
package com.lukouguoji.gjc.page.move
import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityIntExpMoveEditBinding
import com.lukouguoji.gjc.viewModel.IntExpMoveEditViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.DetailsPageType
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
import com.lukouguoji.module_base.router.ARouterConstants
/**
* 国际出港移库编辑/详情页
* 编辑模式仅支持拍照上传与备注修改
*/
@Route(path = ARouterConstants.ACTIVITY_URL_INT_EXP_MOVE_EDIT)
class IntExpMoveEditActivity :
BaseBindingActivity<ActivityIntExpMoveEditBinding, IntExpMoveEditViewModel>() {
override fun layoutId() = R.layout.activity_int_exp_move_edit
override fun viewModelClass() = IntExpMoveEditViewModel::class.java
override fun initOnCreate(savedInstanceState: Bundle?) {
viewModel.initOnCreated(intent)
when (viewModel.pageType.value) {
DetailsPageType.Modify -> setBackArrow("国际出港移库编辑")
else -> setBackArrow("国际出港移库详情")
}
binding.viewModel = viewModel
// 绑定图片 RecyclerView 引用
viewModel.rvImages = binding.rvImages
// 绑定图片列表点击事件(编辑模式下可删除图片)
binding.rvImages.addOnItemClickListener(viewModel)
// 监听图片列表变化并更新 adapter
viewModel.imageList.observe(this) { images ->
binding.rvImages.commonAdapter()?.refresh(images)
}
}
companion object {
@JvmStatic
fun startForEdit(context: Context, maWbId: Long?) {
val starter = Intent(context, IntExpMoveEditActivity::class.java)
.putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Modify.name)
.putExtra(Constant.Key.ID, maWbId?.toString() ?: "")
context.startActivity(starter)
}
@JvmStatic
fun startForDetails(context: Context, maWbId: Long?) {
val starter = Intent(context, IntExpMoveEditActivity::class.java)
.putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Details.name)
.putExtra(Constant.Key.ID, maWbId?.toString() ?: "")
context.startActivity(starter)
}
}
}

View File

@@ -0,0 +1,164 @@
package com.lukouguoji.gjc.viewModel
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.RecyclerView
import com.lukouguoji.gjc.R
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.FileBean
import com.lukouguoji.module_base.bean.GjcMaWb
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.common.DetailsPageType
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.impl.ImageSelectNewViewHolder
import com.lukouguoji.module_base.interfaces.IOnItemClickListener
import com.lukouguoji.module_base.ktx.commonAdapter
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.MediaUtil
import com.lukouguoji.module_base.util.UploadUtil
import kotlinx.coroutines.launch
/**
* 国际出港移库编辑/详情 ViewModel
* 编辑模式仅支持修改备注与交接图片
*/
class IntExpMoveEditViewModel : BaseViewModel(), IOnItemClickListener {
val pageType = MutableLiveData(DetailsPageType.Details)
private var maWbId: Long = 0L
val dataBean = MutableLiveData(GjcMaWb())
// 备注单独用 LiveData 双向绑定,避免修改 data class 属性后需重新赋值
val remark = MutableLiveData("")
// 图片列表
val imageList = MutableLiveData<MutableList<FileBean>>(mutableListOf())
// 图片适配器配置
val imageItemLayoutId = R.layout.item_image_select_new
val imageItemViewHolder = ImageSelectNewViewHolder::class.java
// 详情模式下无图片时显示占位提示
val showNoImage = MutableLiveData(false)
// 图片 RecyclerView 引用(用于从 adapter 实时获取图片)
var rvImages: RecyclerView? = null
fun initOnCreated(intent: Intent) {
pageType.value = DetailsPageType.valueOf(
intent.getStringExtra(Constant.Key.PAGE_TYPE) ?: DetailsPageType.Details.name
)
maWbId = intent.getStringExtra(Constant.Key.ID)?.toLongOrNull() ?: 0L
loadData()
}
private fun loadData() {
launchLoadingCollect({ NetApply.api.getIntExpMoveDetail(maWbId) }) {
onSuccess = {
val bean = it.data ?: GjcMaWb()
// 详情接口 wbNo 可能为空,回退为 前缀 + 运单号
if (bean.wbNo.isNullOrEmpty()) {
bean.wbNo = (bean.prefix ?: "") + (bean.no ?: "")
}
dataBean.value = bean
remark.value = bean.remark ?: ""
// 处理图片列表(同时保留缩略图和原图信息,确保二次编辑时不丢失)
val picList = (bean.pic ?: "").split(",").filter { p -> p.isNotEmpty() }
val originalPicList = (bean.originalPic ?: "").split(",").filter { p -> p.isNotEmpty() }
val images = if (picList.isNotEmpty()) {
picList.mapIndexed { index, picUrl ->
val originalUrl = originalPicList.getOrElse(index) { picUrl }
FileBean(
path = MediaUtil.fillUrl(originalUrl),
url = picUrl,
originalPic = originalUrl
)
}.toMutableList()
} else {
originalPicList.map { url ->
FileBean(path = MediaUtil.fillUrl(url), url = url, originalPic = url)
}.toMutableList()
}
// 编辑模式添加空 FileBean 用于显示“添加照片”按钮
if (pageType.value == DetailsPageType.Modify) {
images.add(FileBean())
}
imageList.value = images
// 详情模式下无图片时显示占位提示
showNoImage.value = pageType.value == DetailsPageType.Details && images.isEmpty()
}
}
}
/**
* 提交保存(只保存备注和图片)
*/
fun submit() {
// 从 adapter 实时获取所有非空图片ViewHolder 新增图片直接操作 adapter items
val allItems = (rvImages?.commonAdapter()?.items as? List<*>)
?.filterIsInstance<FileBean>() ?: imageList.value!!
val images = allItems.filter { it.path.isNotEmpty() }
if (images.size > 7) {
showToast("最多上传7张图片")
return
}
launchLoadingCollect({
// 上传本地新图片;已上传的图片保持原有 url 与 originalPic
images.forEach { fileBean ->
if (fileBean.url.isEmpty()) {
// UploadUtil 返回newName=原图(较大)zipFileName=缩略图(较小)
// FileBean.url 用作缩略图标识FileBean.originalPic 用作原图标识
val data = UploadUtil.upload(fileBean.path).data
fileBean.url = data?.zipFileName ?: ""
fileBean.originalPic = data?.newName ?: ""
}
}
val params = mapOf(
"maWbId" to maWbId,
"remark" to (remark.value ?: ""),
"picNumber" to images.size.toString(),
"pic" to images.joinToString(",") { MediaUtil.removeUrl(it.url) },
"originalPic" to images.joinToString(",") { MediaUtil.removeUrl(it.originalPic) },
).toRequestBody(removeEmptyOrNull = true)
NetApply.api.updateIntExpMove(params)
}) {
onSuccess = {
showToast("保存成功")
viewModelScope.launch {
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
}
getTopActivity().finish()
}
}
}
fun cancel() {
getTopActivity().finish()
}
/**
* 处理图片删除点击事件
*/
override fun onItemClick(position: Int, type: Int) {
if (type == R.id.iv_delete) {
val adapter = rvImages?.commonAdapter() ?: return
if (position < adapter.items.size) {
adapter.removeItem(position)
}
}
}
}

View File

@@ -0,0 +1,259 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="com.lukouguoji.module_base.ui.weight.data.layout.DataLayoutType" />
<import type="com.lukouguoji.module_base.common.DetailsPageType" />
<import type="android.view.View" />
<variable
name="viewModel"
type="com.lukouguoji.gjc.viewModel.IntExpMoveEditViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_f2"
android:orientation="vertical">
<include layout="@layout/title_tool_bar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_white_radius_8"
android:orientation="vertical"
android:padding="15dp">
<!-- 第一行:运单号、件数、重量(均只读) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"运单号"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.wbNo}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"件数"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.pc == null ? "" : String.valueOf(viewModel.dataBean.pc)}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"重量"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.weight == null ? "" : String.valueOf(viewModel.dataBean.weight)}' />
</LinearLayout>
<!-- 第二行:特码、代理人、品名(均只读) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"特码"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.spCode}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"代理人"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.agentCode}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"品名"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.goodsCn == null || viewModel.dataBean.goodsCn.isEmpty() ? viewModel.dataBean.goods : viewModel.dataBean.goodsCn}' />
</LinearLayout>
<!-- 第三行:出港航班、出运路径、运单类型(均只读) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"出港航班"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.flightInfo}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"出运路径"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.rangeText}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"运单类型"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.awbName}' />
</LinearLayout>
<!-- 第四行:承运人(只读)、备注(编辑模式可编辑) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
enable="@{false}"
title='@{"承运人"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@{viewModel.dataBean.by1}' />
<com.lukouguoji.module_base.ui.weight.data.layout.PadDataLayoutNew
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
enable="@{viewModel.pageType != DetailsPageType.Details}"
hint='@{"请输入备注"}'
title='@{"备注"}'
titleLength="@{5}"
type="@{DataLayoutType.INPUT}"
value='@={viewModel.remark}' />
</LinearLayout>
<!-- 交接图片区域label 在左,图片在右 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="交接图片"
android:textColor="@color/text_gray"
completeSpace="@{5}" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_images"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:overScrollMode="never"
itemLayoutId="@{viewModel.imageItemLayoutId}"
viewHolder="@{viewModel.imageItemViewHolder}"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="9" />
</LinearLayout>
<!-- 详情模式下无图片时的占位提示 -->
<TextView
android:id="@+id/tv_no_image"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:text="暂无图片"
android:textColor="@color/text_gray"
android:textSize="14sp"
android:visibility="@{viewModel.showNoImage ? View.VISIBLE : View.GONE}" />
</LinearLayout>
<!-- 底部按钮(详情模式不显示) -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="15dp"
android:gravity="center"
android:orientation="horizontal"
android:visibility="@{viewModel.pageType != DetailsPageType.Details ? View.VISIBLE : View.GONE}">
<TextView
style="@style/tv_bottom_btn"
android:layout_width="120dp"
android:onClick="@{()-> viewModel.cancel()}"
android:text="取消" />
<TextView
style="@style/tv_bottom_btn"
android:layout_width="120dp"
android:onClick="@{()-> viewModel.submit()}"
android:text="保存" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</layout>

View File

@@ -21,8 +21,15 @@
android:layout_marginTop="10dp"
android:orientation="vertical">
<!-- 侧滑布局 -->
<com.mcxtzhang.swipemenulib.SwipeMenuLayout
android:id="@+id/swipe_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 白色卡片 -->
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_white_radius_8"
@@ -312,8 +319,33 @@
</LinearLayout>
<!-- 右侧箭头 -->
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:src="@drawable/img_pda_right" />
</LinearLayout>
<!-- 侧滑菜单区域 -->
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- 编辑按钮 -->
<TextView
android:id="@+id/btn_edit"
style="@style/tv_item_action"
android:background="@color/colorPrimary"
android:text="编辑" />
</androidx.appcompat.widget.LinearLayoutCompat>
</com.mcxtzhang.swipemenulib.SwipeMenuLayout>
</LinearLayout>
</layout>