package com.cheng.bole.ui.fragment.mine.order.list

import android.graphics.Color
import android.text.TextUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.bole.R
import com.cheng.bole.bean.OrderEntity
import com.cheng.bole.widget.CommonShapeView
import java.text.DecimalFormat

class OrderAdapter : BaseQuickAdapter<OrderEntity, BaseViewHolder>(R.layout.listitem_order) {

    init {
        addChildClickViewIds(R.id.btn_invoice, R.id.btn_certificate)
    }

    override fun convert(holder: BaseViewHolder, item: OrderEntity) {
        holder.setText(R.id.tv_name, item.goods_name)
        holder.setText(R.id.tv_order_no, item.out_trade_no)
        holder.setText(
            R.id.tv_pay_type,
            when (item.pay_type) {
                "weixin" -> "微信支付"
                "alipay" -> "支付宝支付"
                "apple" -> "苹果支付"
                "bank" -> "对公转账"
                else -> "未知"
            }
        )
        holder.setText(R.id.tv_amount, "￥${DecimalFormat("0.00").format(item.total_fee.toFloat())}")
        holder.setText(R.id.tv_create_time, item.create_time)
        holder.setText(R.id.tv_pay_time, item.pay_time)

        holder.setGone(R.id.tv_pay_time_title, TextUtils.isEmpty(item.pay_time))
        holder.setGone(R.id.tv_pay_time, TextUtils.isEmpty(item.pay_time))

        val status = holder.getView<CommonShapeView>(R.id.tv_status)
        holder.setGone(R.id.btn_invoice, true)
        holder.setGone(R.id.btn_certificate, true)
        when (item.status) {
            "1" -> {
                status.text = "待支付"
                status.setTextColor(Color.parseColor("#FF4C4C"))
                status.setBgColor(Color.parseColor("#FFEDED"))
                if (item.pay_type == "bank") {
                    holder.setVisible(R.id.btn_certificate, true)
                }
            }

            "2" -> {
                status.text = "已支付"
                status.setTextColor(Color.parseColor("#2090FE"))
                status.setBgColor(Color.parseColor("#E8F3FE"))
                if (item.invoice_status == "1") {
                    holder.setVisible(R.id.btn_invoice, true)
                }
            }

            "3" -> {
                status.text = "已退款"
                status.setTextColor(Color.parseColor("#CCCCCC"))
                status.setBgColor(Color.parseColor("#EEEEEE"))
            }

            "4" -> {
                status.text = "已取消"
                status.setTextColor(Color.parseColor("#CCCCCC"))
                status.setBgColor(Color.parseColor("#EEEEEE"))
            }

            "5" -> {
                status.text = "待审核"
                status.setTextColor(Color.parseColor("#FF9B2F"))
                status.setBgColor(Color.parseColor("#1AFF9B2F"))
            }
        }
    }
}