package com.quansu.heifengwuliu.activity

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.lifecycle.Observer
import com.quansu.heifengwuliu.adapter.OrderInfoInadapter
import com.quansu.heifengwuliu.adapter.OrderInfoadapter
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.databinding.ActivitySourcedetailsBinding
import com.quansu.heifengwuliu.model.DataInfoBean
import com.quansu.heifengwuliu.vmodel.SourceDetailsVModel


/**
 *Created by shihuiyun
 *on 2020/9/15
 */
class SourceDetailsActivity: MBActivity<SourceDetailsVModel, ActivitySourcedetailsBinding>() {


    override fun initCreate(savedInstanceState: Bundle?) {
        super.initCreate(savedInstanceState)

        var info_id=intent?.extras?.getString("info_id", "")
        var type=intent?.extras?.getString("type", "0")//1需要弹出支付的框
        if(!TextUtils.isEmpty(info_id)) {
            vm.getInfo(info_id!!)
        }
        if(type.equals("0")){
            binding.butComeback.visibility= View.GONE
        }

        vm.info.observe(this, Observer {
            //观察
            initViewPager(vm.info.value!!)
            if(type.equals("1")){
                vm.showPayDialog(info_id!!,binding.ll)
            }

        })


    }



   private fun initViewPager(bean:DataInfoBean){
       var  adapterOut= OrderInfoadapter()
       binding.recyclerViewOut.adapter=adapterOut
       var  outList = bean.order.send
       adapterOut!!.addData(outList)
       //入
       var adapterIn= OrderInfoInadapter(bean.order.send[0].time)
       binding.recyclerViewIn.adapter=adapterIn
       var  inList = bean.order.receive
       adapterIn!!.addData(inList)

    }

    override fun binding(): ActivitySourcedetailsBinding {
       return ActivitySourcedetailsBinding.inflate(layoutInflater)
    }


    override fun title(): String? {
        return "货源详情"
    }

    override fun vmClass(): Class<SourceDetailsVModel> {
        return SourceDetailsVModel::class.java
    }




}
