package com.example.smart.ui.item; import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.example.basecore.base.BaseContextViewModel import com.example.smart.reqeust.RetrofitClient import com.example.smart.ui.project.bean.TaskDetailInfo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import com.example.basecore.net.http.Result import com.example.smart.bean.CommonOptionsBean class CreateMissionViewModel() : BaseContextViewModel() { fun createTask(bean: TaskDetailInfo, success: () -> Unit, fail: (String) -> Unit) { // 创建任务 viewModelScope.launch(Dispatchers.Main) { safeCall { callNoResult(RetrofitClient.api.createTask(bean)) }.apply { if (this is Result.SuccessNone) { success() } else if (this is Result.Error) { fail(exception.message ?: "未知错误") } } } } /** * 获取计划可用的项目列表 */ fun getAvailableProjects(planId: Int, success: (List) -> Unit) { viewModelScope.launch(Dispatchers.Main) { safeCall { callList(RetrofitClient.api.availableProjects(planId)) }.apply { if (this is Result.Success) { success(data) } } } } /** * 获取项目详情 */ fun getProjectDetail(projectId: Int, success: (com.example.smart.ui.item.bean.ProjectInfoParam?) -> Unit) { viewModelScope.launch(Dispatchers.Main) { safeCall { execute(RetrofitClient.api.projectDetails(projectId)) }.apply { if (this is Result.Success) { success(data) } else { success(null) } } } } /** * 获取当前用户信息 */ fun getCurrentUserProfile(success: (com.example.smart.bean.ProfileBean?) -> Unit) { viewModelScope.launch(Dispatchers.Main) { safeCall { execute(RetrofitClient.api.getProfileInfo()) }.apply { if (this is Result.Success) { success(data) } else { success(null) } } } } }