初始代码提交
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.sw.inbound.viewmodel
|
||||
|
||||
import com.sw.inbound.model.response.SupplierInfo
|
||||
import com.sw.inbound.repository.RemoteRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* 采购订单
|
||||
*/
|
||||
@HiltViewModel
|
||||
class PurchaseOrderViewModel @Inject constructor(
|
||||
private val repository: RemoteRepository
|
||||
) : BaseViewModel(repository) {
|
||||
|
||||
/**
|
||||
* 采购订单-供应商列表
|
||||
*/
|
||||
private val _supplierList = MutableStateFlow<List<SupplierInfo?>>(emptyList())
|
||||
val supplierList: StateFlow<List<SupplierInfo?>> = _supplierList
|
||||
/**
|
||||
* 获取采购订单-供应商列表
|
||||
*/
|
||||
fun getOrderList(pageNum: Int = 1, pageSize: Int = 5) {
|
||||
if (pageNum != 1) {
|
||||
launch {
|
||||
updateMoreLoading(true)
|
||||
val response = repository.getReceiveList(pageNum, pageSize)
|
||||
updateMoreLoading(false)
|
||||
if (parseResponse(response)) {
|
||||
response.result?.let {
|
||||
updateCanLoadMore(it.size >= pageSize)
|
||||
Timber.d("加载更多 canLoadMore =${it.size >= pageSize}")
|
||||
_supplierList.value = _supplierList.value + it
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
launchWithLoading {
|
||||
val response = repository.getReceiveList(pageNum, pageSize)
|
||||
if (parseResponse(response)) {
|
||||
response.result?.let {
|
||||
_supplierList.value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleSensorScale(weight: Double) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user