package xn.hxp.ui.adapter

import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import xn.hxp.R
import com.blankj.utilcode.util.LogUtils
import com.rc.httpcore.bean.UseLedgerListBean
import xn.hxp.weidith.TextTool


//使用台账-列表
class UseLedgerAdapter :
    BaseQuickAdapter<UseLedgerListBean, BaseViewHolder>(R.layout.item_use_ledger) {

    override fun convert(holder: BaseViewHolder, item: UseLedgerListBean) {
        holder.setText(R.id.chemicalName, item.chemicalName)
        val chemicalNameView = holder.getView<TextView>(R.id.chemicalName)
        chemicalNameView.setOnClickListener { TextTool.showPop(context, chemicalNameView) }
        holder.setText(R.id.tagCode, item.tagCode)
        val tagCodeView = holder.getView<TextView>(R.id.tagCode)
        tagCodeView.setOnClickListener { TextTool.showPop(context, tagCodeView) }
        // 截取后5位
        if (item.collectTime != null) {
            LogUtils.i("==带归还清单 ${item.collectTime}")
            val splitDateTime = item.collectTime.split(" ")
            val date = splitDateTime[0]
            val time = splitDateTime[1]
            holder.setText(R.id.collectTime, "$date")
            holder.setText(R.id.times, "$time")
        } else {
            holder.setText(R.id.collectTime, "")
            holder.setText(R.id.times, "")
        }
        holder.setText(R.id.createByName, item.createByName)
        if (item.outOneUserName != null && item.outTwoUserName != null) {
            holder.setText(R.id.outOneUserName, "${item.outOneUserName}-${item.outTwoUserName}")
        }
        if (item.collectStockNum != null) {
            holder.setText(R.id.surplus, "${item.collectStockNum}${item.specUnit}")
        }

        if (item.useStatus == 0) {
            holder.getView<LinearLayout>(R.id.lintc).visibility = View.VISIBLE
            holder.getView<TextView>(R.id.wholeBottle).visibility = View.GONE
            if (item.returnTime != null) {
                LogUtils.i("==带归还清单 ${item.returnTime}")
                val splitDateTime = item.returnTime!!.split(" ")
                val date = splitDateTime[0]
                val time = splitDateTime[1]
                holder.setText(R.id.returnTime, "$date")
                holder.setText(R.id.returnTimeTwo, "$time")
            }
        } else {
            if (item.statusStr != null) {
                holder.getView<LinearLayout>(R.id.lintc).visibility = View.GONE
                holder.getView<TextView>(R.id.wholeBottle).visibility = View.VISIBLE
                holder.setText(R.id.wholeBottle, "${item.statusStr}")
            }
        }

        if (item.backUser != null) {
            holder.setText(R.id.backUser, "${item.backUser}")
        }
        if (item.backOneUserName != null && item.backTwoUserName != null) {
            holder.setText(R.id.backUserName, "${item.backOneUserName}-${item.backTwoUserName}")
        }
//        if (item.remark != null) {
//            holder.setText(R.id.useStatus, "${item.remark}${item.specUnit}")
//        }

        if (item.useAmount != null) {
            holder.setText(R.id.useStatus, "${item.useAmount}${item.specUnit}")
        }

    }
}