package com.dahe.gldriver.adapter

import android.content.Context
import android.view.ViewGroup
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.utils.OrderUtils
import com.dahe.glex.bean.OrderBean
import com.dahe.mylibrary.utils.ImageLoader

/**
 * @ClassName WaybillAdapter
 * @Author 用户
 * @Date 2024/1/23 16:27
 * @Description TODO
 */
class WaybillListAdapter :
    BaseQuickAdapter<OrderBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: OrderBean?) {
        item?.let {
            holder.run {
                setText(R.id.tvWaybillId,it.orderNum)
                setText(R.id.tvStatu,OrderUtils.getInstance().getOrderStatu(it.orderStatus))
                setText(R.id.tvType,"""${if (it.orderType == "0") "一装一卸" else "一装多卸"}""")
                setText(R.id.tvTime,"""${it.loadingDeadline}装货""")
                setText(R.id.tvDis,"""${it.distance}km""")
                setText(R.id.tvCarNum,it.vehicleNum)
                setText(R.id.tvGood,"""${it.goodItemGrossWeight}吨/${it.goodName}""")
                setText(R.id.tvMoney,it.driverFreight)
                setText(R.id.tvComName,it.realCompanyName)
                setText(R.id.btnOk,OrderUtils.getInstance().getNextByStatu(it.orderStatus))


                ImageLoader.getInstance()
                    .loadRoundImage(context, it.avatar, 6, getView<ImageView>(R.id.ivHead))

                setText(
                    R.id.tvStart,
                    """${
                        if (it.loadingCity.length > 1) it.loadingCity.substring(0, 2) else it.loadingCity
                    } ${if (it.loadingArea.length > 1) it.loadingArea.substring(0, 2) else it.loadingArea}"""
                )
                setText(
                    R.id.tvEnd, """${
                        if (it.receiverCity.length > 1) it.receiverCity.substring(0, 2) else it.receiverCity
                    } ${
                        if (it.receiverArea.length > 1) it.receiverArea.substring(0, 2) else it.receiverArea
                    }"""
                )
            }
        }

    }

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

}