/*
 * @Author: mojunshou 1637302775@qq.com
 * @Date: 2025-04-19 11:34:46
 * @LastEditors: mojunshou 1637302775@qq.com
 * @LastEditTime: 2025-04-28 16:32:36
 * @Description: 微信转账中界面
 */
import { _decorator, Component, Node, Animation } from 'cc';
import VMParent from 'db://oops-framework/libs/model-view/VMParent';
import { smc } from '../../common/SingletonModuleComp';
import { oops } from 'db://oops-framework/core/Oops';
import { UIID } from '../../common/config/GameUIConfig';
import { DeviceUtil } from 'db://oops-framework/core/utils/DeviceUtil';
import { Format } from '../../utils/Format';
import { DCHandler } from '../../common/manager/DCHandler';
import { ServerHandler } from '../../common/manager/ServerHandler';
import { GameEvent } from '../../common/config/GameEvent';
const { ccclass, property } = _decorator;

@ccclass('WechatTransfer')
export class WechatTransfer extends VMParent {
    data: any = {
        money: 1076.6,
        //手续费
        cost: 300,
        gameName: "",
        rates: 70,   //费率
        //还差
        differ: 70,
        //赠送金额
        creditNum: 100,

    }

    @property(Node)  //微信转账中
    private showNode1: Node = null!;

    @property(Node)  //第三方安全验证
    private showNode2: Node = null!;

    @property(Node)  //高价值用户
    private showNode3: Node = null!;

    @property(Node)  //微信打款中
    private showNode4: Node = null!;


    start() {
        oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
        DCHandler.inst.reportData(3000201);
        this.setButton();
        this.showNode1.active = true;
        this.showNode2.active = false;
        this.data.gameName = oops.config.game.gameName;
        this.updateData();
    }

    //设置数据
    updateData() {
        if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
            this.data.money = Format.formatWxCoin(smc.account.AccountModel.wxCoin);
            this.data.cost = smc.game.GameModel.costInfo.handlingCharge;
            this.data.creditNum = smc.game.GameModel.costInfo.giftNum;
            this.data.differ = smc.game.GameModel.costInfo.handlingCharge - smc.game.GameModel.costInfo.giftNum;
        }
    }



    btn_continue() {
        //第三方安全验证
        this.showNode1.active = false;
        this.showNode2.active = true;
        //播放动画
        DCHandler.inst.reportData(3000202);
        const animation = this.showNode2.getComponent(Animation);
        if (animation) {
            animation.play();
        }

    }

    //安全验证关闭
    btn_verifyClose() {
        //高价值用户
        this.onVerifyClose();

    }

    //安全验证知道了
    btn_knew() {
        //高价值用户
        this.onVerifyClose();
    }

    onVerifyClose() {
        DCHandler.inst.reportData(3000203);
        this.showNode2.active = false;
        this.showNode3.active = true;
        const animation = this.showNode3.getComponent(Animation);
        if (animation) {
            animation.play();
        }
    }


    //高价值用户关闭
    btn_HightValueClose() {
        this.onHightValueClose();
        ServerHandler.inst.getFee();
    }


    //高价只用户开心收下
    btn_happyAccept() {
        this.onHightValueClose();
        ServerHandler.inst.getFee();
    }


    onHightValueClose() {
        this.showNode3.active = false;
        this.showNode4.active = true;
        const animation = this.showNode4.getComponent(Animation);
        if (animation) {
            animation.play();
        }
        //3秒后关闭
        this.scheduleOnce(() => {
            ServerHandler.inst.updatePopupState({
                level: smc.account.AccountModel.curLevel,
                type: smc.game.GameModel.popupType
            })
            oops.gui.remove(UIID.WechatTransfer)
        }, 4)
    }
}


