fix: 图片控件优化及多处字段修正
- 图片选择控件:加号按钮灰色背景、label 样式统一、图片区域并入表单卡片 - 国内进港移交:修复图片上传未提交 bug,从 adapter 实时获取图片列表 - 国内进港移库列表:添加右侧箭头,已出库禁止编辑 - 国际事故签证列表:修正 Bean 字段名匹配 API(dep/dest/pc/weight/dpc) - 国际进港舱单:实到件数、计费重量、品名(中) 设为必填 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,9 @@ class GnjYiKuHandoverActivity :
|
||||
|
||||
binding.viewModel = viewModel
|
||||
|
||||
// 绑定图片 RecyclerView 引用
|
||||
viewModel.rvImages = binding.rvImages
|
||||
|
||||
// 绑定图片列表点击事件(编辑模式下可删除图片)
|
||||
binding.rvImages.addOnItemClickListener(viewModel)
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ 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 androidx.recyclerview.widget.RecyclerView
|
||||
import com.lukouguoji.module_base.util.MediaUtil
|
||||
import com.lukouguoji.module_base.util.UploadUtil
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -40,6 +43,9 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
// 详情模式下无图片时显示占位提示
|
||||
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.Modify.name
|
||||
@@ -56,9 +62,9 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
val bean = it.data ?: GnjYiKuBean()
|
||||
dataBean.value = bean
|
||||
|
||||
// 处理图片列表
|
||||
// 处理图片列表(拼接完整 URL)
|
||||
val images = bean.getImageList().map { url ->
|
||||
FileBean(path = url)
|
||||
FileBean(path = MediaUtil.fillUrl(url), url = url)
|
||||
}.toMutableList()
|
||||
|
||||
// 编辑模式添加空 FileBean 用于显示"添加照片"按钮
|
||||
@@ -82,8 +88,10 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
fun submit() {
|
||||
val bean = dataBean.value ?: return
|
||||
|
||||
// 获取所有非空图片
|
||||
val images = imageList.value!!.filter { it.path.isNotEmpty() }
|
||||
// 从 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张图片")
|
||||
@@ -94,8 +102,9 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
// 上传图片
|
||||
val uploadedUrls = mutableListOf<String>()
|
||||
images.forEach { fileBean ->
|
||||
if (fileBean.path.startsWith("http")) {
|
||||
uploadedUrls.add(fileBean.path)
|
||||
if (fileBean.url.isNotEmpty()) {
|
||||
// 已上传的图片,直接用文件名
|
||||
uploadedUrls.add(fileBean.url)
|
||||
} else {
|
||||
val result = UploadUtil.upload(fileBean.path)
|
||||
if (result.verifySuccess()) {
|
||||
@@ -127,10 +136,11 @@ class GnjYiKuHandoverViewModel : BaseViewModel(), IOnItemClickListener {
|
||||
* 处理图片删除点击事件
|
||||
*/
|
||||
override fun onItemClick(position: Int, type: Int) {
|
||||
val list = imageList.value!!
|
||||
if (type == R.id.iv_delete && position < list.size) {
|
||||
list.removeAt(position)
|
||||
imageList.value = list
|
||||
if (type == R.id.iv_delete) {
|
||||
val adapter = rvImages?.commonAdapter() ?: return
|
||||
if (position < adapter.items.size) {
|
||||
adapter.removeItem(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
@@ -189,43 +188,39 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 交接图片区域 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:background="@drawable/bg_white_radius_8"
|
||||
android:orientation="vertical"
|
||||
android:padding="15dp">
|
||||
|
||||
<TextView
|
||||
<!-- 交接图片区域:label 在左,图片在右 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="交接图片"
|
||||
android:textColor="@color/text_normal"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
android:layout_marginTop="15dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:overScrollMode="never"
|
||||
itemLayoutId="@{viewModel.imageItemLayoutId}"
|
||||
viewHolder="@{viewModel.imageItemViewHolder}"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="6" />
|
||||
<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="80dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:background="@color/white"
|
||||
android:layout_height="60dp"
|
||||
android:gravity="center"
|
||||
android:text="暂无图片"
|
||||
android:textColor="@color/text_gray"
|
||||
@@ -234,35 +229,32 @@
|
||||
|
||||
</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.getTopActivity().finish()}"
|
||||
android:text="取消" />
|
||||
|
||||
<TextView
|
||||
style="@style/tv_bottom_btn"
|
||||
android:layout_width="120dp"
|
||||
android:onClick="@{()-> viewModel.submit()}"
|
||||
android:text="保存" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<!-- 底部按钮(详情模式不显示) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:background="@color/white"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="@{viewModel.pageType != DetailsPageType.Details ? View.VISIBLE : View.GONE}">
|
||||
|
||||
<TextView
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:background="@drawable/bg_gray_radius_4"
|
||||
android:gravity="center"
|
||||
android:onClick="@{()-> viewModel.getTopActivity().finish()}"
|
||||
android:text="取消"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
style="@style/tv_bottom_btn_lg"
|
||||
android:onClick="@{()-> viewModel.submit()}"
|
||||
android:text="保存" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user