package com.zxhl.main.page.activity

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.content.res.AssetFileDescriptor
import android.graphics.Color
import android.media.MediaPlayer
import android.text.Html
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.animation.Animation
import android.view.animation.AnimationSet
import android.view.animation.AnimationUtils
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.Constant
import com.zxhl.cms.common.NetConfig
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.SettingPreference
import com.zxhl.cms.net.model.box.*
import com.zxhl.cms.net.model.video.MemberEntity
import com.zxhl.cms.pay.PayActivity
import com.zxhl.cms.pay.PayContract
import com.zxhl.cms.pay.PayPresenter
import com.zxhl.cms.utils.*
import com.zxhl.cms.widget.LoadingDialog
import com.zxhl.main.R
import com.zxhl.main.page.`interface`.PopupWidowCloseCallBack
import com.zxhl.main.page.contract.LotteryContract
import com.zxhl.main.page.presenter.LotteryPresenter
import com.zxhl.main.page.view.DialogUtils
import com.zxhl.main.page.view.RecoverPopupWindow
import com.zxhl.novel.utils.server.PayResultEntity
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_layout_lottery_reslut.*
import kotlinx.android.synthetic.main.activity_layout_lottery_reslut.id_ll_five_chou

class LotteryRuslutActivity : BaseActivity(), LotteryContract.View, AdCallback<String>,
    PopupWidowCloseCallBack, Animator.AnimatorListener, PayContract.View {

    private var boxid: String? = ""
    private var type: String? = ""
    private var mPresenter: LotteryPresenter? = null
    private var userCoins: Double = 0.0
    private var oneSellCoin: Double = 0.0
    private var fiveSellCoin: Double = 0.0
    private var mMediaPlayer: MediaPlayer? = null
    private var price = ""
    private var recoverprice = ""
    private var huixueprice = ""
    private var isUseHuixueCard = "0"
    private var goodsReslut: LotteryEntity? = null
    private var ids: String = ""
    private var goodsLevel: String? = ""
    private var intentlist: MutableList<LotteryEntity>? = ArrayList()
    private var mfinishactivity: Observable<Int>? = null
    private var mPayPresenter: PayContract.Presenter? = null
    private var mLoading: LoadingDialog? = null
    private var payResultObservable: Observable<PayResultEntity>? = null
    private var pay_type = 0
    override fun onClick(v: View?) {

    }

    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_lottery_reslut
    }

    override fun init() {
        initPayCoing()
        mfinishactivity =
            RxBus.get().register(Constant.finish_activity, Int::class.java)
        mfinishactivity?.observeOn(AndroidSchedulers.mainThread())
            ?.subscribe(Consumer<Int?> { s ->
                finish()
            }, Consumer<Throwable?> { })
        mMediaPlayer = MediaPlayer()
        mMediaPlayer?.reset()
        val afd: AssetFileDescriptor = this.assets.openFd("getgoods.mp3")
        mMediaPlayer?.setDataSource(afd.fileDescriptor, afd.startOffset, afd.length)
        mMediaPlayer?.prepareAsync()
        mMediaPlayer?.setOnPreparedListener {
            mMediaPlayer?.start()

        }
        mMediaPlayer?.setOnCompletionListener {
            mMediaPlayer?.stop()
        }
        id_img_back?.setOnClickListener {
            finish()
        }
        id_tv_kefu?.setOnClickListener {
            JumpUtils.webJump("客服", NetConfig.H5.WEB_URL_CUSTOMER_SERVICE)
        }
        id_tv_cangku?.setOnClickListener {
            finish()
            RxBus.get().post(Constant.SWITCH_PAGE, 1)
            //JumpUtils.lotteryBoxJump(boxid, Constant.Key.ONE_LOTTERY, "")
        }
        id_tv_go_cangku?.setOnClickListener {
            finish()
            RxBus.get().post(Constant.SWITCH_PAGE, 1)
        }
        id_tv_go_on?.setOnClickListener {
            if (type.equals(Constant.Key.RE_PUMPING_ONE_LOTTERY) || type.equals(Constant.Key.DOUBLE_LOTTERY)) {
                type = Constant.Key.ONE_LOTTERY
            }
            if (type.equals(Constant.Key.RE_PUMPING_FIVE_LOTTERY)) {
                type = Constant.Key.FIVE_LOTTERY
            }
            if (type.equals(Constant.Key.ONE_LOTTERY)) {
                EventUtils.onEvent("one_more_lottery", "再来一发")
            } else if (type.equals(Constant.Key.FIVE_LOTTERY)) {
                EventUtils.onEvent("five_more_lottery", "再来五发")
            }
            Log.e("MXL", "needprice:" + price + "usercoins" + userCoins)
            val needPrice = price?.toDoubleOrNull() ?: 0.00
            if (userCoins > 0 && userCoins >= needPrice) {
                Log.e("MXL", "Id为其他时走之前逻辑" + boxid + price)
                JumpUtils.lotteryBoxJump(boxid, type, price)
                finish()
            } else {
                val coins = needPrice - userCoins
                if (TextUtils.equals("flow_tag_xymh_z", SettingPreference.getFlowTag())) {
                    mLoading?.setLoading("loading")
                    mLoading?.show()
                    if (pay_type == 1) {
                        mPayPresenter?.requestAliPay(
                            this,
                            coins.toString(),
                            pay_type.toString(),
                            "6"
                        )
                    } else {
                        mPayPresenter?.requestMiniProgrom(
                            coins.toString(),
                            pay_type.toString(),
                            "6"
                        )
                    }
                } else {
                    JumpUtils.payJump(boxid, coins.toString(), type)
                }
            }
        }
        id_tv_huishou?.setOnClickListener {
            RecoverPopupWindow().init(
                this,
                ids,
                price,
                type,
                recoverprice,
                "0",
                this,
                intentlist,
                null,
                recoveType
            )
        }
        id_tv_coin_num?.setOnClickListener {
            JumpUtils.payJump("0", "0", "0")
        }
        id_tv_coin_num?.text = SettingPreference.getUserCoinNum()
        boxid = intent?.data?.getQueryParameter("boxid") ?: ""
        type = intent?.data?.getQueryParameter("type") ?: ""
        price = intent?.data?.getQueryParameter("price") ?: ""
        var depotIds = intent?.data?.getQueryParameter("depotIds") ?: ""
        mPresenter = LotteryPresenter(this)
        if (type.equals(Constant.Key.TEST_LOTTERY)) {
            mPresenter?.testLottery(boxid)
            id_rl_lottery_result_bottom.visibility = View.GONE
            id_tv_text.visibility = View.GONE
        } else if (type.equals(Constant.Key.ONE_LOTTERY)) {
            id_rl_lottery_result_bottom.visibility = View.VISIBLE
            id_tv_text.visibility = View.GONE
            id_tv_go_on.text = "再来一发"
            mPresenter?.oneLottery(boxid)
        } else if (type.equals(Constant.Key.FIVE_LOTTERY)) {
            id_rl_lottery_result_bottom.visibility = View.VISIBLE
            id_tv_text.visibility = View.GONE
            id_tv_go_on.text = "再来五发"
            mPresenter?.fiveLottery(boxid)
        } else if (type.equals(Constant.Key.RE_PUMPING_ONE_LOTTERY)) {
            //重抽单抽
            if (boxid != null) {
                id_rl_lottery_result_bottom.visibility = View.VISIBLE
                id_tv_text.visibility = View.GONE
                id_tv_go_on.text = "再来一发"
                mPresenter?.rePumpingOneLottery(boxid, depotIds)
            }
        } else if (type.equals(Constant.Key.RE_PUMPING_FIVE_LOTTERY)) {
            //重抽五连抽
            if (boxid != null) {
                id_rl_lottery_result_bottom.visibility = View.VISIBLE
                id_tv_text.visibility = View.GONE
                id_tv_go_on.text = "再来五发"
                mPresenter?.rePumpingFiveLottery(boxid, depotIds)
            }
        }


        initAnim()
    }

    private var annotation: AnimatorSet? = null

    private fun initAnim() {
        annotation = AnimatorSet()

        val startBgAnim: ObjectAnimator =
            ObjectAnimator.ofFloat(id_activity_lottery_result_anim_bg, "alpha", 0f, 1f)
        val startImgAnim: ObjectAnimator =
            ObjectAnimator.ofFloat(id_activity_lottery_result_anim_img, "alpha", 0f, 1f)

        val endBgAnim: ObjectAnimator =
            ObjectAnimator.ofFloat(id_activity_lottery_result_anim_bg, "alpha", 1f, 0f)
        val endImgAnim: ObjectAnimator =
            ObjectAnimator.ofFloat(id_activity_lottery_result_anim_img, "alpha", 1f, 0f)

        startBgAnim?.setDuration(500)
        startImgAnim?.setDuration(800)

        endBgAnim?.setDuration(800)
        endImgAnim?.setDuration(800)

        annotation?.playSequentially(startBgAnim, startImgAnim)
        annotation?.play(endBgAnim)?.with(endImgAnim)?.after(2200)
        annotation?.addListener(this)
        annotation?.startDelay = 500
    }

    fun startAlphaAnim() {
        annotation?.start()
    }

    override fun onAnimationStart(p0: Animator?) {
    }

    override fun onAnimationEnd(p0: Animator?) {
        id_view_lottie?.postDelayed({
            id_view_lottie?.resumeAnimation()
        }, 400)
        id_view_lottie?.postDelayed({
            setGoodsData(goodsReslut)
        }, 700)
        id_view_lottie?.addAnimatorUpdateListener(object : ValueAnimator.AnimatorUpdateListener {
            override fun onAnimationUpdate(animation: ValueAnimator?) {
                if (animation?.animatedFraction == 1f) {
                    Log.e("MXL", "播放变色动画结束")
                    if (goodsReslut != null) {

                    }
                }
            }
        })
    }

    override fun onAnimationCancel(p0: Animator?) {
    }

    override fun onAnimationRepeat(p0: Animator?) {
    }

    override fun setOneLotterResult(result: OneLotteryEntity?) {
        if (result?.goods != null) {
            intentlist?.clear()
            intentlist?.add(result?.goods!!)
        }
        UserDataUtils.updateUserInfo(this)
        if (!TextUtils.isEmpty(result?.text)) {
            id_tv_text.visibility = View.VISIBLE
            id_tv_text?.text = Html.fromHtml(result?.text)
        } else {
            id_tv_text.visibility = View.GONE
        }
        if (type.equals(Constant.Key.DOUBLE_LOTTERY)) {
//            id_tv_text_card.visibility = View.VISIBLE
//            id_tv_text_card?.text = "使用暴击卡额外获得商品\n回收不可获得幸运币"
        } else {
            if (!TextUtils.isEmpty(result?.card?.text)) {
                id_tv_text_card.visibility = View.VISIBLE
                id_tv_text_card?.text = Html.fromHtml(result?.card?.text)
            } else {
                id_tv_text_card.visibility = View.GONE
            }
        }

        if (result?.popUps == false) {
            id_img_bottom_anim.visibility = View.GONE
        } else {
            id_img_bottom_anim.visibility = View.VISIBLE
            id_img_bottom_anim?.animation = AnimationUtils.loadAnimation(this, R.anim.input_down)
            MainLooper.get()
                ?.postDelayed(Runnable {
                    id_img_bottom_anim?.animation =
                        AnimationUtils.loadAnimation(this, R.anim.outdown)
                    id_img_bottom_anim.visibility = View.GONE
                }, 2000)

        }
        if (result?.fake != null) {
            Log.e("MXL", "存在假的产品")
            goodsLevel = result?.goods?.goodsLevel
            setOneInfoData(result?.fake)
            goodsReslut = result?.goods
        } else {
            setOneInfoData(result?.goods)
        }


    }

    fun setGoodsData(result: LotteryEntity?) {
        EventUtils.onEvent("one_lottery_goodsID" + "" + result?.id)
        ids = result?.depotId.toString()
        recoverprice = result?.recoverPriceStr.toString()
        id_tv_pinzhi?.text = "${result?.cateName}"
        id_tv_good_name?.text = "${result?.productName}"
        id_img_goods?.setLoadImageUrl(result?.mainImage, false)
        // setGoodBg(result?.goodsLevel.toString())
        //  id_img_goods_bg.visibility = View.VISIBLE
    }

    fun setOneInfoData(result: LotteryEntity?) {
        EventUtils.onEvent("one_lottery_goodsID" + "" + result?.id)
        if (!TextUtils.isEmpty(goodsLevel)) {
            Log.e("MXL", "GOODSLEVEL" + goodsLevel)
            if (goodsLevel.equals("1")) {
                id_view_lottie?.imageAssetsFolder = "bianxiyou/images/"
                id_view_lottie?.setAnimation("bianxiyou/data.json")
            } else if (goodsLevel.equals("2")) {
                id_view_lottie?.imageAssetsFolder = "bianshishi/images/"
                id_view_lottie?.setAnimation("bianshishi/data.json")
            } else if (goodsLevel.equals("3")) {
                id_view_lottie?.imageAssetsFolder = "bianchuanshuo/images/"
                id_view_lottie?.setAnimation("bianchuanshuo/data.json")
            }
            id_view_lottie?.repeatCount = 0
            id_view_lottie?.playAnimation()
            id_view_lottie?.postDelayed({
                id_view_lottie?.pauseAnimation()
            }, 100)
            startAlphaAnim()

        } else {
            setGoodBg(result?.goodsLevel.toString())
        }

        ids = result?.depotId.toString()
        recoverprice = result?.recoverPriceStr.toString()
        id_ll_dan_chou?.visibility = View.VISIBLE
        id_ll_five_chou?.visibility = View.GONE
        id_tv_pinzhi?.text = "${result?.cateName}"
        id_tv_good_name?.text = "${result?.productName}"
        id_img_goods?.setLoadImageUrl(result?.mainImage, false)
        Log.e("MXL", "LEVEL" + result?.goodsLevel)
        // setGoodBg(result?.goodsLevel.toString())


    }

    fun setGoodBg(level: String) {
        if (level.equals("0")) {
            id_img_goods_bg.setBackgroundResource(R.drawable.bj_putong)
        } else if (level.equals("1")) {
            id_img_goods_bg.setBackgroundResource(R.drawable.bj_xiyou)
        } else if (level.equals("2")) {
            id_img_goods_bg.setBackgroundResource(R.drawable.bj_shishi)
        } else if (level.equals("3")) {
            id_img_goods_bg.setBackgroundResource(R.drawable.bj_chuanshuo)
        }
        // id_img_goods_bg.visibility=View.VISIBLE

    }

    override fun setTestLotterResult(result: LotteryEntity?) {

        setOneInfoData(result)
    }

    var GoodsIdList = ArrayList<String>()
    fun reportGoodsId() {

    }

    override fun setFiveLotterResult(result: FiveLotteryEntiy?) {
        if (result?.goods != null) {
            intentlist?.clear()
            intentlist?.addAll(result?.goods!!)
        }


        UserDataUtils.updateUserInfo(this)
        var mList: List<LotteryEntity>? = null
        if (result?.goods != null) {
            mList = result?.goods
        }

        id_ll_dan_chou?.visibility = View.GONE
        id_ll_five_chou?.visibility = View.VISIBLE
        if (!TextUtils.isEmpty(result?.text)) {
            id_tv_text.visibility = View.VISIBLE
            id_tv_text?.text = Html.fromHtml(result?.text)
        } else {
            id_tv_text.visibility = View.GONE
        }

        if (!TextUtils.isEmpty(result?.card?.text)) {
            id_tv_text_card.visibility = View.VISIBLE
            id_tv_text_card?.text = Html.fromHtml(result?.card?.text)
        } else {
            id_tv_text_card.visibility = View.GONE
        }

        if (result?.popUps == false) {
            id_img_bottom_anim.visibility = View.GONE
        } else {
            id_img_bottom_anim.visibility = View.VISIBLE
            id_img_bottom_anim?.animation = AnimationUtils.loadAnimation(this, R.anim.input_down)
            MainLooper.get()
                ?.postDelayed(Runnable {
                    id_img_bottom_anim?.animation =
                        AnimationUtils.loadAnimation(this, R.anim.outdown)
                    id_img_bottom_anim.visibility = View.GONE
                }, 2000)

        }
        //id_img_one_bg id_img_one id_img_two_bg id_img_two
        //id_img_three_bg id_img_three id_img_four_bg id_img_four
        val sb = StringBuilder()
        if (mList != null) {
            for (dataBean in mList) {
                if (sb.length > 0) {
                    sb.append(",")
                }
                sb.append(dataBean.depotId)
            }
        }
        recoverprice = mList?.get(0)?.recoverPriceStr.toString()
        ids = sb.toString()
        id_tv_one_pinzhi?.text = mList?.get(0)?.cateName
        id_tv_one_name?.text = mList?.get(0)?.productName
//        Glide.with(this).load(mList?.get(0)?.mainImage)
//            .into(id_img_one)
        id_img_one?.setLoadImageUrl(mList?.get(0)?.mainImage, false)
        var mListImgView: MutableList<ImageView> = ArrayList()
        mListImgView.add(id_img_one_bg)
        mListImgView.add(id_img_two_bg)
        mListImgView.add(id_img_three_bg)
        mListImgView.add(id_img_four_bg)
        mListImgView.add(id_img_five_bg)
        for (i in 0 until (mList?.size ?: 0)) {
            Log.e("MXL", "i" + i + mList?.get(i)?.goodsLevel.toString())
            setBg(mListImgView[i], mList?.get(i)?.goodsLevel.toString())
        }

        id_tv_two_pinzhi?.text = mList?.get(1)?.cateName
        id_tv_two_name?.text = mList?.get(1)?.productName
//        Glide.with(this).load(mList?.get(1)?.mainImage)
//            .into(id_img_two)
        id_img_two.setLoadImageUrl(mList?.get(1)?.mainImage, false)
        id_tv_three_pinzhi?.text = mList?.get(2)?.cateName
        id_tv_three_name?.text = mList?.get(2)?.productName
        id_img_three.setLoadImageUrl(mList?.get(2)?.mainImage, false)
//        Glide.with(this).load(mList?.get(2)?.mainImage)
//            .into(id_img_three)
        id_tv_four_pinzhi?.text = mList?.get(3)?.cateName
        id_tv_four_name?.text = mList?.get(3)?.productName
        id_img_four.setLoadImageUrl(mList?.get(3)?.mainImage, false)
//        Glide.with(this).load(mList?.get(3)?.mainImage)
//            .into(id_img_four)
        id_tv_five_pinzhi?.text = mList?.get(4)?.cateName
        id_tv_five_name?.text = mList?.get(4)?.productName
        id_img_five.setLoadImageUrl(mList?.get(4)?.mainImage, false)
//        Glide.with(this).load(mList?.get(4)?.mainImage)
//            .into(id_img_five)
        if (!result?.goods.isNullOrEmpty()) {
            for (i in result?.goods!!) {
                EventUtils.onEvent("five_lootter_GoodsId", "" + i.id)
            }
        }

    }

    override fun setPropsCardList(result: PropsCardList?, cardEntity: PropsCardEntity?) {
        if (null == result) {
            id_ll_props_card_view.visibility = View.GONE
        } else {
            if (result.show) {
                id_ll_props_card_view.visibility = View.VISIBLE
                initPropsCard(result, cardEntity)
            } else {
                id_ll_props_card_view.visibility = View.GONE
            }
        }
    }

    fun setBg(img: ImageView, level: String?) {
        if ("0".equals(level)) {
            img.setImageResource(R.drawable.bj_putong_xiao)
        } else if ("1".equals(level)) {
            img.setImageResource(R.drawable.bj_xiyou_xiao)
        } else if ("2".equals(level)) {
            img.setImageResource(R.drawable.bj_shishi_xiao)
        } else if ("3".equals(level)) {
            img.setImageResource(R.drawable.bj_chuanshuo_xiao)
        }
    }

    override fun onResult(code: Int, result: String?) {
        id_tv_coin_num?.text = SettingPreference.getUserCoinNum()
        userCoins = SettingPreference.getUserCoinNum().toString().toDoubleOrNull() ?: 0.00
        Log.e("MXL", "用户金钱数" + userCoins)
        if (boxid.equals("-2") || boxid.equals("-3")) {
            if (SettingPreference.isNewUser()) {
                boxid = "-1"
                price = "19"
            } else {
                boxid = "80"
                price = "29"
            }
        } else {
            if (TextUtils.equals(boxid, "-1")) {
                price = "29"
            }
        }


    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e("MXL", "LotteryRuslutActivity onDestroy")
        if (mMediaPlayer != null) {
            mMediaPlayer?.stop()
            mMediaPlayer?.release()
        }
        if (mfinishactivity != null) {
            RxBus.get().unregister(Constant.finish_activity, mfinishactivity!!)
        }
        if (payResultObservable != null)
            RxBus.get().unregister(Constant.PAY_RESULT, payResultObservable!!)
    }

    override fun onClosePopupWindow() {

    }

    fun initPayCoing() {
        mLoading = LoadingDialog.getLoadingDialog(
            this,
            getString(com.zxhl.cms.R.string.wait_ing),
            false,
            false
        )
        mPayPresenter = PayPresenter(this)
        mPayPresenter?.appInfo()
        payResultObservable = RxBus.get().register(Constant.PAY_RESULT, PayResultEntity::class.java)
        payResultObservable?.observeOn(AndroidSchedulers.mainThread())
            ?.subscribe(Consumer<PayResultEntity> { obj ->
                if (obj.isPaySuc) {
                    EventUtils.onEvent("pay_page_pay_query_order", "付款成功")
                    mPayPresenter?.verifyPay(obj.txt, obj.payType)
                } else {
                    showResultLoading(false)
                }
            }, Consumer<Throwable> { })
    }

    private fun showResultLoading(isPaySuc: Boolean) {
        if (isPaySuc) {
            EventUtils.onEvent("pay_suc")
            mLoading?.setResult(true, "支付成功", 1000)
        } else {
            EventUtils.onEvent("pay_fail")
            mLoading?.setResult(false, "支付失败", 1000)
        }

    }


    override fun updatePriceList(data: List<MemberEntity.ProductDetail>) {

    }

    override fun verifyOrderFail() {
        showResultLoading(false)
    }

    override fun requestOrderSuc() {
        mLoading?.setLoading("正在支付")
    }

    override fun verifyOrderSuc(orsder: String) {
        UserDataUtils.updateUserInfo(this)
        showResultLoading(true)
        JumpUtils.lotteryBoxJump(boxid, type, price)
    }

    override fun setCanInvest(boolean: Boolean?) {

    }

    override fun setOrderNo(order: String?) {

    }

    var recoveType: String = ""
    override fun setAppInfo(result: AppInEntity?) {
        if (result != null) {
            recoveType = result.recover_type
            if (result.pay_ali.equals("1") && result.pay_wx.equals("0")) {
                pay_type = PayActivity.ALI_PAY
            } else {
                pay_type = PayActivity.MINI_PROGRAM
            }


        }
    }

    //道具卡
    private fun initPropsCard(result: PropsCardList, cardEntity: PropsCardEntity?) {
        //暴击卡
        if (!result.criticalHit.isNullOrEmpty()) {
            id_card_baoji_num.text = " x${result.criticalHit?.size} "
            id_card_baoji_num.setTextColor(Color.parseColor("#4C84FF"))
            id_card_baoji_num.textSize = 12f
            id_card_baoji_suo.visibility = View.GONE
        } else {
            id_card_baoji_num.text = "未获得"
            id_card_baoji_num.setTextColor(Color.parseColor("#999999"))
            id_card_baoji_num.textSize = 10f
            id_card_baoji_suo.visibility = View.VISIBLE
        }
        //重抽卡
        if (!result.rePumping.isNullOrEmpty()) {
            id_card_chongchou_num.text = " x${result.rePumping?.size} "
            id_card_chongchou_num.setTextColor(Color.parseColor("#4C84FF"))
            id_card_chongchou_num.textSize = 12f
            id_card_chongchou_suo.visibility = View.GONE

        } else {
            id_card_chongchou_num.text = "未获得"
            id_card_chongchou_num.setTextColor(Color.parseColor("#999999"))
            id_card_chongchou_num.textSize = 10f
            id_card_chongchou_suo.visibility = View.VISIBLE

        }
        //回血卡
        if (!result.bloodReturn.isNullOrEmpty()) {
            id_card_huixue_num.text = " x${result.bloodReturn?.size} "
            id_card_huixue_num.setTextColor(Color.parseColor("#4C84FF"))
            id_card_huixue_num.textSize = 12f
            id_card_huixue_suo.visibility = View.GONE

        } else {
            id_card_huixue_num.text = "未获得"
            id_card_huixue_num.setTextColor(Color.parseColor("#999999"))
            id_card_huixue_num.textSize = 10f
            id_card_huixue_suo.visibility = View.VISIBLE
        }
//        if (cardEntity?.bloodReturn != null) {
//            DialogUtils.showPropsCard(this,
//                3, 1, 1,
//                "恭喜您获得回血卡，下次抽盒\n即可使用",
//                "使用回血卡可提升回收获得的幸运币",
//                {
//                    //left
//                }, {
//                    //right
//                    id_tv_go_on.callOnClick()
//                })
//        }
//        if (cardEntity?.criticalHit != null) {
//            DialogUtils.showPropsCard(this,
//                2, 1, 1,
//                "恭喜您获得暴击卡，下次抽盒\n即可使用",
//                "使用暴击卡可多获得一件商品",
//                {
//                    //left
//                }, {
//                    //right
//                    id_tv_go_on.callOnClick()
//                })
//        }
        if (cardEntity?.rePumping != null) {
            DialogUtils.showPropsCard(this,
                1,
                1,
                2,
                "恭喜您获得重抽卡，下次抽盒\n即可使用",
                "Not satisfied with the product, you can use the reopen card to reopen the box for free",
                {
                    //left
                }, {
                    //right
                    if (type == Constant.Key.ONE_LOTTERY && isUseHuixueCard == "0") {
                        finish()
                        JumpUtils.lotteryBoxJump(
                            boxid,
                            Constant.Key.RE_PUMPING_ONE_LOTTERY,
                            price,
                            ids
                        )
                    } else if (type == Constant.Key.FIVE_LOTTERY && isUseHuixueCard == "0") {
//                            JumpUtils.lotteryBoxJump(
//                                boxid,
//                                Constant.Key.RE_PUMPING_FIVE_LOTTERY,
//                                price,
//                                ids
//                            )
//                            finish()
                        showToast("仅限单次抽取")
                    } else {
                        id_tv_go_on.callOnClick()
                    }
                })
        }


        //暴击卡
//        id_card_baoji.setOnClickListener {
//            EventUtils.onEvent("baoji_card_click")
//            var cardNum = if (result.criticalHit.isNullOrEmpty()) 0 else result.criticalHit!!.size;
//            var status = 0;
//            var descStr = ""
//            if (result.criticalHitNum == 1) {
//                descStr = "下次抽取,即可获得暴击卡"
//            } else {
//                descStr = "再抽${result.criticalHitNum}次即可获得暴击卡";
//            }
//            if (cardNum == 1 && cardEntity?.criticalHit != null) {
//                status = 0;
//            } else {
//                if (cardNum > 0) {
//                    status = 2
//                    descStr = "是否使用暴击卡"
//                }
//            }
//            DialogUtils.showPropsCard(this,
//                2, cardNum, status,
//                descStr,
//                "使用暴击卡可多获得一件商品",
//                {
//                    //left
//                }, {
//                    //right
//                    if (status == 2) {
//                        if ((type == Constant.Key.ONE_LOTTERY || type == Constant.Key.FIVE_LOTTERY) && isUseHuixueCard == "0") {
//                            JumpUtils.lotteryBoxJump(boxid, Constant.Key.DOUBLE_LOTTERY, price, ids)
//                            finish()
//                        } else {
//                            showToast("一次只能使用一张卡")
//                        }
//
//                    } else {
//                        id_tv_go_on.callOnClick()
//                    }
//                })
//        }
        //重抽卡
        id_card_chongchou.setOnClickListener {
            EventUtils.onEvent("chongchou_click")
            var cardNum = if (result.rePumping.isNullOrEmpty()) 0 else result.rePumping!!.size;
            var status = 0;
            var descStr = ""

            if (cardNum > 0) {
                status = 2
                descStr = "是否使用重抽卡"
            } else {
                if (result.rePumpingNum == 1) {
                    descStr = "下次必得重抽卡"
                } else if (result.rePumpingNum == -1) {
                    descStr = ""
                    status = -1;
                } else {
                    descStr = "再抽${result.rePumpingNum}次即可获得重抽卡";
                }

            }

            DialogUtils.showPropsCard(this,
                1,
                cardNum,
                status,
                descStr,
                "Not satisfied with the product, you can use the reopen card to reopen the box for free",
                {
                    //left
                }, {
                    //right
                    if (status == 2) {
                        if (type == Constant.Key.ONE_LOTTERY && isUseHuixueCard == "0") {
                            JumpUtils.lotteryBoxJump(
                                boxid,
                                Constant.Key.RE_PUMPING_ONE_LOTTERY,
                                price,
                                ids
                            )
                            finish()
                        } else if (type == Constant.Key.FIVE_LOTTERY && isUseHuixueCard == "0") {
//                            JumpUtils.lotteryBoxJump(
//                                boxid,
//                                Constant.Key.RE_PUMPING_FIVE_LOTTERY,
//                                price,
//                                ids
//                            )
//                            finish()
                            showToast("仅限单次抽取")
                        } else {
                            showToast("一次只能使用一张卡")
                        }
                    } else {
                        id_tv_go_on.callOnClick()
                    }
                })
        }
        //回血卡
//        id_card_huixue.setOnClickListener {
//            EventUtils.onEvent("huixue_card_click")
//            var cardNum = if (result.bloodReturn.isNullOrEmpty()) 0 else result.bloodReturn!!.size;
//            var status = 0;
//            var descStr = ""
//            if (result.bloodReturnNum == 1) {
//                descStr = "下次抽取,即可获得回血卡"
//            } else {
//                descStr = "再抽${result.bloodReturnNum}次即可获得回血卡";
//            }
//            if (cardNum == 1 && cardEntity?.bloodReturn != null) {
//                status = 0;
//            } else {
//                if (cardNum > 0) {
//                    status = 2
//                    descStr = "是否使用回血卡"
//                }
//            }
//            isUseHuixueCard = "0"
//            DialogUtils.showPropsCard(this,
//                3, cardNum, status,
//                descStr,
//                "使用回血卡可提升回收获得的幸运币",
//                {
//                    //left
//                }, {
//                    //right
//                    if (status == 2) {
//                        if ((type == Constant.Key.ONE_LOTTERY || type == Constant.Key.FIVE_LOTTERY) && isUseHuixueCard != "1") {
//                            isUseHuixueCard = "1"
//                            id_tv_huishou.callOnClick()
//                            showToast("回收将获得额外幸运币")
//                        } else {
//                            showToast("一次只能使用一张卡")
//                        }
//                    } else {
//                        id_tv_go_on.callOnClick()
//                    }
//                })
//        }
    }

}