- 新增入库专用网络层(InboundApiService、InboundRepository、InboundNetworkModule、InboundInterceptor) - 新增入库相关数据模型(IngredientByTrace、SupplierOption、ZoneOption、GoodsSearchModel、CleanInboundParam、RawInboundParam、InboundApiResponse) - 新增 FormField 动态表单模型(FieldType 枚举、apiKey 字段映射、submitValueId 控制提交值) - 新增 FormFieldAdapter,基于 FlexboxLayoutManager 实现两列自动换行表单,支持五种字段类型 - 新增 InboundGoodsSearchDialog(溯源码检索食材)和 InboundGoodsStoreDialog(入库录入,表单转 Map 提交) - 新增 StoreViewModel,提交接口入参改为 Map<String, Any> - 重构 StoreActivity:注入 StoreViewModel,onResume 预加载供应商/区域列表到 GlobalData - 修改 GoodsListActivity:抽取 onGoodsSearchRequested() 供子类重写 - 修改 GoodsRecognizeDialog:StoreActivity 场景下打开 InboundGoodsStoreDialog - GlobalData 新增 inboundSupplierList / inboundZoneList 全局缓存 - build.gradle.kts 新增 flexbox:3.0.0 依赖 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
159 lines
5.3 KiB
Kotlin
159 lines
5.3 KiB
Kotlin
package com.sw.inbound.dialog
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.sw.inbound.activity.GoodsListActivity
|
|
import com.sw.inbound.activity.StoreActivity
|
|
import com.sw.inbound.adapter.RecognizeAdapter
|
|
import com.sw.inbound.databinding.DialogGoodsRecognizeBinding
|
|
import com.sw.inbound.model.response.GoodsSearchModel
|
|
import com.sw.inbound.model.response.SearchGoodsInfo
|
|
import com.sw.inbound.utils.ext.clickWithDebounce
|
|
import com.sw.inbound.utils.ext.gone
|
|
import com.sw.inbound.utils.ext.visible
|
|
import java.io.File
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
class GoodsRecognizeDialog(
|
|
context: Context,
|
|
var goodsFile: File? = null,
|
|
var goodsName: String? = null,
|
|
var list: MutableList<SearchGoodsInfo.Record>,
|
|
//var closeCallback:()->Unit,
|
|
var findGoods: () -> Unit
|
|
) : BaseDialog(context) {
|
|
|
|
private lateinit var binding: DialogGoodsRecognizeBinding
|
|
private lateinit var inflater: LayoutInflater
|
|
override fun getRootView(): View {
|
|
inflater = LayoutInflater.from(context)
|
|
binding = DialogGoodsRecognizeBinding.inflate(inflater)
|
|
return binding.root
|
|
}
|
|
|
|
// override fun show() {
|
|
// super.show()
|
|
// binding.ivGoods.load(goodsFile)
|
|
// binding.tvGoods.text = goodsName
|
|
// }
|
|
|
|
private val recognizeAdapter by lazy {
|
|
RecognizeAdapter(list).apply {
|
|
// isStateViewEnable = true
|
|
setOnItemClickListener { adapter, view, position ->
|
|
if (list[position].isSelected) {
|
|
showGoodsStoreDialog(position)
|
|
return@setOnItemClickListener
|
|
}
|
|
list.forEach { item ->
|
|
item.isSelected = false
|
|
}
|
|
list[position].isSelected = true
|
|
notifyDataSetChanged()
|
|
showGoodsStoreDialog(position)
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun showGoodsStoreDialog(position: Int) {
|
|
if (activity is StoreActivity) {
|
|
// 入库称重页面:识别结果无溯源码,直接用物品名称构造 GoodsSearchModel 打开入库录入弹窗
|
|
val goods = list[position]
|
|
InboundGoodsStoreDialog(
|
|
context = context,
|
|
goods = GoodsSearchModel(materName = goods.goodsName ?: "")
|
|
) {
|
|
dismiss()
|
|
}.show()
|
|
return
|
|
}
|
|
GoodsStoreDialog(
|
|
context = context,
|
|
funcType = 0,
|
|
goods = list[position]
|
|
) {
|
|
activity?.addGoods(it)
|
|
//activity?.startTime = System.currentTimeMillis()
|
|
dismiss()
|
|
}.show()
|
|
}
|
|
|
|
private var activity: GoodsListActivity? = null
|
|
override fun initView() {
|
|
activity = getReceiptActivity()
|
|
binding.rvRecognize.let {
|
|
it.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
|
it.adapter = recognizeAdapter
|
|
}
|
|
val isEmpty = list.isEmpty()
|
|
if (isEmpty) {
|
|
// loadEmptyView()
|
|
binding.rvRecognize.gone()
|
|
binding.flEmptyLayout.visible()
|
|
} else {
|
|
binding.rvRecognize.visible()
|
|
binding.flEmptyLayout.gone()
|
|
}
|
|
// if (recognizeAdapter.list.isEmpty()) {
|
|
// loadEmptyView()
|
|
// }
|
|
binding.ivClose.setOnClickListener {
|
|
dismiss()
|
|
// activity?.delayRecognizeFood()
|
|
//activity?.startTime = System.currentTimeMillis()
|
|
}
|
|
binding.btnManuallyFind.setOnClickListener {
|
|
findGoods()
|
|
//dismiss()
|
|
}
|
|
binding.btnAgainRecognize.clickWithDebounce(1000) {
|
|
//dismiss()
|
|
activity?.againRecognizeFood { goodsList ->
|
|
//binding.rvRecognize.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
|
if (goodsList.isEmpty()) {
|
|
// loadEmptyView()
|
|
binding.rvRecognize.gone()
|
|
binding.flEmptyLayout.visible()
|
|
return@againRecognizeFood
|
|
}
|
|
list.clear()
|
|
list.addAll(goodsList)
|
|
// recognizeAdapter.isStateViewEnable = false
|
|
recognizeAdapter.notifyDataSetChanged()
|
|
|
|
binding.rvRecognize.visible()
|
|
binding.flEmptyLayout.gone()
|
|
}
|
|
}
|
|
}
|
|
|
|
// private var emptyBinding: LayoutEmptyRecognizeBinding? = null
|
|
private fun loadEmptyView() {
|
|
// if (emptyBinding == null) {
|
|
// emptyBinding = LayoutEmptyRecognizeBinding.inflate(inflater, binding.flEmptyLayout, false)
|
|
// }
|
|
// binding.flEmptyLayout.removeAllViews()
|
|
// emptyBinding?.root.let {
|
|
// binding.flEmptyLayout.addView(it)
|
|
// }
|
|
binding.rvRecognize.gone()
|
|
binding.flEmptyLayout.visible()
|
|
// emptyBinding?.root?.let {
|
|
// recognizeAdapter.isStateViewEnable = true
|
|
// recognizeAdapter.stateView = it
|
|
// }
|
|
}
|
|
|
|
|
|
override fun dismiss() {
|
|
super.dismiss()
|
|
activity?.run {
|
|
isShowRecognizeDialog = true
|
|
goodsRecognizeDialog = null
|
|
}
|
|
}
|
|
|
|
} |