package com.lukouguoji.gjc.viewModel

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.module_base.base.BaseViewModel
import com.lukouguoji.module_base.bean.GjcUldUseBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.launchLoadingCollect
import com.lukouguoji.module_base.ktx.showToast

/**
 * 国际出港板箱过磅详情 ViewModel
 */
class GjcBoxWeighingDetailsViewModel : BaseViewModel() {

    // 主键ID（从Intent接收）
    var useId: Long = 0

    // 详情数据
    val dataBean = MutableLiveData(GjcUldUseBean())

    /**
     * 初始化数据
     */
    fun initOnCreated(intent: Intent) {
        useId = intent.getLongExtra(Constant.Key.ID, 0)
        if (useId > 0) {
            getData()
        } else {
            showToast("参数错误")
            getTopActivity().finish()
        }
    }

    /**
     * 获取详情数据
     */
    private fun getData() {
        launchLoadingCollect({
            NetApply.api.getGjcBoxWeighingDetails(useId)
        }) {
            onSuccess = {
                dataBean.value = it.data ?: GjcUldUseBean()
            }
        }
    }
}
