package cn.flightfeather.thirdappmodule.module.inspection
|
|
import android.arch.lifecycle.MutableLiveData
|
import cn.flightfeather.thirdappmodule.CommonApplication
|
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
|
import cn.flightfeather.thirdappmodule.bean.vo.DayTaskProgressVo
|
import cn.flightfeather.thirdappmodule.bean.vo.TaskVo
|
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
|
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
|
import cn.flightfeather.thirdappmodule.repository.InspectionRepository
|
import cn.flightfeather.thirdappmodule.repository.SubTaskRepository
|
import okhttp3.ResponseBody
|
import org.jetbrains.anko.toast
|
|
/**
|
* @author riku
|
* Date: 2019/7/29
|
*/
|
class InspectionViewModel : BaseViewModel() {
|
|
private val inspectionRepository = InspectionRepository()
|
|
private val subTaskRepository = SubTaskRepository()
|
|
var monthTaskList = MutableLiveData<ArrayList<TaskVo>>()
|
|
var dayTaskList = MutableLiveData<ArrayList<DayTaskProgressVo>>()
|
|
var subTaskList = MutableLiveData<ArrayList<Subtask>>()
|
|
var hasUnUploadImage = MutableLiveData<Boolean>()
|
|
/**
|
* 获取月任务
|
* @param yearMonth 年月
|
*/
|
fun getMonthTask(yearMonth: String) {
|
inspectionRepository.getMonthDayTask(yearMonth, userId, userTypeId.toString(),
|
object : ResultCallBack<ArrayList<TaskVo>> {
|
override fun onSuccess(result: ArrayList<TaskVo>?) {
|
result?.let {
|
monthTaskList.value = it
|
}
|
}
|
|
override fun onFailure() {
|
|
}
|
})
|
}
|
|
/**
|
* 获取日任务
|
* @param taskId 总任务id
|
*/
|
fun getDayTask(taskId: String) {
|
inspectionRepository.getDayTask(taskId, userId, userTypeId.toString(),
|
object : ResultCallBack<ArrayList<DayTaskProgressVo>> {
|
override fun onSuccess(result: ArrayList<DayTaskProgressVo>?) {
|
result?.let {
|
dayTaskList.value = it
|
}
|
}
|
|
override fun onFailure() {
|
}
|
|
})
|
}
|
|
/**
|
* 获取子任务
|
* @param dayTaskId 日任务id
|
*/
|
fun getSubTask(dayTaskId: String) {
|
inspectionRepository.getSubTask(dayTaskId, userId, userTypeId.toString(),
|
object : ResultCallBack<ArrayList<Subtask>> {
|
override fun onSuccess(result: ArrayList<Subtask>?) {
|
result?.let {
|
subTaskList.value = it
|
}
|
}
|
|
override fun onFailure() {
|
}
|
|
})
|
}
|
|
/**
|
* 删除子任务
|
*/
|
fun deleteSubTask(subTaskId: String, onSuccess: () -> Unit) {
|
subTaskRepository.deleteSubTask(subTaskId, object : ResultCallBack<ResponseBody> {
|
override fun onSuccess(result: ResponseBody?) {
|
if (result != null) {
|
CommonApplication.getInstance().toast("删除成功")
|
onSuccess()
|
} else {
|
CommonApplication.getInstance().toast("删除失败")
|
}
|
}
|
|
override fun onFailure() {
|
CommonApplication.getInstance().toast("网络错误")
|
}
|
})
|
}
|
|
/**
|
* 查询本地是否有图片未上传
|
*/
|
fun checkUnUploadImage() {
|
inspectionRepository.checkUnUploadImage(object : ResultCallBack<Boolean> {
|
override fun onSuccess(result: Boolean?) {
|
result?.let {
|
hasUnUploadImage.value = it
|
}
|
}
|
|
override fun onFailure() {
|
|
}
|
|
})
|
}
|
}
|