package com.example.smart.ui.project.equiplist
|
|
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.viewModelScope
|
import com.example.basecore.base.BaseContextViewModel
|
import com.example.basecore.net.http.Result
|
import com.example.smart.reqeust.RetrofitClient
|
import com.example.smart.ui.home.page.data.PageReq
|
import com.example.smart.ui.project.equiplist.bean.EquipmentBean
|
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.launch
|
|
|
class EquipListViewModel: BaseContextViewModel( ) {
|
|
val bean = MutableLiveData<List<EquipmentBean>>()
|
|
fun callList(projectId: String, fail: (String) -> Unit) {
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
execute(RetrofitClient.api.equipmentList(projectId, PageReq())) }.apply {
|
if (this is Result.Success) {
|
bean.value = data.list
|
} else if (this is Result.Error) {
|
fail(exception.message ?: "未知错误")
|
}
|
}
|
}
|
}
|
}
|