package cn.muchinfo.rma.view.base.chart

import android.content.Intent
import androidx.lifecycle.MutableLiveData
import cn.muchinfo.rma.global.GlobalDataCollection
import cn.muchinfo.rma.global.data.account.loginQeruy.GoodsInfo
import cn.muchinfo.rma.view.MyApplication
import cn.muchinfo.rma.view.base.BaseViewModel

class ChartViewModel : BaseViewModel(){

    var outGoodsCode = ""
    var goodsCode = ""
    var goodsInfo : MutableLiveData<GoodsInfo> = MutableLiveData<GoodsInfo>()  // 当前选中的商品信息

    fun initData(intent: Intent){
        outGoodsCode = intent.getStringExtra("outGoodsCode").toString()
        goodsCode = intent.getStringExtra("goodsCode").toString()
        goodsInfo.postValue(GlobalDataCollection.instance?.goodsInfoList?.find { it.goodscode.equals(goodsCode) })
    }

    fun initRequest(){
        queryTsData(goodsCode);
    }


    fun queryTsData(goodsCode: String) {
        val params = mutableMapOf<String, String>().apply {
            put("goodsCode", goodsCode)
        }
        MyApplication.getInstance()?.chartManager?.queryTsData(params = params) { isSuccess, respData, _ ->
            if (isSuccess) {

            }
        }
    }
}