refactor(food): 统一商品数据模型字段映射逻辑

- 在 FoodSearchDialog 中添加 oldGoodsId 字段赋值逻辑
- 在 VectorCollectionFragment 中统一商品 ID 映射处理
- 将 goodsId 字段更新为 materId 的值或空字符串
- 保留原始 goodsId 值到 oldGoodsId 字段用于回溯
- 简化代码中的循环变量引用方式
This commit is contained in:
2026-05-14 15:42:07 +08:00
parent fee9598689
commit b44f4aae5a
2 changed files with 7 additions and 3 deletions
@@ -243,6 +243,8 @@ class FoodSearchDialog(
records.forEach { records.forEach {
it.rawMaterialsTypes = it.rawMaterialsType it.rawMaterialsTypes = it.rawMaterialsType
it.rawMaterialsType = null it.rawMaterialsType = null
it.oldGoodsId = it.goodsId
it.goodsId = it.materId ?: ""
} }
list.addAll(records) list.addAll(records)
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
@@ -398,9 +398,11 @@ class VectorCollectionFragment : BaseFragment<FragmentVectorCollectionBinding>()
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
private fun fillSearchList(list: List<GoodsItem>) { private fun fillSearchList(list: List<GoodsItem>) {
// 将 rawMaterialsType 转存到 rawMaterialsTypes,并清空 rawMaterialsType // 将 rawMaterialsType 转存到 rawMaterialsTypes,并清空 rawMaterialsType
list.forEach { item -> list.forEach {
item.rawMaterialsTypes = item.rawMaterialsType it.rawMaterialsTypes = it.rawMaterialsType
item.rawMaterialsType = null it.rawMaterialsType = null
it.oldGoodsId = it.goodsId
it.goodsId = it.materId ?: ""
} }
// 空布局切过 LinearLayoutManager,此处恢复为 2 列 GridLayoutManager // 空布局切过 LinearLayoutManager,此处恢复为 2 列 GridLayoutManager
if (binding.rvSearchFood.layoutManager !is GridLayoutManager) { if (binding.rvSearchFood.layoutManager !is GridLayoutManager) {