package com.zj365.health.act

import android.annotation.SuppressLint
import android.text.TextUtils
import android.view.View
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.GsonUtils
import com.xty.base.act.BaseListAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.setImage
import com.zj365.health.databinding.ActOrderDetailBinding
import com.zj365.health.vm.PayCancerVm
import com.xty.network.model.CancerGoodsBean

/**
 * 已填问卷列表
 */
@Route(path = ARouterUrl.ORDER_DETAIL)
class OrderDetailAct : BaseListAct<PayCancerVm>() {

    val binding by lazy { ActOrderDetailBinding.inflate(layoutInflater) }

    var data: CancerGoodsBean? = null
    override fun setLayout() = binding.root

    @SuppressLint("SetTextI18n")
    override fun initData() {
        super.initData()
        val result = intent.getStringExtra("data")
        if (!TextUtils.isEmpty(result)) {
            data = GsonUtils.fromJson(result, CancerGoodsBean::class.java)
            data?.let {
                binding.tvGoodsIms.apply {
                    if (!TextUtils.isEmpty(it.goodsImageUrl)) {
                        setImage(baseContext, it.goodsImageUrl)
                    } else {
                        setImage(baseContext, "https://minioapi.auprty.com/anyu/app/xuefei.png")
                    }
                }
                binding.tvTitle.text = it.goodsName
                val equals = it.payChannel.equals("EXCHANGE_CODE")
                if (equals) {
                    binding.tvPrice.visibility = View.GONE
                    binding.llAll.visibility = View.GONE
                } else {
                    binding.tvPrice.visibility = View.VISIBLE
                    binding.llAll.visibility = View.VISIBLE
                }

                binding.tvPrice.text = "¥${it.price}"
                binding.tvPriceAll.text = "¥${it.price}"
                binding.tvOrderNo.text = it.orderNo
                binding.tvPayTime.text = it.payTime
                binding.tvDealTime.text = it.createTime

                when (it.payChannel) {
                    "ALIPAY_APP" -> {
                        binding.tvPayType.text = "支付宝"
                    }

                    "WEIXIN_APP" -> {
                        binding.tvPayType.text = "微信"
                    }

                    "EXCHANGE_CODE" -> {
                        binding.tvPayType.text = "兑换码(${
                            if (!TextUtils.isEmpty(it.exchangeCode)) {
                                it.exchangeCode
                            } else {
                                "--"
                            }
                        })"
                    }

                    "EXPERIENCE" -> {
                        binding.tvPayType.text = "免费试用"
                    }

                    else -> {
                        binding.llPayType.isVisible = false
                    }
                }
            }
        }
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "订单详情"
        binding.title.mIvBack.setOnClickListener { finish() }
        mViewModel.getEstimateRecord()
    }

    override fun initAdapter() {

    }

    override fun loadData() {
        mViewModel.getEstimateRecord()
    }

    override fun liveObserver() {

    }

}