18034727885
2026-04-14 370014cbb9ec1ef64e7e42bb4f9a12671461d8e4
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
package com.xw.yunwei.ui.work.notice
 
import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.xw.common.base.BasePagingViewModel
import com.xw.common.utils.ToastUtilCommon
import com.xw.yunwei.model.NoticeModel
import com.xw.yunwei.net.UserRepository
import org.koin.core.component.inject
 
class NoticeVM(application: Application) : BasePagingViewModel(application) {
 
    val userRepository: UserRepository by inject()
 
    val dataList: MutableLiveData<List<NoticeModel>> = MutableLiveData()
 
    override fun getDataList(index: Int) {
        if (index == 1) {
            refreshLiveData.refresh()
        } else {
            refreshLiveData.loading()
        }
        launchRequest(showLoading = false, error = { code, msg ->
            ToastUtilCommon.showError(msg)
            refreshLiveData.done()
        }) {
            val data = userRepository.getNoticeList(mapOf("pageNum" to index, "pageSize" to pageSize))
            val list: MutableList<NoticeModel> = ArrayList()
            if (index == 1) {
                refreshLiveData.first()
            } else {
                refreshLiveData.other()
                list.addAll(dataList.value ?: ArrayList())
            }
            for (item in data?.records ?: ArrayList()) {
                list.add(item)
            }
            if ((data?.total ?: 0) <= list.size) {
                refreshLiveData.done()
            }
            dataList.postValue(list)
            pageNo = index
        }
    }
 
    fun setRead(id: Long, block: () -> Unit) {
        launchRequest {
            userRepository.read(id)
            runOnMainThread { block() }
        }
    }
 
}