package com.lukouguoji.gjj.viewModel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import com.alibaba.fastjson.JSONObject
import com.lukouguoji.module_base.http.user.UserNetwork
import kotlinx.coroutines.Dispatchers

class GjjWareHouseInfoViewModel : ViewModel() {

    private val logName = "GjjWareHouseInfoViewModel"

    var wayBillInfo = JSONObject()

    /**
     * 查询详情
     */
    private val queryInfoByIdWareHouseLiveData = MutableLiveData<Int>()
    val queryInfoByIdWareHouseObserver = Transformations.switchMap(queryInfoByIdWareHouseLiveData) { param ->
        liveData(Dispatchers.IO) {
            try {
                var response = JSONObject()
                if (param != -9999) {
                    response = UserNetwork.queryInfoByIdGjjCangKu(param)
                }
                emit(response)
            } catch (e: Exception) {
                Log.e(logName, e.stackTraceToString())
            }

        }
    }

    fun queryInfoByIdWareHouse(wbId: Int) {
        queryInfoByIdWareHouseLiveData.value = wbId
    }


}