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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.example.smart.ui.creatplan
 
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.bean.CommonOptionsBean
import com.example.smart.reqeust.RetrofitClient
import com.example.smart.reqeust.deviceFuzzyPath
import com.example.smart.reqeust.deviceModelPath
import com.example.smart.reqeust.deviceScorePath
import com.example.smart.reqeust.entrustPath
import com.example.smart.ui.creatplan.bean.CreatePlanParam
import com.example.smart.widget.CommonOptionViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
 
 
class CreatePlanViewModel() : CommonOptionViewModel() {
 
 
    val systemOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
 
    val systemScoreOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
    val systemFuzzyOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
 
 
    val deviceOptionBeans = MutableLiveData<List<CommonOptionsBean>>()
 
    val deviceScoreOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
    val deviceFuzzyOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
 
    val entrustOptionsBean = MutableLiveData<List<CommonOptionsBean>>()
 
 
    val createResult = MutableLiveData<String>()
 
 
    val searchResult = MutableLiveData<ArrayList<CommonOptionsBean>>()
 
 
    @Deprecated("弃用,目前直接给下拉框")
    fun searchEntrustName(keyword: String, fail: (String) -> Unit) {
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callList(RetrofitClient.api.searchEntrust(keyword))
            }.apply {
                if (this is Result.Success) {
                    searchResult.value = data as ArrayList<CommonOptionsBean>
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
        }
    }
 
    /**
     * 请求委托方选项
     */
    fun requestEntrustOption() {
        callOption(entrustPath, entrustOptionsBean)
    }
 
    /**
     * 综合体系模型
     */
    fun requestSystemOptions(fail: (String) -> Unit) {
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callList(RetrofitClient.api.systemOptions())
            }.apply {
                if (this is Result.Success) {
                    systemOptionsBean.value = data
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
        }
    }
 
 
    /**
     *  综合体系模型子模型
     *  综合打分专家&综合模糊专家
     */
    fun requestSystemChildOptions(id: String, fail: (String) -> Unit) {
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callList(RetrofitClient.api.systemScoreOption(id))
            }.apply {
                if (this is Result.Success) {
                    systemScoreOptionsBean.value = data
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
 
            safeCall {
                callList(RetrofitClient.api.systemFuzzyOption(id))
            }.apply {
                if (this is Result.Success) {
                    systemFuzzyOptionsBean.value = data
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
        }
 
    }
 
 
    /**
     * 设备体系模型
     */
    fun requestDeviceSystemOptions() {
        callOption(deviceModelPath, deviceOptionBeans)
    }
 
    /**
     * 设备体系模型子成分
     * 设备模糊专家
     * 设备打分专家
     */
    fun callDeviceSystemChildOptions(id: String) {
        callOption(deviceScorePath, deviceScoreOptionsBean, id)
        callOption(deviceFuzzyPath, deviceFuzzyOptionsBean, id)
    }
 
 
    /**
     * 新建计划接口
     */
    fun createItem(param: CreatePlanParam, fail: (String) -> Unit) {
 
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callNoResult(RetrofitClient.api.createPlan(param))
            }.apply {
                if (this is Result.SuccessNone) {
                    createResult.value = status
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
        }
    }
 
 
}