package com.zj365.health.act.tonguediagnosis

import android.view.View
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.adapter.TongueRecordAdapter
import com.zj365.health.databinding.ActivityTongueOrderListBinding
import com.zj365.health.vm.TongueDiagnosisVm
import com.xty.network.model.CancerGoodsBean

@Route(path = ARouterUrl.TONGUE_ORDER_LIST_ACTIVITY)
class TongueOrderListActivity  : BaseListAct<TongueDiagnosisVm>() {

    val mAdapter by lazy { TongueRecordAdapter() }
    val binding by lazy { ActivityTongueOrderListBinding.inflate(layoutInflater) }
    override fun setLayout() = binding.root

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "舌诊记录"
        binding.title.mIvBack.setOnClickListener { finish() }
        loadData()
    }

    override fun initAdapter() {
        setRecycleRefresh(binding.mRecycle,binding.mRefresh,true)
        binding.mRecycle.layoutManager= LinearLayoutManager(this)
        binding.mRecycle.adapter=mAdapter
        mAdapter.setOnItemClickListener { adapter, view, position ->
            val bean = adapter.data.get(position) as CancerGoodsBean
            bundle.clear()
            bundle.putString("orderNo",bean.orderNo)
            when (bean.status) {
                1 -> {
                    RouteManager.goAct(ARouterUrl.TONGUE_EDIT_INFO_ACTIVITY, bundle)
                }
                else -> {
                    bundle.putSerializable("orderBean",bean)
                    RouteManager.goAct(ARouterUrl.TONGUE_DETAIL_ACTIVITY, bundle)
                }
            }

        }
    }

    override fun loadData() {
        //获取数据
        mViewModel.tongueOrderList(1)
    }

    override fun onResume() {
        super.onResume()
        loadData()
    }

    override fun liveObserver() {
        mViewModel.cancerGoodsBeanObservable.observe(this) {
            it.data?.let {
                if (it.isEmpty() && page == 1){
                    binding.viewNone.rlRoot.visibility = View.VISIBLE
                } else {
                    binding.viewNone.rlRoot.visibility = View.GONE
                }

                setDate(mAdapter,it)
            }
        }
    }



}