package com.lukouguoji.aerologic.page.gnj.unload.detail

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.RecyclerView
import com.lukouguoji.aerologic.R
import com.lukouguoji.module_base.base.BasePageViewModel
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.GnjUnloadListBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.launchCollect
import com.lukouguoji.module_base.ktx.launchLoadingCollect
import com.lukouguoji.module_base.ktx.toRequestBody
import kotlin.properties.Delegates

class GnjUnloadDetailsViewModel : BasePageViewModel() {

    // 详情信息
    val dataBean = MutableLiveData<GnjUnloadListBean>()

//    单证交警--类型
    val handover = MutableLiveData("")

    val itemViewHolder = GnjUnloadDetailsViewHolder::class.java
    val itemLayoutId = R.layout.item_gnj_unload_car;

//    val carList = MutableList(List<GnjUnloadListBean>)

    ///////////////////////////////////////////////////////////////////////////
    // 方法区
    ///////////////////////////////////////////////////////////////////////////

    fun initOnCreated(intent: Intent) {
        val dataBeanString = intent.getStringExtra(Constant.Key.DATA) ?: ""
        dataBean.value = NetApply.gson.fromJson(dataBeanString, GnjUnloadListBean::class.java)
        refresh()
    }

    override fun getData() {
        launchLoadingCollect({
            NetApply.api.getGnjUnloadCarList(
                mapOf(
                    "fid" to dataBean.value?.fid,
                    "fdate" to dataBean.value?.fdate
                ).toRequestBody())
        }) {
            onSuccess = {
                launchCollect({NetApply.api.getHandover(dataBean.value!!.fid)}) {
                    onSuccess = { itt ->
                        if (itt.data == null) handover.value = "" else handover.value = "业务袋"
                    }
                }
                pageModel.handleListBean(it)
            }
        }
    }

}