18034727885
2026-04-27 3a4c1bbb2cf4fb1cdda8a5061b0674f30e7456b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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<CommonOptionsBean>) -> 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)
                }
            }
        }
    }
}