package com.zj365.health.act

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseListAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.recycleUtils.RecycleItem
import com.zj365.health.R
import com.zj365.health.adapter.XdHistoryAdapter
import com.zj365.health.databinding.ActHistoryXdBinding
import com.zj365.health.vm.XdVm
import com.xty.network.model.XdInfoBean

/**
 *
 * 历史心电
 */
@Route(path = ARouterUrl.XD_HISTORY)
class XdHistoryAct : BaseListAct<XdVm>() {
    val binding by lazy { ActHistoryXdBinding.inflate(layoutInflater) }
    val adapter by lazy { XdHistoryAdapter() }
    var userId=""
    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
        isDarkBar = true
        intent.extras?.let {
            if(it.containsKey("id")){
                userId=it.getString("id").toString()
            }
        }


    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        setRecycleRefresh(binding.mRecycle,binding.mRefresh)
        binding.title.mTvTitle.text = getString(R.string.history_detail)
        binding.title.mIvBack.setOnClickListener {
            finish()
        }

    }


    override fun liveObserver() {
        mViewModel.uploadLive.observe(this) {
            setDate(adapter,it.data)
        }
    }

    override fun loadData() {
        mViewModel.getXdHistory(userId)
    }

    override fun initAdapter() {

        binding.mRecycle.addItemDecoration(RecycleItem(this, 10))
        binding.mRecycle.layoutManager = LinearLayoutManager(this)
        binding.mRecycle.adapter = adapter
        adapter.setOnItemClickListener { adapter, view, position ->
            var bean=adapter.getItem(position) as XdInfoBean
            bundle.clear()
            bundle.putSerializable("bean",bean)
            RouteManager.goAct( ARouterUrl.XD_DETAIL,bundle)
        }
    }
}