package com.lukouguoji.aerologic.page.log.list

import androidx.lifecycle.MutableLiveData
import com.lukouguoji.aerologic.R
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.bean.LogBean
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.formatDate
import com.lukouguoji.module_base.ktx.launchLoadingCollect
import com.lukouguoji.module_base.ktx.toRequestBody
import dev.utils.common.DateUtils

class LogQueryViewModel : BasePageViewModel() {

    val startDate = MutableLiveData(DateUtils.getCurrentTime().formatDate())
    val endDate = MutableLiveData("")

    val keyWord = MutableLiveData("")
    val operatorId = MutableLiveData("")

    val count = MutableLiveData(0)

    val itemLayoutId = R.layout.item_log_query
    val itemViewHolder = LogQueryViewHolder::class.java

    fun searchClick() {
        refresh()
    }

    override fun getData() {
        launchLoadingCollect({
            NetApply.api.getLogList(
                mapOf(
                    "pageNum" to pageModel.page,
                    "pageSize" to pageModel.limit,
                    "startTime" to startDate.value,
                    "endTime" to endDate.value,
                    "key" to keyWord.value,
                    "opId" to operatorId.value,
                ).toRequestBody()
            )
        }) {
            onSuccess = {
                pageModel.handleListBean(it)
                count.value = it.total
            }
        }
    }
}
