package com.zj365.health.fragment

import android.widget.Toast
import com.xty.base.fragment.BaseVmFrag
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.getImageUrl
import com.xty.common.setImageUser
import com.zj365.health.adapter.KeeperAdapter
import com.zj365.health.databinding.FragMyKeeperBinding
import com.zj365.health.vm.MyKeeperVm


/**
 * 我的管家
 */
class MyKeeperFrag : BaseVmFrag<MyKeeperVm>() {
    val binding by lazy { FragMyKeeperBinding.inflate(layoutInflater) }
    val adapter by lazy { KeeperAdapter() }
    var fromUserId=""
    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
        fromUserId=arguments?.getString(fromUserId).toString()
    }
    override fun initView() {
        super.initView()
        mViewModel.getKeeper()
    }

    override fun setViewModel() = MyKeeperVm()
    override fun observer() {
        mViewModel.keeperLive.observe(this) {
            if ( it.data.size<1){
               Toast.makeText(context, "暂未分配管家，请电话联系对应管家", Toast.LENGTH_SHORT)
                return@observe
            }
            binding.mDocName.text = it.data[0].realname
            if ( it.data[0].gender == 1) {
                binding.mSex.text = "男"
            } else {
                binding.mSex.text = "女"
            }
            binding.mPosition.text = it.data[0].positionName
            binding.phone.text = it.data[0].phone
            if (com.alibaba.android.arouter.utils.TextUtils.isEmpty( it.data[0].intro) ){
                binding.mTvLoc.text= "健康管家"
            }else{
                binding.mTvLoc.text  =  it.data[0].intro
            }
            if (com.alibaba.android.arouter.utils.TextUtils.isEmpty(it.data[0].experience) ){
                binding.detail.text= "--"
            }else{
                binding.detail.text = it.data[0].experience
            }
            binding.mPhoto.apply {
                setImageUser(
                    requireContext(), getImageUrl(it.data[0].avatar)
                )
            }
            binding.llLeft.setOnClickListener { itt ->
          /*      TUIConversationUtils.startAYSingleChatActivity(
                    "man_" + it.data[0].id,
                    it.data[0].realname,
                    it.data[0].avatar
                );*/
            }


            binding.llRight.setOnClickListener {itd ->
                bundle.clear()
                bundle.putSerializable("bean", it.data[0] )
                RouteManager.goAct(ARouterUrl.ONLINE_MAKE, bundle)
            }

        }
    }



}