| | |
| | | |
| | | import android.arch.lifecycle.MutableLiveData |
| | | import cn.flightfeather.thirdappmodule.bean.entity.* |
| | | import cn.flightfeather.thirdappmodule.bean.vo.BaseSubScene |
| | | import cn.flightfeather.thirdappmodule.bean.vo.SceneConstructionSite |
| | | import cn.flightfeather.thirdappmodule.bean.vo.SceneDetailStrVo |
| | | import cn.flightfeather.thirdappmodule.bean.vo.SceneDetailVo |
| | | import cn.flightfeather.thirdappmodule.common.net.ResultCallBack |
| | | import cn.flightfeather.thirdappmodule.model.event.SceneEvent |
| | | import cn.flightfeather.thirdappmodule.module.base.BaseViewModel |
| | | import cn.flightfeather.thirdappmodule.repository.CommonRepository |
| | | import cn.flightfeather.thirdappmodule.repository.SceneRepository |
| | | import com.google.gson.Gson |
| | | import okhttp3.ResponseBody |
| | | import org.greenrobot.eventbus.EventBus |
| | | import org.jetbrains.anko.toast |
| | |
| | | */ |
| | | class SceneDetailViewModel : BaseViewModel() { |
| | | private val sceneRepository = SceneRepository() |
| | | private val commonRepository = CommonRepository.instance |
| | | |
| | | val allProvinceList = ArrayList<Province>() |
| | | val allCityList = ArrayList<City>() |
| | |
| | | |
| | | val allSceneTypeList = MutableLiveData<ArrayList<Domainitem>>().apply { value = ArrayList() } |
| | | |
| | | val subScene = MutableLiveData<> |
| | | val subScene = MutableLiveData<BaseSubScene>() |
| | | val sceneStatus = ArrayList<String>() |
| | | |
| | | /** |
| | | * 获取行政区划可选项 |
| | | */ |
| | | fun getData() { |
| | | sceneRepository.getDivision(object : ResultCallBack<Division> { |
| | | override fun onSuccess(result: Division?) { |
| | |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * 获取场景类型可选项 |
| | | */ |
| | | fun getSceneType() { |
| | | sceneRepository.getSceneType(object : ResultCallBack<ArrayList<Domainitem>> { |
| | | override fun onSuccess(result: ArrayList<Domainitem>?) { |
| | |
| | | }) |
| | | } |
| | | } |
| | | |
| | | fun getSceneDetail(scene: Scense?) { |
| | | scene?.let { |
| | | sceneRepository.getSceneDetail(it, object : ResultCallBack<SceneDetailVo<SceneConstructionSite>> { |
| | | override fun onSuccess(result: SceneDetailVo<SceneConstructionSite>?) { |
| | | result?.let { r -> |
| | | subScene.value = r.subScene |
| | | } |
| | | } |
| | | |
| | | override fun onFailure() { |
| | | application.toast("施工阶段没有记录") |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | fun updateSceneDetail(scene: Scense?, success: () -> Unit) { |
| | | scene?.let { |
| | | val vo = SceneDetailStrVo().apply { |
| | | this.scene = it |
| | | this.subScene = Gson().toJson(this@SceneDetailViewModel.subScene.value) |
| | | } |
| | | sceneRepository.updateSceneDetail(vo, object : ResultCallBack<String> { |
| | | override fun onSuccess(result: String?) { |
| | | application.toast("施工阶段修改成功") |
| | | success() |
| | | } |
| | | |
| | | override fun onFailure() { |
| | | application.toast("施工阶段修改失败") |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | fun getSceneStatus(success: () -> Unit) { |
| | | commonRepository.getDomainItem("工地工期", object : ResultCallBack<ArrayList<Domainitem>> { |
| | | override fun onSuccess(result: ArrayList<Domainitem>?) { |
| | | result?.let { arr -> |
| | | sceneStatus.addAll(arr.map { it.text }) |
| | | success() |
| | | } |
| | | } |
| | | |
| | | override fun onFailure() { |
| | | application.toast("施工阶段选项无记录") |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | data class Division( |