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
54
package com.xw.yunwei.ui.work.car.detail.operations.repair.record
 
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.CarOperationRecordModel
import com.xw.yunwei.net.WorkRepository
import org.koin.core.component.inject
import kotlin.getValue
 
class RecordVM(application: Application): BasePagingViewModel(application) {
 
    val workRepository: WorkRepository by inject()
    val dataList: MutableLiveData<List<CarOperationRecordModel>> = MutableLiveData()
    var dataType: Int = 0
    var carId = 0L
 
    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 map = mapOf(
                "operationType" to (dataType + 1),
                "pageNum" to index,
                "pageSize" to pageSize,
                "vehicleId" to carId,
            )
            val data = workRepository.getRecord(map)
 
            val list: MutableList<CarOperationRecordModel> = 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
        }
    }
}