/** 
 * @description 提现结果界面类
 * @author kaka
 */
const { ccclass, property } = cc._decorator;

@ccclass
export default class CashPro extends cc.Component {
    //提现成功
    @property(cc.Node)
    loadPart: cc.Node = null;

    @property(cc.Animation)
    loadAni: cc.Animation = null;

    @property(cc.Node)
    moneyPart: cc.Node = null;

    @property(cc.Label)
    labRedMoney: cc.Label = null;

    @property(cc.Node)
    btnTixian: cc.Node = null;

    @property(cc.Node)
    btnAuth: cc.Node = null;

    @property(cc.Node)
    cashPro: cc.Node = null;

    @property(cc.Label)
    labMoney: cc.Label = null;

    //提现金额
    money = 0

    //点击冷却
    hasTap = false

    update() {
        if (gData.cashPro.init_data) {
            this.init(gData.cashPro.cashPro_money);
        }

        if (gData.cashPro.init_success) {
            this.tixianSuccess();
        }

        if (gData.cashPro.init_fail) {
            this.tixianFail();
        }
    }

    lateUpdate() {
        gData.cashPro.init_data = false;
        gData.cashPro.init_success = false;
        gData.cashPro.init_fail = false;
    }

    init(money) {
        this.money = money

        this.loadPart.active = false
        this.cashPro.active = false

        if (gData.loginData.isAuth) {
            this.btnAuth.active = false
            this.btnTixian.active = true
        }
        else {
            this.btnAuth.active = true
            this.btnTixian.active = false
        }
    }

    showLoad() {
        this.loadPart.active = true
        this.loadAni.play('load', 0)
    }

    tixianSuccess() {
        this.loadPart.active = false
        this.showCashPro()
    }

    showCashPro() {
        this.cashPro.active = true;
        mk.tween.move(this.cashPro, 0.3, cc.v2(1000, 0), cc.v2(0, 0), null, 'elasticIn');
        this.labMoney.string = `¥${this.money}`
    }

    tixianFail() {
        console.log('tixianFail  ')
        this.loadPart.active = false

        mk.ui.closePanel('module/cashPro/cashPro')
    }

    authBack() {
        this.btnAuth.active = false
        this.btnTixian.active = true
    }

    clickCash() {
        mk.audio.playEffect('button');

        this.showLoad();
        gData.cashPro.onCash();
    }

    clickAuth() {
        mk.audio.playEffect('button');
        if (!this.hasTap) {
            this.hasTap = true
            // AdM.WxLogin()

            this.scheduleOnce(() => {
                this.hasTap = false
            }, 3)
        }
    }
}
