添加了界面及逻辑
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package com.sw.platecabinet.viewmodel
|
||||
|
||||
import com.sw.platecabinet.GlobalData.globalEquipmentCode
|
||||
import com.sw.platecabinet.model.ErrorInfo
|
||||
import com.sw.platecabinet.model.request.BindParam
|
||||
import com.sw.platecabinet.model.request.EquipmentParam
|
||||
import com.sw.platecabinet.model.request.SearchParam
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.model.response.SearchResult
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
@@ -10,12 +15,99 @@ class SettingViewModel : BaseViewModel() {
|
||||
private val _equipmentList = MutableStateFlow<List<EquipmentUserInfo>>(emptyList())
|
||||
val equipmentList: StateFlow<List<EquipmentUserInfo>> = _equipmentList
|
||||
|
||||
fun getEquipmentList(param: EquipmentParam) {
|
||||
private val _searchMemberList = MutableStateFlow<List<SearchResult.Member>>(emptyList())
|
||||
val searchMemberList: StateFlow<List<SearchResult.Member>> = _searchMemberList
|
||||
|
||||
var currentPage = 1
|
||||
var isLoading = false
|
||||
var canLoadMore = true
|
||||
|
||||
/**
|
||||
* 绑定/解绑状态 <绑定/解绑, 错误信息,>
|
||||
*/
|
||||
private val _bindStateChange = MutableStateFlow<Pair<Boolean?, ErrorInfo>>(null to ErrorInfo())
|
||||
val bindStateChange: StateFlow<Pair<Boolean?, ErrorInfo>> = _bindStateChange
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备绑定用户信息列表
|
||||
*/
|
||||
fun getEquipmentList(equipmentCode: String = globalEquipmentCode) {
|
||||
launchWithLoading {
|
||||
val param = EquipmentParam(equipmentCode = equipmentCode)
|
||||
val response = repository.getEquipmentList(param)
|
||||
if (parseResponse(response)) {
|
||||
_equipmentList.value = response.data ?: emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索会员信息列表
|
||||
*/
|
||||
fun getSearchMemberList(param: String, pageNum: Int = 1, pageSize: Int = 50) {
|
||||
currentPage = pageNum
|
||||
launch {
|
||||
val param = SearchParam(
|
||||
param = param,
|
||||
pageNum = pageNum,
|
||||
pageSize = pageSize
|
||||
)
|
||||
isLoading = true
|
||||
val response = repository.searchUser(param)
|
||||
isLoading = false
|
||||
if (parseResponse(response)) {
|
||||
response.data?.let {
|
||||
canLoadMore = it.hasNextPage != false
|
||||
val newList = it.list ?: emptyList()
|
||||
if (pageNum == 1) {
|
||||
_searchMemberList.value = newList
|
||||
} else {
|
||||
_searchMemberList.value = _searchMemberList.value.plus(newList)
|
||||
}
|
||||
currentPage++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bindPlate(
|
||||
equipmentBoxCode: String,
|
||||
equipmentCode: String = globalEquipmentCode,
|
||||
memberId: Int,
|
||||
plateNumber: String
|
||||
) {
|
||||
launchWithLoading {
|
||||
val bindParam = BindParam(
|
||||
equipmentBoxCode = equipmentBoxCode,
|
||||
equipmentCode = equipmentCode,
|
||||
memberId = memberId,
|
||||
plateNumber = plateNumber
|
||||
)
|
||||
val response = repository.bindEquipment(bindParam)
|
||||
if (parseResponse(response)) {
|
||||
_bindStateChange.value = true to ErrorInfo()
|
||||
} else {
|
||||
_bindStateChange.value = true to ErrorInfo(response.code, response.msg.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun unbindPlate(
|
||||
equipmentBoxCode: String,
|
||||
equipmentCode: String = globalEquipmentCode
|
||||
) {
|
||||
launchWithLoading {
|
||||
val bindParam = BindParam(
|
||||
equipmentBoxCode = equipmentBoxCode,
|
||||
equipmentCode = equipmentCode
|
||||
)
|
||||
val response = repository.bindEquipment(bindParam)
|
||||
if (parseResponse(response)) {
|
||||
_bindStateChange.value = false to ErrorInfo()
|
||||
} else {
|
||||
_bindStateChange.value = false to ErrorInfo(response.code, response.msg.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user