package com.dahe.gldriver.adapter

import android.content.Context
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.dahe.gldriver.R
import com.dahe.gldriver.bean.CarBean
import com.dahe.glex.bean.WayBillBean
import com.dahe.mylibrary.utils.ImageLoader

/**
 * @ClassName WaybillAdapter
 * @Author 用户
 * @Date 2024/1/23 16:27
 * @Description TODO
 */
class CarsAdapter :
    BaseQuickAdapter<CarBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: CarBean?) {
        holder.run {
            setText(R.id.tvCarNum, item?.vehicleNum)
            setText(R.id.tvCarType, item?.vehicleType)
            setText(R.id.tvCarLen, """${if (!item?.carLong.isNullOrEmpty()) item?.carLong else ""}mm""")
            setText(
                R.id.tvCarWei,
                """${
                    if (!item?.approvedLoad.isNullOrEmpty()) item?.approvedLoad?.toFloat()
                        ?.div(1000) else 0
                }吨"""
            )

            ImageLoader.getInstance()
                .loadRoundImage(context, item?.carUrl, 6, getView<ImageView>(R.id.ivHead))
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        // 返回一个 ViewHolder
        return QuickViewHolder(R.layout.item_cars, parent)
    }
}