package com.xw.yunwei.ui.work.site
|
|
import android.app.Application
|
import androidx.lifecycle.MutableLiveData
|
import com.xw.common.Constants
|
import com.xw.common.base.BaseViewModel
|
import com.xw.yunwei.model.FenceInfoModel
|
import com.xw.yunwei.model.SiteModel
|
import com.xw.yunwei.model.sitePlaceHolder
|
import com.xw.yunwei.net.WorkRepository
|
import org.koin.core.component.inject
|
|
class SiteNavVM(application: Application) : BaseViewModel(application) {
|
|
val workRepository: WorkRepository by inject()
|
|
val filterStatus = listOf(
|
"全部", "可运营", "待生效","启用中", "已停用", "失效"
|
)
|
|
val selectStatus = mutableListOf<String>(filterStatus[0])
|
|
val dataList: MutableLiveData<List<SiteModel>> = MutableLiveData()
|
|
var siteItem: MutableLiveData<SiteModel?> = MutableLiveData() // 站点详情
|
var fences: MutableLiveData<List<FenceInfoModel>> = MutableLiveData() // 站点详情
|
|
val search = MutableLiveData("")
|
var cityCode: String = ""
|
|
//是否已经筛选
|
fun hadFilter(): Boolean {
|
return selectStatus.count { it != filterStatus[0] } > 0
|
}
|
|
fun query(lat: Double? = null, lon: Double? = null) {
|
launchRequest {
|
val map = mutableMapOf<String, Any?>()
|
// 运营状态 1=待启用 2=启用中 3=已停用 4=已失效
|
// map["operationStatus"] =
|
// if (selectStatus.isNotEmpty()) selectStatus.map { filterStatus.indexOf(it) + 1 }
|
// .joinToString(",") else null
|
map["operationStatus"] = if(selectStatus.getOrNull(0) == filterStatus[0]) null else "${filterStatus.indexOf(selectStatus.getOrNull(0))+3}"
|
// map["operationStatus"] = if (selectStatus.isEmpty()) null else filterStatus.indexOf(selectStatus[0]) + 1
|
// map["pointType"] = null // 点位类型1运营点位 2测试点位
|
map["queryParams"] = search.value // 查询参数
|
map["cityCode"] = cityCode
|
if (lat != null && lon != null) {
|
map["longitude"] = lon
|
map["latitude"] = lat
|
} else {
|
map["longitude"] = Constants.longitude
|
map["latitude"] = Constants.latitude
|
}
|
workRepository.querySites(map)?.let {
|
val data = it.toMutableList()
|
if (it.isNotEmpty()) {
|
data.add(sitePlaceHolder)
|
}
|
dataList.postValue(data)
|
}
|
}
|
}
|
|
fun getFenceByCode(){
|
launchRequest(showLoading = false) {
|
workRepository.getFenceByCode(cityCode)?.let {
|
fences.postValue(it)
|
}
|
}
|
}
|
}
|