package cn.flightfeather.thirdapp.module.inspection
|
|
import android.arch.lifecycle.MutableLiveData
|
import cn.flightfeather.thirdapp.bean.*
|
import cn.flightfeather.thirdapp.common.net.ResultCallBack
|
import cn.flightfeather.thirdapp.model.event.ProblemEvent
|
import cn.flightfeather.thirdapp.module.base.BaseViewModel
|
import cn.flightfeather.thirdapp.repository.ProblemRepository
|
import okhttp3.ResponseBody
|
import org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.toast
|
|
/**
|
* @author riku
|
* Date: 2019/8/1
|
*/
|
class MenuEvidenceViewModel : BaseViewModel() {
|
|
private val problemRepository = ProblemRepository()
|
|
//所有问题可能出现的位置
|
val locationList = MutableLiveData<ArrayList<Domainitem>>()
|
|
//所有问题的分类集合
|
val problemFatherType = MutableLiveData<ArrayList<String>>()
|
|
//当前所选问题分类下的详细问题集合
|
val problemType = MutableLiveData<ArrayList<Problemtype>>()
|
|
val suggestionList = MutableLiveData<ArrayList<String>>()
|
|
val problemMap = HashMap<String, ArrayList<Problemtype>>()
|
|
/**
|
* 获取场景问题可选位置(目前只有工地,但所有场景都使用)
|
*/
|
fun getLocationList() {
|
problemRepository.getLocationList(object : ResultCallBack<ArrayList<Domainitem>> {
|
override fun onSuccess(result: ArrayList<Domainitem>?) {
|
result?.let {
|
locationList.value = it
|
}
|
}
|
|
override fun onFailure() {
|
|
}
|
|
})
|
}
|
|
/**
|
* 获取对应场景下所有问题类型
|
*/
|
fun getProblemType(taskTypeId: Byte, cityCode: String, districtCode: String, sceneTypeId: Byte) {
|
problemRepository.getProblemType(taskTypeId, cityCode, districtCode, sceneTypeId, object : ResultCallBack<ArrayList<Problemtype>> {
|
override fun onSuccess(result: ArrayList<Problemtype>?) {
|
result?.let {
|
if (it.isEmpty()) {
|
it.add(Problemtype().apply {
|
guid = "0"
|
typename = "无"
|
name = "无"
|
})
|
}
|
|
val typeList = ArrayList<String>()
|
|
it.forEach {p ->
|
if (problemMap.containsKey(p.typename)) {
|
problemMap[p.typename]?.add(p)
|
} else {
|
typeList.add(p.typename)
|
problemMap[p.typename] = ArrayList<Problemtype>().apply { add(p) }
|
}
|
}
|
|
problemFatherType.value = typeList
|
}
|
}
|
|
override fun onFailure() {
|
}
|
|
})
|
}
|
|
/**
|
* 获取问题对应的整改建议
|
*/
|
fun getSuggestionList(ptGuid: String) {
|
problemRepository.getSuggestion(ptGuid, object : ResultCallBack<ArrayList<ChangeAdvice>> {
|
override fun onSuccess(result: ArrayList<ChangeAdvice>?) {
|
result?.let {
|
val advices = ArrayList<String>()
|
it.forEach {c ->
|
advices.add(c.adName)
|
}
|
advices.add("暂无建议")
|
suggestionList.value = advices
|
}
|
}
|
|
override fun onFailure() {
|
}
|
|
})
|
}
|
|
/**
|
* 新增一个问题
|
*/
|
fun putProblem(problem: Problemlist) {
|
problemRepository.putOneProblemList(problem, object : ResultCallBack<ResponseBody> {
|
override fun onSuccess(result: ResponseBody?) {
|
result?.let {
|
application.toast("提交成功")
|
|
EventBus.getDefault().post(ProblemEvent(problem))
|
}
|
}
|
|
override fun onFailure() {
|
application.toast("提交失败")
|
}
|
|
})
|
}
|
|
/**
|
* 新增本地多媒体文件记录
|
*/
|
fun putMediaFile(mediaFile: Mediafile) {
|
problemRepository.putMediaFileLocal(mediaFile, object : ResultCallBack<Int> {
|
override fun onSuccess(result: Int?) {
|
|
}
|
|
override fun onFailure() {
|
|
}
|
|
})
|
}
|
|
/**
|
* 下拉框选择一个问题类型时,需展示对应类别的具体问题
|
*/
|
fun refreshProblems(problemFatherType: String?) {
|
problemMap[problemFatherType]?.let {
|
problemType.value = it
|
}
|
}
|
}
|