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.utils.OrderUtils
import com.dahe.glex.bean.OrderBean
import com.dahe.glex.bean.WayBillBean
import com.dahe.mylibrary.utils.ImageLoader

/**
 * @ClassName WaybillAdapter
 * @Author 用户
 * @Date 2024/1/23 16:27
 * @Description TODO
 */
class WaybillAdapter :
    BaseQuickAdapter<OrderBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: OrderBean?) {
        item?.run {
            holder.run {
                setText(
                    R.id.tvStart,
                    """${
                        if (loadingCity.length > 1) loadingCity.substring(0, 2) else loadingCity
                    } ${if (loadingArea.length > 1) loadingArea.substring(0, 2) else loadingArea}"""
                )
                setText(
                    R.id.tvEnd, """${
                        if (receiverCity.length > 1) receiverCity.substring(0, 2) else receiverCity
                    } ${
                        if (receiverArea.length > 1) receiverArea.substring(0, 2) else receiverArea
                    }"""
                )
                setText(R.id.tvMoney, driverFreight)
                setText(R.id.tvCom, realCompanyName)
                setText(R.id.tvDis, """距离:${distance}KM""")
                setText(R.id.tvCredit, """信用 ${shipperCreditRating}""")
                setText(
                    R.id.tvRate,
                    """交易 ${shipperTransactionVolume} 好评率 ${shipperPositiveReviewRate}"""
                )
                setText(R.id.tvProduct, """${vehicleLength}/${vehicleType}/""")
                setText(R.id.tvModel, """${if (orderType == "0") "一装一卸" else "一装多卸"}""")
                setText(R.id.btnOk, OrderUtils.getInstance().getOrderStatu(orderStatus))

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

    }

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