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 ?: "未知错误")
|
}
|
}
|
}
|
}
|
|
|
}
|