package com.zj365.health.adapter

import android.graphics.Color
import android.graphics.Typeface
import android.text.SpannableString
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ruffian.library.widget.RImageView
import com.xty.base.adapter.BaseAdapter
import com.xty.common.setImage
import com.xty.common.util.SpannableUtils
import com.xty.network.model.ShopOrderListBean
import com.zj365.health.R

class GoodsOrderAdapter : BaseAdapter<ShopOrderListBean.ShopOrderBean>(R.layout.item_shop_order_list) {
    override fun convert(holder: BaseViewHolder, item: ShopOrderListBean.ShopOrderBean) {
        holder.setText(R.id.tv_order_no,"订单 ${item.order_no}")
        holder.setText(R.id.tv_goods_name,item.goods_name)
        holder.setText(R.id.tv_spec,item.goods_sku)
        holder.getView<RImageView>(R.id.img_goods).setImage(context,item.goods_pic)
        var priceTxt = holder.getView<TextView>(R.id.tv_price)
        var fontStr = "订单金额："
        var str =  SpannableString("¥ ${item.pay_price}")

        priceTxt.text = SpannableUtils.setStrSpan(
            "${fontStr}${str}",
            -1,
            ContextCompat.getColor(
                context, R.color.col_2621
            ),
            -1,
            "${fontStr}${str}".length -"${str}".length,
            "${fontStr}${str}".length
        )
        holder.setText(R.id.tv_num,"数量：${item.goods_num}")
        var status = holder.getView<TextView>(R.id.tv_order_status)

        status.text = item.status_name
        when(item.status){ //1待支付 2已支付(待发货) 3待收货 4已完成5已取消6退款中7退款成功8退款失败
            1 ->{
                status.setTextColor(context.getColor(R.color.col_9BD))
                holder.setGone(R.id.tv_confirm_receive_goods,true)
                holder.setText(R.id.tv_logistics,"取消订单")
                holder.setText(R.id.tv_refund,"立即支付")

                holder.setGone(R.id.tv_logistics,false)

                holder.setGone(R.id.tv_refund,false)
            }
            2 ->{
                holder.setGone(R.id.tv_confirm_receive_goods,true)
                holder.setText(R.id.tv_logistics,"联系客服")
                holder.setText(R.id.tv_refund,"申请退款")

                holder.setGone(R.id.tv_logistics,false)

                holder.setGone(R.id.tv_refund,false)
            }
            3->{
                status.setTextColor(context.getColor(R.color.col_9BD))
                holder.setGone(R.id.tv_confirm_receive_goods,false)
                holder.setText(R.id.tv_logistics,"查看物流")
                holder.setText(R.id.tv_refund,"申请退款")
                holder.setGone(R.id.tv_logistics,false)

                holder.setGone(R.id.tv_refund,false)

            }
            4 ,8->{
                status.setTextColor(context.getColor(R.color.col_02c))
                holder.setText(R.id.tv_logistics,"联系客服")
                holder.setGone(R.id.tv_confirm_receive_goods,true)
                holder.setGone(R.id.tv_logistics,false)

                holder.setGone(R.id.tv_refund,true)
                holder.setGone(R.id.line,true)

            }
            else ->{
                status.setTextColor(context.getColor(R.color.col_9BD))

                holder.setGone(R.id.tv_confirm_receive_goods,true)
                holder.setGone(R.id.tv_logistics,true)

                holder.setGone(R.id.tv_refund,true)
                holder.setGone(R.id.line,true)


            }

        }

    }
}