package com.zj365.health.act

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.fragment.BaseFragList
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.recycleUtils.RecycleItem
import com.xty.common.util.CommonUtils
import com.zj365.health.adapter.ProgrammeAdapter
import com.zj365.health.databinding.ActProgremmHistoryBinding
import com.zj365.health.vm.ProgrammeHistoryVm
import com.xty.network.model.ProgrammeBean

/**
 * 历史方案
 */
@Route(path = ARouterUrl.PROGRAMME_HISTORY)
class ProgrammeHistoryFrag : BaseFragList<ProgrammeHistoryVm>() {

    val binding by lazy { ActProgremmHistoryBinding.inflate(layoutInflater) }
    val mAdapter by lazy { ProgrammeAdapter() }

    override fun setLayout() = binding.root

    override fun initData() {
        super.initData()
    }

    override fun initView() {
        super.initView()
        setRecycleRefresh(binding.mRecycle, binding.mRefresh)

    }

    override fun initAdapter() {
        setRecycleRefresh(binding.mRecycle, binding.mRefresh)
        binding.mRecycle.adapter = mAdapter
        binding.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.mRecycle.addItemDecoration(RecycleItem(requireContext(), 20))
        mAdapter.setOnItemClickListener { adapter, view, position ->
            var bean = adapter.getItem(position) as ProgrammeBean
            bundle.clear()
            bundle.putSerializable("bean", bean)
            RouteManager.goAct(ARouterUrl.PROGRAMME_DETAIL_NEW, bundle)

        }
    }

    override fun refresh() {
        CommonUtils.getMyUserInfo()?.let {
            mViewModel.getNesProg(it.id.toString())
        }
    }

    override fun setViewModel(): ProgrammeHistoryVm = ProgrammeHistoryVm()

    override fun observer() {
        mViewModel.progLive.observe(this) {
            setDate(mAdapter, it.data)
        }
    }
}