package com.example.smart.ui.plan
|
|
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.plan.data.CheckTaskBean
|
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.launch
|
|
|
class PlanViewModel : BaseContextViewModel() {
|
|
val projectBean = MutableLiveData<List<CheckTaskBean>>()
|
|
|
fun requestProjectData(planId: Int, fail: (String) -> Unit) {
|
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
callList(RetrofitClient.api.getTaskList(planId)) }.apply {
|
if (this is Result.Success) {
|
projectBean.value = data
|
} else if (this is Result.Error) {
|
fail(exception.message ?: "未知错误")
|
}
|
}
|
}
|
}
|
|
|
}
|