package com.zj365.health.act

import android.content.Intent
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.zj365.health.R
import com.zj365.health.adapter.CollectBloodAdapter
import com.zj365.health.databinding.ActCollectBloodListBinding
import com.zj365.health.vm.PayCancerVm


/**
 * 已填问卷列表
 */
@Route(path = ARouterUrl.COLLECT_BLOOD_list)
class CollectBloodListAct : BaseListAct<PayCancerVm>() {
    val mAdapter by lazy { CollectBloodAdapter() }
    val binding by lazy { ActCollectBloodListBinding.inflate(layoutInflater) }


    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "预约采血记录"
        binding.title.mIvBack.setOnClickListener { finish() }
        binding.tvPurchase.setOnClickListener {
            //采血列表
            bundle.clear()
            bundle.putBoolean("isList",true)
            RouteManager.goActRequest(ARouterUrl.COLLECT_BLOOD, this,100,bundle)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100){
            loadData()
        }
    }
    override fun initAdapter() {
        setRecycleRefresh(binding.mRecycle,binding.mRefresh)
        binding.mRecycle.layoutManager= LinearLayoutManager(this)
        binding.mRecycle.adapter=mAdapter
        mAdapter.addChildClickViewIds(R.id.llUploadSuccess,R.id.llUpload)
    }

    override fun loadData() {
        mViewModel.getBlood(page)
    }

    override fun liveObserver() {
        mViewModel.getBloodObservable.observe(this) {
            it.data?.records.let {
                mAdapter.setNewInstance(it)
            }
        }
    }

}