feat: 国际出港查询详情
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package com.lukouguoji.gjc.viewModel
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.lukouguoji.gjc.fragment.GjcQueryStorageFragment
|
||||
import com.lukouguoji.gjc.fragment.GjcQueryWarehouseFragment
|
||||
import com.lukouguoji.gjc.fragment.GjcQueryWaybillFragment
|
||||
import com.lukouguoji.module_base.base.BaseViewModel
|
||||
import com.lukouguoji.module_base.common.Constant
|
||||
import com.lukouguoji.module_base.http.net.NetApply
|
||||
import com.lukouguoji.module_base.ktx.launchLoadingCollect
|
||||
import com.lukouguoji.module_base.ktx.showToast
|
||||
import com.lukouguoji.module_base.ktx.toRequestBody
|
||||
|
||||
/**
|
||||
* 国际出港查询详情-ViewModel
|
||||
*/
|
||||
class GjcQueryDetailsViewModel : BaseViewModel() {
|
||||
|
||||
// ==================== 基础数据 ====================
|
||||
var maWbId: String = "" // 运单主键ID
|
||||
|
||||
// ==================== Tab管理 ====================
|
||||
val currentTab = MutableLiveData(0) // 当前Tab索引 (0/1/2)
|
||||
|
||||
// ==================== 详情数据 ====================
|
||||
val detailData = MutableLiveData<Map<String, Any>>(emptyMap())
|
||||
|
||||
// ==================== Fragment列表 ====================
|
||||
val fragmentList by lazy {
|
||||
listOf(
|
||||
GjcQueryWaybillFragment.newInstance(this), // 运单信息
|
||||
GjcQueryWarehouseFragment.newInstance(this), // 仓库信息
|
||||
GjcQueryStorageFragment.newInstance(this) // 库位信息
|
||||
)
|
||||
}
|
||||
|
||||
// ==================== 方法区 ====================
|
||||
|
||||
/**
|
||||
* 初始化(从Intent获取maWbId)
|
||||
*/
|
||||
fun initOnCreated(intent: Intent) {
|
||||
maWbId = intent.getStringExtra(Constant.Key.ID) ?: ""
|
||||
}
|
||||
|
||||
/**
|
||||
* Tab点击事件
|
||||
*/
|
||||
fun onTabClick(index: Int) {
|
||||
currentTab.value = index
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载详情数据
|
||||
*/
|
||||
fun loadDetails() {
|
||||
if (maWbId.isEmpty()) {
|
||||
showToast("运单ID为空")
|
||||
return
|
||||
}
|
||||
|
||||
val params = mapOf("maWbId" to maWbId.toLongOrNull()).toRequestBody()
|
||||
|
||||
launchLoadingCollect({ NetApply.api.getGjcQueryDetails(params) }) {
|
||||
onSuccess = { result ->
|
||||
detailData.value = result.data ?: emptyMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user