package com.zj365.health.act

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.base.vm.BaseVm
import com.xty.common.arouter.ARouterUrl
import com.zj365.health.adapter.GoodsLogisticsAdapter
import com.zj365.health.databinding.ActGoodsLogisticsBinding
import com.zj365.health.vm.GoodsLogisticsVm

@Route(path = ARouterUrl.LOGISTICS_ACT)
class GoodsLogisticsAct : BaseVmAct<GoodsLogisticsVm>() {
    val binding by lazy { ActGoodsLogisticsBinding.inflate(layoutInflater) }

    val adapter by lazy { GoodsLogisticsAdapter() }

    var orderId:Long = 0

    override fun liveObserver() {

        mViewModel.goodsLogisticsLiveData.observe(this){
            binding.tvTrackingNumber.text = "${it.data.express_name}  ${it.data.express_sn}"
            binding.tvShippingAddress.text = it.data.address
            adapter.setNewInstance(it.data.data)
        }
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "物流信息"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }

        orderId = intent.getLongExtra("orderId",0)
        mViewModel.getShippingTracking(orderId)

        binding.recycler.layoutManager = LinearLayoutManager(this)
        binding.recycler.addItemDecoration(object : RecyclerView.ItemDecoration(){
            override fun getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
                super.getItemOffsets(outRect, itemPosition, parent)
            }
        })

        binding.recycler.adapter = adapter


    }


    override fun setLayout() = binding.root
}