package com.quansu.heifengwuliu.vmodel

import android.os.Bundle
import androidx.lifecycle.MutableLiveData
import com.quansu.heifengwuliu.activity.SourceDetailsActivity
import com.quansu.heifengwuliu.model.DataInfoBean
import com.quansu.heifengwuliu.model.InfoEditBean
import com.quansu.heifengwuliu.utils.net.NetEngine
import com.ysnows.base.base.BRepository
import com.ysnows.base.base.BViewModel
import com.ysnows.base.utils.UiSwitch


open class OwnerSingleVModel : BViewModel<BRepository>() {

    var unit: MutableLiveData<String> = MutableLiveData(unitValues)
    var goodstype: MutableLiveData<String> = MutableLiveData()

    var insurance: MutableLiveData<String> = MutableLiveData()

    var isPush: MutableLiveData<Int> = MutableLiveData(isPushValue)
    var isAgree: MutableLiveData<Int> = MutableLiveData(isPushValue)

    val info: MutableLiveData<DataInfoBean> = MutableLiveData<DataInfoBean>()


    companion object {

        const val isPushValue = 1

        const val unitValues = "吨"
    }


    fun choseUnits() {
        //选择单车运量

//        QMUIBottomSheet.BottomListSheetBuilder(repository().context)
//                .addItem("吨")
//                .addItem("方")
//                .addItem("件")
//                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
//
//                    when(position){
//                        0->unit.value="吨"
//                        1->unit.value="方"
//                        2->unit.value="件"
//                        else ->unit.value=""
//                    }
//                    dialog.dismiss()
//
//                }
//                .build()
//                .show()


    }


    fun getDataInfo(info_id:String){

        repository().lreq(NetEngine.service.infoGet(info_id))
                .doOnNext() {
                    if (it.ok()) {
                        info.value=it.data() as DataInfoBean
                    }
                }
                .subscribe()


    }



    fun setReleaseSource(info_id:String,type_id:String,total:String,driver:String,
                         nums:String,is_public:String,is_insurance:String,
                         type:String,data:String,send:String,receive:String
    ){
        //todo:发布货源

        repository().lreq(NetEngine.service.infoEdit(info_id,type_id,total,driver,nums,is_public,is_insurance,type,
        data,send,receive))
                .doOnNext() {
                    if (it.ok()) {
                        var  bean=it.data() as InfoEditBean
                        UiSwitch.bundle(repository().context, SourceDetailsActivity::class.java, Bundle().apply {
                            putString("info_id", bean.info_id)
                            putString("type","1")
                        })

                    }
                }
                .subscribe()

    }





}
