package com.yidian.shenghuoquan.bmanagercenter.personnel.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.shenghuoquan.bmanagercenter.R
import com.yidian.shenghuoquan.bmanagercenter.personnel.bean.AccountUser
import com.yidian.xpage.XPageManager

/**
 * 我的员工列表的适配器
 */
class MyStaffListAdapter : BaseQuickAdapter<AccountUser, BaseViewHolder>(R.layout.item_staff_list) {

  override fun convert(holder: BaseViewHolder, item: AccountUser) {
    holder.getView<TextView>(R.id.tv_name).text = item.nickName
    holder.getView<TextView>(R.id.tv_mobile).text = item.mobile
    if (!item.roleList.isNullOrEmpty()) {
      val sb = StringBuilder()
      item.roleList.forEachIndexed { index, s ->
        sb.append(s)
        if (index < item.roleList.size - 1) {
          sb.append("｜")
        }
      }
      holder.getView<TextView>(R.id.tv_role_list).text = sb
    }

    // 点击管理，进入员工管理
    holder.getView<TextView>(R.id.tv_manage).setOnClickListener {
      val hashMap = HashMap<String, Any?>()
      hashMap["staffInfo"] = item
      XPageManager.push(XRouterPathConstants.PERSONAL_STAFF_MANAGE, hashMap)
    }
  }
}
