feat: 国际出港查询详情 tab 仓库信息
This commit is contained in:
@@ -6,17 +6,23 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.lukouguoji.gjc.R
|
||||
import com.lukouguoji.gjc.databinding.FragmentGjcQueryWarehouseBinding
|
||||
import com.lukouguoji.gjc.holder.GjcQueryWarehouseViewHolder
|
||||
import com.lukouguoji.gjc.viewModel.GjcQueryDetailsViewModel
|
||||
import com.lukouguoji.module_base.base.CommonAdapter
|
||||
import com.lukouguoji.module_base.bean.GjcWarehouse
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
|
||||
/**
|
||||
* 国际出港查询详情 - 仓库信息Fragment (空实现)
|
||||
* 国际出港查询详情 - 仓库信息Fragment
|
||||
*/
|
||||
class GjcQueryWarehouseFragment : Fragment() {
|
||||
|
||||
private lateinit var binding: FragmentGjcQueryWarehouseBinding
|
||||
private lateinit var viewModel: GjcQueryDetailsViewModel
|
||||
private lateinit var adapter: CommonAdapter
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -30,9 +36,58 @@ class GjcQueryWarehouseFragment : Fragment() {
|
||||
false
|
||||
)
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
initRecyclerView()
|
||||
observeData()
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化RecyclerView
|
||||
*/
|
||||
private fun initRecyclerView() {
|
||||
adapter = CommonAdapter(
|
||||
requireContext(),
|
||||
R.layout.item_gjc_query_warehouse,
|
||||
GjcQueryWarehouseViewHolder::class.java
|
||||
)
|
||||
|
||||
binding.rvWarehouseList.apply {
|
||||
layoutManager = LinearLayoutManager(requireContext())
|
||||
adapter = this@GjcQueryWarehouseFragment.adapter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 观察数据变化
|
||||
*/
|
||||
private fun observeData() {
|
||||
viewModel.warehouseList.observe(viewLifecycleOwner) { mapList ->
|
||||
if (mapList.isEmpty()) {
|
||||
// 显示空数据提示
|
||||
binding.rvWarehouseList.visibility = View.GONE
|
||||
binding.llEmpty.visibility = View.VISIBLE
|
||||
} else {
|
||||
// Map → GjcWarehouse Bean 转换
|
||||
val beanList = mapList.map { map ->
|
||||
try {
|
||||
val json = NetApply.gson.toJson(map)
|
||||
NetApply.gson.fromJson(json, GjcWarehouse::class.java)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
GjcWarehouse() // 转换失败返回空对象
|
||||
}
|
||||
}
|
||||
|
||||
// 更新RecyclerView
|
||||
binding.rvWarehouseList.visibility = View.VISIBLE
|
||||
binding.llEmpty.visibility = View.GONE
|
||||
adapter.refresh(beanList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(vm: GjcQueryDetailsViewModel) =
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.lukouguoji.gjc.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemGjcQueryWarehouseBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.GjcWarehouse
|
||||
|
||||
/**
|
||||
* 国际出港查询详情-仓库信息ViewHolder
|
||||
*/
|
||||
class GjcQueryWarehouseViewHolder(view: View) :
|
||||
BaseViewHolder<GjcWarehouse, ItemGjcQueryWarehouseBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position // 用于显示序号和背景切换
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user