package com.example.smart.ui.sign
|
|
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.sign.bean.SignRequestBean
|
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.launch
|
|
|
class SignViewModel: BaseContextViewModel( ) {
|
|
val signResult = MutableLiveData<String>()
|
|
/**
|
* 个人签到
|
*/
|
fun signForWork(bean: SignRequestBean, fail: (String) -> Unit) {
|
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
callNoResult(RetrofitClient.api.workSign(bean)) }.apply {
|
if (this is Result.SuccessNone) {
|
signResult.value = status
|
} else if (this is Result.Error) {
|
fail(exception.message ?: "未知错误")
|
}
|
}
|
}
|
}
|
|
|
/**
|
* 项目签到
|
*/
|
fun signForProject(bean: SignRequestBean, fail: (String) -> Unit) {
|
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
callNoResult(RetrofitClient.api.projectSign(bean)) }.apply {
|
if (this is Result.SuccessNone) {
|
signResult.value = status
|
} else if (this is Result.Error) {
|
fail(exception.message ?: "未知错误")
|
}
|
}
|
}
|
}
|
|
|
|
|
}
|