18034727885
2026-06-26 253f680fb9666751e0f9a8e5e8f2f9e3eb1894e3
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
package com.example.smart.ui.project.check
 
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.reqeust.RetrofitClient.getBody
import com.example.smart.ui.home.page.data.PageReq
import com.example.smart.ui.project.check.bean.CheckBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
 
class CheckViewModel : BaseContextViewModel() {
 
    val checkList = MutableLiveData<List<CheckBean>>()
 
    fun getDataList(id: String, mine: Boolean, fail: (String) -> Unit) {
        val params = PageReq()
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                execute(RetrofitClient.api.checkList(params, id, mine))
            }.apply {
                if (this is Result.Success) {
                    checkList.value = data.list ?: ArrayList()
                } else if (this is Result.Error) {
                    fail(exception.message ?: "未知错误")
                }
            }
        }
    }
 
 
    fun addCheckInfo(item: CheckBean, suc: () -> Unit) {
        val map = mapOf(
            "checkTaskIdId" to item.checkTaskId,
            "title" to item.title,
            "safetySlip" to item.safetySlip,
            "checkUserImg" to item.checkUserImg,
            "integrityNotification" to item.integrityNotification,
        )
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callNoResult(RetrofitClient.api.addCheck(getBody(map)))
            }.apply {
                if (this is Result.SuccessNone) {
                    suc.invoke()
                } else if (this is Result.Error) {
                    com.blankj.utilcode.util.ToastUtils.showLong(exception.message ?: "未知错误")
                }
            }
        }
    }
 
    fun editCheckInfo(item: CheckBean, suc: () -> Unit) {
        val map = mapOf(
            "id" to item.id,
            "title" to item.title,
            "safetySlip" to item.safetySlip,
            "checkUserImg" to item.checkUserImg,
            "integrityNotification" to item.integrityNotification,
        )
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callNoResult(RetrofitClient.api.editCheck(getBody(map)))
            }.apply {
                if (this is Result.SuccessNone) {
                    suc.invoke()
                } else if (this is Result.Error) {
                    com.blankj.utilcode.util.ToastUtils.showLong(exception.message ?: "未知错误")
                }
            }
        }
    }
 
    fun deleteCheckInfo(item: CheckBean, suc: () -> Unit) {
        val map = mapOf(
            "ids" to arrayOf(item.id)
        )
        viewModelScope.launch(Dispatchers.Main) {
            safeCall {
                callNoResult(RetrofitClient.api.deleteCheck(getBody(map)))
            }.apply {
                if (this is Result.SuccessNone) {
                    suc.invoke()
                } else if (this is Result.Error) {
                    com.blankj.utilcode.util.ToastUtils.showLong(exception.message ?: "未知错误")
                }
            }
        }
    }
 
}