package com.yidian.shenghuoquan.buserorder.app.adapter

import android.graphics.Typeface
import android.widget.RelativeLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.app.bean.OrderWebData

class OrderListAdapter : BaseQuickAdapter<OrderWebData, BaseViewHolder>(R.layout.border_recycle_order_item){
  override fun convert(holder: BaseViewHolder, item: OrderWebData) {
    mapDataToHoder(item, holder)
  }

  private fun mapDataToHoder(data: OrderWebData, holder: BaseViewHolder) {
    holder.itemView.findViewById<TextView>(R.id.tv_market_name).text = data.marketing_name
    holder.itemView.findViewById<TextView>(R.id.tv_pay_status).text = data.online_status
    when(data.order_item_list.size) {
      1 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
      }
      2 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_goog2_name).text = data.order_item_list[1].goods_name
      }
      3 -> {
        holder.itemView.findViewById<TextView>(R.id.tv_goog1_name).text = data.order_item_list[0].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_goog2_name).text = data.order_item_list[1].goods_name
        holder.itemView.findViewById<TextView>(R.id.tv_good3_name).text = data.order_item_list[2].goods_name
      }
    }
    holder.itemView.findViewById<TextView>(R.id.tv_order_goods_count).text = data.goods_num.toString()
    holder.itemView.findViewById<TextView>(R.id.tv_pay_time).text = data.pay_time
    var money:TextView = holder.itemView.findViewById<TextView>(R.id.tv_pay_money_count)
    money.setTypeface(Typeface.DEFAULT_BOLD)
    money.text = "${data.payment}"
    holder.itemView.findViewById<RelativeLayout>(R.id.rl_show_order_detail).setOnClickListener {
      //跳转订单详情页面
    }
    if (data.online_status.equals("4")) {
      holder.itemView.findViewById<TextView>(R.id.tv_pay_money_status).text = "已退款:"
    } else {
      holder.itemView.findViewById<TextView>(R.id.tv_pay_money_status).text = "已支付:"
    }
  }
}
