package com.cheng.blzb.ui.fragment.mine.history

import android.text.TextUtils
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.BidDetailEntity
import com.cheng.blzb.utils.BidTypeUtils
import com.cheng.blzb.widget.CommonShapeView
import com.example.base.ui.list.LoadMoreAdapter
import java.text.DecimalFormat

class HistoryAdapter: LoadMoreAdapter<BidDetailEntity>(R.layout.listitem_bid) {

    override fun convert(holder: BaseViewHolder, item: BidDetailEntity) {
        val tvTag = holder.getView<CommonShapeView>(R.id.tv_tag)
        tvTag.setBgColor(BidTypeUtils.getTypeColor(item.type_name))
        tvTag.text = BidTypeUtils.getShortName(item.type_name)

        holder.setText(R.id.tv_title, item.origin_content.toString())
        holder.setText(R.id.tv_location, if (TextUtils.isEmpty(item.city_name)) "全国" else item.city_name)
        holder.setText(R.id.tv_amount, item.project_amount)
        holder.setText(R.id.tv_time, item.tips_time)
        holder.setText(R.id.tv_rate, DecimalFormat("0.0").format(item.star.toFloat()))

        holder.setGone(R.id.tv_amount, TextUtils.isEmpty(item.project_amount))
        holder.setGone(R.id.tv_time, true)
    }
}