- StoreActivity 进入时统一弹出 InboundGoodsSearchDialog,关闭后退出页面 - InboundGoodsStoreDialog 支持 goods 可空,适配无溯源码直接入库场景 - FormField 新增 extraApiKeys/extraValues 支持下拉多字段提交(供应商id+type、区域id+name) - DictType 新增 type 字段,供应商选项携带类型信息 - FormFieldAdapter 下拉选中时按 extraApiKeys 映射写入 extraValues - InboundApiService 使用 @JvmSuppressWildcards 修复 Retrofit Map 泛型通配符异常 - BaseActivity 改为继承 AppCompatActivity,主题切换为 MaterialComponents - 日期格式统一为 yyyy-MM-dd HH:mm:ss(去除 ISO 8601 的 T 分隔符) - 搜索列表选中逻辑修复,改用 notifyDataSetChanged 触发刷新
124 lines
4.5 KiB
Kotlin
124 lines
4.5 KiB
Kotlin
package com.sw.inbound.dialog
|
|
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import com.sw.inbound.activity.StoreActivity
|
|
import com.sw.inbound.adapter.InboundSearchAdapter
|
|
import com.sw.inbound.databinding.DialogInboundGoodsSearchBinding
|
|
import com.sw.inbound.databinding.LayoutEmptySearchBinding
|
|
import com.sw.inbound.model.response.GoodsSearchModel
|
|
import com.sw.inbound.utils.ext.addOnActionSearchListener
|
|
import com.sw.inbound.utils.ext.hideKeyboard
|
|
import com.sw.inbound.utils.ext.toast
|
|
|
|
/** 入库物品检索弹窗,使用溯源码查询食材,供 StoreActivity 使用 */
|
|
class InboundGoodsSearchDialog(
|
|
context: Context
|
|
) : BaseDialog(context) {
|
|
|
|
private lateinit var inflater: LayoutInflater
|
|
private var emptyBinding: LayoutEmptySearchBinding? = null
|
|
private lateinit var binding: DialogInboundGoodsSearchBinding
|
|
|
|
override fun getRootView(): View {
|
|
inflater = LayoutInflater.from(context)
|
|
binding = DialogInboundGoodsSearchBinding.inflate(inflater)
|
|
return binding.root
|
|
}
|
|
|
|
private var storeActivity: StoreActivity? = null
|
|
|
|
override fun initView() {
|
|
storeActivity = getReceiptActivity() as? StoreActivity
|
|
binding.tvDialogTitle.text = if (storeActivity?.storeType == 1) "毛菜检索" else "净菜检索"
|
|
binding.ivClose.setOnClickListener { dismiss() }
|
|
binding.ivGoodsSearch.setOnClickListener { searchGoods() }
|
|
binding.etInputGoods.addOnActionSearchListener { searchGoods() }
|
|
binding.btnAddGoods.setOnClickListener {
|
|
InboundGoodsStoreDialog(context = context, goods = null) {
|
|
dismiss()
|
|
}.show()
|
|
}
|
|
binding.btnConfirm.setOnClickListener {
|
|
if (list.isEmpty()) {
|
|
context.toast("请搜索物品")
|
|
return@setOnClickListener
|
|
}
|
|
if (clickIndex == -1) {
|
|
context.toast("请选择物品")
|
|
return@setOnClickListener
|
|
}
|
|
InboundGoodsStoreDialog(
|
|
context = context,
|
|
goods = list[clickIndex]
|
|
) {
|
|
storeActivity?.goodsRecognizeDialog?.dismiss()
|
|
dismiss()
|
|
}.show()
|
|
}
|
|
binding.rvSearch.let {
|
|
it.layoutManager = GridLayoutManager(context, 2, LinearLayoutManager.VERTICAL, false)
|
|
it.adapter = searchAdapter
|
|
}
|
|
binding.refreshLayout.let {
|
|
it.setEnableRefresh(false)
|
|
it.setEnableLoadMore(false)
|
|
}
|
|
loadEmptyView()
|
|
}
|
|
|
|
private fun searchGoods() {
|
|
val traceCode = binding.etInputGoods.text.toString().trim()
|
|
if (traceCode.isBlank()) {
|
|
context.toast("请输入溯源码")
|
|
return
|
|
}
|
|
storeActivity?.storeViewModel?.getIngredientByTrace(traceCode) { items ->
|
|
binding.etInputGoods.hideKeyboard()
|
|
val models = items.map { GoodsSearchModel.from(it) }
|
|
if (models.isEmpty()) {
|
|
loadEmptyView()
|
|
searchAdapter.submitList(emptyList())
|
|
return@getIngredientByTrace
|
|
}
|
|
list.clear()
|
|
list.addAll(models)
|
|
binding.rvSearch.layoutManager =
|
|
GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false)
|
|
searchAdapter.submitList(list.toList())
|
|
}
|
|
}
|
|
|
|
private fun loadEmptyView() {
|
|
binding.rvSearch.layoutManager =
|
|
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
|
if (emptyBinding == null) {
|
|
emptyBinding = LayoutEmptySearchBinding.inflate(inflater, binding.rvSearch, false)
|
|
}
|
|
emptyBinding?.run {
|
|
tvContent.text = "请检查溯源码或稍后重试"
|
|
root.setOnClickListener { root.hideKeyboard() }
|
|
searchAdapter.stateView = root
|
|
}
|
|
}
|
|
|
|
private var clickIndex = -1
|
|
private val list: MutableList<GoodsSearchModel> = mutableListOf()
|
|
|
|
private val searchAdapter by lazy {
|
|
InboundSearchAdapter().apply {
|
|
isStateViewEnable = true
|
|
setOnItemClickListener { _, _, position ->
|
|
clickIndex = position
|
|
if (list[position].isSelected) return@setOnItemClickListener
|
|
list.forEach { it.isSelected = false }
|
|
list[position].isSelected = true
|
|
notifyDataSetChanged()
|
|
}
|
|
}
|
|
}
|
|
}
|