package com.quansu.heifengwuliu.vmodel

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.quansu.heifengwuliu.activity.AddressAddActivity
import com.quansu.heifengwuliu.config.MIntentAction
import com.quansu.heifengwuliu.fragment.AddressFragment
import com.quansu.heifengwuliu.model.AddressBean
import com.ysnows.base.base.BRRepository
import com.ysnows.base.base.BRViewModel
import com.ysnows.base.utils.B
import com.ysnows.base.utils.UiSwitch

class AddressVModel: BRViewModel<BRRepository>() {


    var type:String?=null
    var context:AddressFragment?=null


    fun inData(type:String,context:AddressFragment){
        this.type=type
        this.context=context
    }

    fun onChose(item: AddressBean){

        val intent = Intent()
        var con = repository().context as Activity
        var bundle= Bundle()
        bundle.putSerializable("item",item)
        intent.putExtras(bundle)
        con.setResult(Activity.RESULT_OK, intent)
        con.finish()


    }

    fun  toDetails(addr_id:String){

        UiSwitch.bundleRes(context, AddressAddActivity::class.java,
                B.with().putString("type",type)
                        .putString("addr_id",addr_id)
                        .ok(), MIntentAction.REQUEST_CODE_ONE)
    }


}
