package com.zj365.mime.act

import android.text.Html
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.arouter.ARouterUrl
import com.zj365.mime.databinding.ActNewProgrammeDetailBinding
import com.zj365.mime.vm.ProgrammeVm
import com.xty.network.model.ProgrammeBean
import com.xty.network.model.ProgrammeDataBean

/**
 * 方案内容
 */
@Route(path = ARouterUrl.PROGRAMME_DETAIL_NEW)
class ProgeammeDetailAct : BaseVmAct<ProgrammeVm>() {
    val binding by lazy { ActNewProgrammeDetailBinding.inflate(layoutInflater) }

    val id: String? by lazy {
        intent.getStringExtra("id")
    }
    var msg: ProgrammeBean? = null
    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
        if (id == null || id!!.isEmpty()) {
            msg = intent.extras!!.getSerializable("bean") as? ProgrammeBean
            refreshView()
        }
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener { finish() }
        id?.let {
            mViewModel.findById(it)
        }
    }

    override fun liveObserver() {
        mViewModel.findById.observe(this) {
            msg = it.data
            refreshView()
        }
    }

    private fun refreshView() {
        msg?.let {
            binding.tvProgrammeName.text = it.name
            binding.tvAgency.text = it.orgName
            binding.tvTime.text = it.createTime
            binding.mMsg.text = Html.fromHtml(it.prName)
            binding.title.mTvTitle.text = it.name
        }
    }
}