puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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)
            }
        }
    }
}