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
|
}
|
}
|
}
|