import { IGameCfgData } from './../../libs/tw/data/game/cfg/IGameCfgData';
import { GFun } from './../../libs/tc/util/GFun';
import { NetName } from './../../libs/tw/enum/NetName';
import { TaskRenderer } from './TaskRenderer';
import { DataManager } from './../../libs/tw/manager/DataManager';
import { ModuleTypes } from './../types/sceneTypes';

import Scene from "../views/Scene";
import PanelCtrl from "../ctrls/panelCtrl";
import SceneCtrl from '../ctrls/sceneCtrl';
import { NetManager } from '../../libs/tw/manager/NetManager';
import Loading from '../loading/Loading';
import { Buried } from '../../libs/tw/util/Buried';
import { GCache } from '../../libs/tc/util/GCache';
import { ButtonType } from "../types/sceneTypes";
import SvgaCtrl from "../ctrls/svgaCtrl";
import CityItem from '../storePanel/CityItem';
import { GDispatcher } from '../../libs/tc/util/GDispatcher';
import { GetBuriedData } from '../ctrls/GetBuriedData';
import OppoShareCtrl from '../ctrls/oppoShareCtrl';

export default class StartScene extends Scene {

    public get skinKey() { return 'StartScene' }
    public get groupName() { return 'startscene' }
    public mData: any;

    public startBg: eui.Image;
    private startBgTexture:egret.Texture;

    public startList: eui.Scroller;
    public startGroup: eui.Group;
    public card1Group: eui.Group;
    public card1img: eui.Image;
    public card1di: eui.Image;
    public card1num: eui.Label;

    public card2Group: eui.Group;
    public card2img: eui.Image;
    public card2di: eui.Image;
    public card2num: eui.Label;

    public card3Group: eui.Group;
    public card3img: eui.Image;
    public card3di: eui.Image;
    public card3num: eui.Label;

    public card4Group: eui.Group;
    public card4img: eui.Image;
    public card4di: eui.Image;
    public card4num: eui.Label;

    public card5Group: eui.Group;
    public card5img: eui.Image;
    public card5di: eui.Image;
    public card5num: eui.Label;

    public jinGroup: eui.Group;
    public jinimg: eui.Image;
    public jindi: eui.Image;
    public jinnum: eui.Label;

    public cardBtn: eui.Button;
    public cardnum: eui.Label;
    public openBtn: eui.Button;
    public waitBtn: eui.Button;
    public hadopenBtn: eui.Button;
    public endgameBtn: eui.Button;

    public guanzhuBtn: eui.Button;
    public ruleBtn: eui.Button;
    public prizeBtn: eui.Button;
    public diGroup: eui.Group;
    public diimg:eui.Image;
    public warnBtn: eui.Button;
    public warn2Btn: eui.Button;
    public starttip:eui.Image;

    public taskGroup: eui.Group;
    private func1: any;
    private func2: any;
    private func3: any;
    private func4: any;
    private func5: any;
    private func6: any;

    public pushstatus: any;
    public diheight: any = 0;

    private getcardExposure: any;
    private openExposure: any;
    private pushExposure: any;
    private closeExposure: any;
    private ruleExposure: any;
    private prizeExposure: any;

    public static instance: StartScene;
    constructor(data?) {
        super(data);
        if(data){
            this.mData = data;
            this.pushstatus = data.pushstatus;
        }else{
            let tmpData = { baseinfo: DataManager.ins.getData(NetName.OPPO_JOIN1_INDEX).data, 
                            taskinfo: DataManager.ins.getData(NetName.OPPO_QUERYTASKLIST).data, 
                            pushstatus: DataManager.ins.getData(NetName.OPPO_SUBSCIBE_STATE).data.status };
            this.mData = tmpData;
            this.pushstatus = tmpData.pushstatus;
        }
        console.log("pushstatus："+this.pushstatus);
        StartScene.instance = this;
        // this.startList.height = 1080/window.innerWidth*window.innerHeight;
    }

    initEvents() {
        super.initEvents();
        // for (let i = 1; i < 6; i++) {
        //     this["func" + i] = this.showCard.bind(this, i, this.mData.baseinfo.cardList[i - 1].cardNum)
        //     this["card" + i + "Group"].addEventListener(egret.TouchEvent.TOUCH_TAP, this["func" + i], this);

        // }
        
        //this.diimg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_openColose, this);
        this.prizeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_prizeBtn, this);
        this.ruleBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ruleBtn, this);
        this.guanzhuBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.guanzhu, this);
        GDispatcher.addEvent("updateCard", this.updateCard, this)
        this.starttip.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{window.location.href = "https://www.oppo.com/cn/privacy/policy"}, this);
    }
    // private timesOpen = 0;
    // private onTap_openColose(){
    //     this.timesOpen ++;
    //     if(this.timesOpen == 20){
    //         window['openConsole']();
    //     }
    // }
    updateCard() {
        console.log('刷新2');
        setTimeout(() => {
            OppoShareCtrl.instance.share();
        }, 2000);
       
        let data = DataManager.ins.getData(NetName.OPPO_JOIN1_INDEX).data;
        this.mData.baseinfo == data;
        if (data) {
            // console.log("卡片信息")card1
            for (let i = 0; i < data.cardList.length; i++) {
                this["card" + (i + 1) + "num"].text = data.cardList[i].cardNum;
                if (data.cardList[i].cardNum == 0) {
                    this["card" + (i + 1) + "di"].visible = false;
                    this["card" + (i + 1) + "num"].visible = false;
                    if (i + 1 == 1) {
                        this["card" + (i + 1) + "img"].source = "cardpeach3_png";
                    } else if (i + 1 == 2) {
                        this["card" + (i + 1) + "img"].source = "cardfina3_png";
                    } else if (i + 1 == 3) {
                        this["card" + (i + 1) + "img"].source = "cardcase3_png";
                    } else if (i + 1 == 4) {
                        this["card" + (i + 1) + "img"].source = "cardhapp3_png";
                    } else if (i + 1 == 5) {
                        this["card" + (i + 1) + "img"].source = "cardheal3_png";
                    }

                }
            }
            if (data.eggCardStatus == 1) {
                this.jinimg.source = "cardlucky3_png"
                this.jindi.visible = false;
                this.jinnum.visible = false;

            } else {
                this.jinnum.text = "1";
            }

        }
        let iswx = 0;
        if (GFun.getIsWxClient()) {
            iswx = 2;
        } else {
            iswx = 1;
        }
        if (iswx == 2) {
            this.guanzhuBtn.visible = false;
        } else {
            this.guanzhuBtn.visible = false;
        }
        if (data.collectStatus == 1) {
            this.cardBtn.visible = true;
            this.cardnum.visible = true;
            this.cardBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.getCard, this)
            this.cardnum.text = data.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (data.collectStatus == 2) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = data.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = true;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (data.collectStatus == 3) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = data.remainTimes;
            this.openBtn.visible = true;
            this.openBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPrize, this)
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (data.collectStatus == 4) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = data.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = true;
            this.hadopenBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "已开奖，可于我的奖品中查看奖品详情～" }) }, this)
            this.endgameBtn.visible = false;
        } else if (data.collectStatus == 5) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = data.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = true;
        }
        
        if (data.receiveEggCard) {
            let data = { prizeId: "egg_card" }
            PanelCtrl.instance.show(ModuleTypes.GETCARD_PANEL, data);
        }
        if (this.pushstatus == 0) {
            this.warnBtn.visible = true;
            this.warn2Btn.visible = false;
            this.warnBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
            this.warn2Btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);

        } else {
            this.warnBtn.visible = false;
            this.warn2Btn.visible = true;
            this.warnBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
            this.warn2Btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
        }
        if(GFun.getIsWxClient()){
            this.warnBtn.visible = false;
            this.warn2Btn.visible = false;
        }
    }

    removeEvents() {
        super.removeEvents();
        for (let i = 1; i < 6; i++) {
            this["card" + i + "Group"].removeEventListener(egret.TouchEvent.TOUCH_TAP, this["func" + i], this);

        }
        this.jinGroup.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.func6, this);
        this.prizeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_prizeBtn, this);
        this.ruleBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ruleBtn, this);
        this.guanzhuBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.guanzhu, this);
        this.cardBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.getCard, this)
        this.openBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.openPrize, this)
        this.hadopenBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "已开奖，可于我的奖品中查看奖品详情～" }) }, this)
        this.endgameBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "活动已结束" }) }, this)
        this.warnBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
        this.warn2Btn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
    }

    setEvents() {
        for (let i = 1; i < 6; i++) {
            this["card" + i + "Group"].addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "去OPPO+APP和微信参与哦～" }) }, this);

        }
        this.jinGroup.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "去OPPO+APP和微信参与哦～" }) }, this);
        this.prizeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_prizeBtn, this);
        this.ruleBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ruleBtn, this);
        this.guanzhuBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.guanzhu, this);
        this.cardBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "去OPPO+APP和微信参与哦～" }) }, this)
        this.openBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "去OPPO+APP和微信参与哦～" }) }, this)
        this.hadopenBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "已开奖，可于我的奖品中查看奖品详情～" }) }, this)
        this.endgameBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "活动已结束" }) }, this)
        this.warnBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
        this.warn2Btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
    }

    initBuried() {
        this.ruleExposure = GetBuriedData(8)
        NetManager.ins.showLog(this.ruleExposure);
        this.prizeExposure = GetBuriedData(9)
        NetManager.ins.showLog(this.prizeExposure);
    }

    start() {
        super.start();
        this.percentHeight = 100;

    }
    private cityJson;
    protected async preLoadRes() {
        //加载背景并设置背景图片
        this.startBgTexture = await RES.getResAsync('prizeBg_jpg');
        return new Promise(function (resolve, reject) {
            resolve();
        });

    }

    protected onSkinComplete(): void {
        super.onSkinComplete();
        this.startBg.texture = this.startBgTexture;
        this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
        if (this.stage) {
            this.onLoad();
        }
    }

    private onLoad(): void {
        
        // console.log('屏幕',screen.width,screen.height)
        // if(screen.height/screen.width >= 2.22)
        // {
        //     this.startList.y = 140;
        // }
        if(GFun.isIOS){
            PanelCtrl.instance.show(ModuleTypes.IOSNO_PANEL);
        }
        console.log('微信唤起登录',window['loginlinkNoInApp']);
        console.log('端内唤起登录',window['loginlinkInApp']);
        this.initBuried();
        if(this.mData.baseinfo && this.mData.taskinfo && this.mData.pushstatus!=99){
            this.initUI();
            if(this.mData.baseinfo.collectStatus != 5){
                this.handleAccept();
            }
        }else{
            this.notLogin();
        }
    }

    notLogin(){
        for (let i = 0; i < 5; i++) {
            this["card" + (i + 1) + "di"].visible = false;
            this["card" + (i + 1) + "num"].visible = false;
            if (i + 1 == 1) {
                this["card" + (i + 1) + "img"].source = "cardpeach3_png";
            } else if (i + 1 == 2) {
                this["card" + (i + 1) + "img"].source = "cardfina3_png";
            } else if (i + 1 == 3) {
                this["card" + (i + 1) + "img"].source = "cardcase3_png";
            } else if (i + 1 == 4) {
                this["card" + (i + 1) + "img"].source = "cardhapp3_png";
            } else if (i + 1 == 5) {
                this["card" + (i + 1) + "img"].source = "cardheal3_png";
            }
        }
        this.jinimg.source = "cardlucky3_png"
        this.jindi.visible = false;
        this.jinnum.visible = false;
        this.cardBtn.visible = true;
        this.cardnum.visible = true;
            
        this.cardnum.text = "3";
        this.openBtn.visible = false;
        this.waitBtn.visible = false;
        this.hadopenBtn.visible = false;
        this.endgameBtn.visible = false;
        this.warnBtn.visible = true;
        this.warn2Btn.visible = false;
        let data = DataManager.ins.getData(NetName.OPPO_JOIN1_INDEX).code;
        if(data == "100001"){
            this.addEventListener(egret.TouchEvent.TOUCH_TAP,this.turnUrlLink,this)
        }else if(data == "100018"){
            this.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL,{msg:"账号异常，请重试~"})},this)
        }if (GFun.checkInApp(["oppocommunity"]) || GFun.getIsWxClient()) {
            
        } else {
            if(!GFun.isIOS){
                PanelCtrl.instance.show(ModuleTypes.NOTIPS_PANEL);
            }
            //this.removeEvents();
            //this.setEvents()
        }
        
        this.initTask();
    }
    private turnUrlLink(){
        if(GFun.getIsWxClient()){
            if(GFun.isIOS){
                window.location.href = window['ios'] + window['loginlinkNoInApp'];
            }else{
                window.location.href = window['android'] + window['loginlinkNoInApp'];
            }
        }
        if(/oppocommunity/i.test(navigator.userAgent)){
            window['RainbowBridge'] .callMethod("OPlusJSCommondMethod", "login", null, function(res) {
                if (res.status.code == 0) {
                    
                    window.location.href = window['loginlinkInApp'];
                }
            })
        }
    }
    initUI(): void {
        console.log('刷新1');
        OppoShareCtrl.instance.share();
        // this.removeEvents()
        // this.initEvents()
        for (let i = 1; i < 6; i++) {
            // this["func" + i] = this.showCard.bind(this, i, this.mData.baseinfo.cardList[i - 1].cardNum)
            this["card" + i + "Group"].removeEventListener(egret.TouchEvent.TOUCH_TAP, this["func" + i], this);

        }
        this.jinGroup.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.func6, this);

        for (let i = 1; i < 6; i++) {
            this["func" + i] = this.showCard.bind(this, i, this.mData.baseinfo.cardList[i - 1].cardNum)
            this["card" + i + "Group"].addEventListener(egret.TouchEvent.TOUCH_TAP, this["func" + i], this);

        }
        // if(screen.height/screen.width >= 2.22){
        //     this.startList.height = 1080 / window.innerWidth * window.innerHeight-140;
        // }else{
        //     this.startList.height = 1080 / window.innerWidth * window.innerHeight;
        // }
        this.startList.height = 1080 / window.innerWidth * window.innerHeight;
        //this.startList.height = 750 / window.innerWidth * window.innerHeight;

        this.func6 = this.showCard.bind(this, 6, this.mData.baseinfo.eggCardStatus)
        this.jinGroup.addEventListener(egret.TouchEvent.TOUCH_TAP, this.func6, this);

        if (GFun.getCookie("isNotLoginUser") == "true") {
            console.log("notlogin");
            this.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{this.turnUrlLink();},this)
        }


        if (this.mData.baseinfo) {
            // console.log("卡片信息")card1

            for (let i = 0; i < this.mData.baseinfo.cardList.length; i++) {
                this["card" + (i + 1) + "num"].text = this.mData.baseinfo.cardList[i].cardNum;
                if (this.mData.baseinfo.cardList[i].cardNum == 0) {
                    this["card" + (i + 1) + "di"].visible = false;
                    this["card" + (i + 1) + "num"].visible = false;
                    if (i + 1 == 1) {
                        this["card" + (i + 1) + "img"].source = "cardpeach3_png";
                    } else if (i + 1 == 2) {
                        this["card" + (i + 1) + "img"].source = "cardfina3_png";
                    } else if (i + 1 == 3) {
                        this["card" + (i + 1) + "img"].source = "cardcase3_png";
                    } else if (i + 1 == 4) {
                        this["card" + (i + 1) + "img"].source = "cardhapp3_png";
                    } else if (i + 1 == 5) {
                        this["card" + (i + 1) + "img"].source = "cardheal3_png";
                    }

                } else {
                    this["card" + (i + 1) + "di"].visible = true;
                    this["card" + (i + 1) + "num"].visible = true;
                    if (i + 1 == 1) {
                        this["card" + (i + 1) + "img"].source = "cardtao_png";
                    } else if (i + 1 == 2) {
                        this["card" + (i + 1) + "img"].source = "cardcai_png";
                    } else if (i + 1 == 3) {
                        this["card" + (i + 1) + "img"].source = "cardshi_png";
                    } else if (i + 1 == 4) {
                        this["card" + (i + 1) + "img"].source = "cardxing_png";
                    } else if (i + 1 == 5) {
                        this["card" + (i + 1) + "img"].source = "cardjian_png";
                    }
                }
            }
            if (this.mData.baseinfo.eggCardStatus == 1) {
                this.jinimg.source = "cardlucky3_png"
                this.jindi.visible = false;
                this.jinnum.visible = false;

            } else {
                this.jinnum.text = "1";
            }

        }
        if (this.mData.taskinfo && this.mData.taskinfo.rewardCount > 0) {
            PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: `新增${this.mData.taskinfo.rewardCount}次抽卡机会～` })
        }

        let iswx = 0;
        if (GFun.getIsWxClient()) {
            iswx = 2;
        } else {
            iswx = 1;
        }
        if (iswx == 2) {
            this.guanzhuBtn.visible = false;
        } else {
            this.guanzhuBtn.visible = false;
        }
        if (this.mData.baseinfo.collectStatus == 1) {
            this.cardBtn.visible = true;
            this.cardnum.visible = true;
            this.getcardExposure = GetBuriedData(1)
            NetManager.ins.showLog(this.getcardExposure);
            this.cardBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.getCard, this)
            this.cardnum.text = this.mData.baseinfo.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (this.mData.baseinfo.collectStatus == 2) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = this.mData.baseinfo.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = true;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (this.mData.baseinfo.collectStatus == 3) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = this.mData.baseinfo.remainTimes;
            this.openBtn.visible = true;
            this.openExposure = GetBuriedData(2)
            NetManager.ins.showLog(this.openExposure);
            this.openBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPrize, this)
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = false;
        } else if (this.mData.baseinfo.collectStatus == 4) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = this.mData.baseinfo.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = true;
            this.hadopenBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "已开奖，可于我的奖品中查看奖品详情～" }) }, this)
            this.endgameBtn.visible = false;
        } else if (this.mData.baseinfo.collectStatus == 5) {
            this.cardBtn.visible = false;
            this.cardnum.visible = false;
            // this.cardnum.text = this.mData.baseinfo.remainTimes;
            this.openBtn.visible = false;
            this.waitBtn.visible = false;
            this.hadopenBtn.visible = false;
            this.endgameBtn.visible = true;
            this.endgameBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "活动已结束" }) }, this)
            for (let i = 1; i < 6; i++) {
                this["card" + i + "Group"].removeEventListener(egret.TouchEvent.TOUCH_TAP, this["func" + i], this);
    
            }
            for (let i = 1; i < 6; i++) {
                this["card" + i + "Group"].addEventListener(egret.TouchEvent.TOUCH_TAP, () => { PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: "活动已结束" }) } , this);
    
            }
        }
        // let now = new Date()

        // if (now.getTime() > this.mData.baseinfo.eggCardStartTime) {
        //     NetManager.ins.getCard((success, result) => {
        //         if (!success) {
        //             return;
        //         }
        //         if (result.data == null) {
        //             return;
        //         }
        //         PanelCtrl.instance.show(ModuleTypes.GETCARD_PANEL, result.data);
        //     })
        // }
        if (this.mData.baseinfo.receiveEggCard) {
            let data = { prizeId: "egg_card" }
            PanelCtrl.instance.show(ModuleTypes.GETCARD_PANEL, data);
        }
        if (this.pushstatus == 0) {
            console.log("hree0")
            this.pushExposure = GetBuriedData(3)
            NetManager.ins.showLog(this.pushExposure);
            this.warnBtn.visible = true;
            this.warn2Btn.visible = false;
            this.warnBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);

        }else if(this.pushstatus == 99) {
            this.warnBtn.visible = true;
            this.warn2Btn.visible = false;
            this.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{this.turnUrlLink();},this)
        } else {
            console.log("hree2")
            this.closeExposure = GetBuriedData(4)
            NetManager.ins.showLog(this.closeExposure);
            this.warnBtn.visible = false;
            this.warn2Btn.visible = true;
            this.warn2Btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
        }

        this.initTask()

        if (GFun.checkInApp(["oppocommunity"]) || GFun.getIsWxClient()) {
        } else {
            if(!GFun.isIOS){
                console.log(GFun.isIOS);
                PanelCtrl.instance.show(ModuleTypes.NOTIPS_PANEL);
            }
            
            //this.removeEvents();
            //this.setEvents()
        }
    }

    initTask() {
        let taskRenderer = new TaskRenderer()
        this.taskGroup.addChild(taskRenderer)
        this.taskGroup.height = taskRenderer.height
        this.height += (this.taskGroup.height - 500)
        let setHeight = 500;
        // if(screen.height/screen.width >= 2.22){
        //     setHeight = 700;
        // }
        
        if (this.diheight < this.startGroup.height + setHeight) {
            this.diheight = this.startGroup.height + setHeight;
            if(setHeight == 700){
                this.startGroup.height = 4955;
            }
        }
        //this.startBg.height = this.diheight
        this.diGroup.y = this.diheight - setHeight
        if (DataManager.ins.getData(NetName.OPPO_QUERYTASKLIST) && DataManager.ins.getData(NetName.OPPO_QUERYTASKLIST).data && DataManager.ins.getData(NetName.OPPO_QUERYTASKLIST).data.length > 1) {
            this.diGroup.y = this.diheight - setHeight
        }

        let iswx = 0;
        if (GFun.getIsWxClient()) {
            iswx = 2;
        } else {
            iswx = 1;
        }
        if(iswx == 1){
            // this.diimg.visible = true;
            // this.warnBtn.visible = true;
            // this.warn2Btn.visible = true;
        }else{
            this.diimg.visible = false;
            this.warnBtn.visible = false;
            this.warn2Btn.visible = false;
        }
    }

    private handleAccept() {
        let shareCode = GFun.getQueryString('shareCode');
        //console.log('分享shareCode',shareCode);
        if (shareCode) {
            NetManager.ins.acceptPopup((success, result) => {
                console.log('后端返回',success,result);
                if (!result) {
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '网络异常，请重试~' });
                    return;
                }
                if (success) {
                    PanelCtrl.instance.show(ModuleTypes.ACCEPT_PANEL, {acceptResult:true,content: "点击帮好友助力，\n可为好友增加 1 次集卡机会，\n快去助力吧~",shareCode:shareCode});
                }else{
                    if(result.code == '100014'){
                        PanelCtrl.instance.show(ModuleTypes.ACCEPT_PANEL, {acceptResult:false, content: "不能给自己助力哦，\n快去集稳卡吧～"});
                    }
                    else{
                        PanelCtrl.instance.show(ModuleTypes.ACCEPT_PANEL, {acceptResult:false, content: "助力失败啦，\n快让好友重新分享助力吧～"});
                    }
                }
            }, shareCode)
        }
    }
    private showCard(num, cardnum) {
        console.log(num);
        console.log(cardnum);
        let data = { cardid: num, cardnum: cardnum };
        PanelCtrl.instance.show(ModuleTypes.CARD_PANEL, data);
        // if (num == 6 && cardnum == 1) {
        //     let now = new Date();
        //     if (now.getDate() > 16 && now.getDate() < 19) {
        //         PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: `锦鲤卡将于1月${now.getDate()}日10：00开始发放，\n先到先得，记得来哦~` })
        //     } else if (now.getDate() < 17) {
        //         PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: `锦鲤卡将于1月17日10：00开始发放，\n先到先得，记得来哦~` })
        //     } else {
        //         PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: `抱歉！锦鲤稳卡已经发完啦！快去集齐另外5张稳卡，兑换现金红包吧！` })
        //     }

        // }//else{

        //}

    }

    private getCard() {
        NetManager.ins.clickLog(this.getcardExposure)
        PanelCtrl.instance.btnDelay(this.cardBtn);
        let data = DataManager.ins.getData(NetName.OPPO_JOIN1_INDEX).data;
        if (data.remainTimes == 0) {
            PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '当前没有抽卡机会啦，快去获取更多抽卡机会吧~' });
        } else {
            Loading.instace.show()
            NetManager.ins.getCard((success, result) => {
                Loading.instace.hide();
                if (!success) {
                    PanelCtrl.instance.show(ModuleTypes.NOPRIZE_PANEL);
                    return;
                }
                if (result.data == null) {
                    PanelCtrl.instance.show(ModuleTypes.NOPRIZE_PANEL);
                    return;
                }
                PanelCtrl.instance.show(ModuleTypes.GETCARD_PANEL, result.data);
            })

        }

    }

    private openPrize() {
        console.log("开奖")
        PanelCtrl.instance.btnDelay(this.openBtn);
        NetManager.ins.clickLog(this.openExposure)
        if (GFun.getIsWxClient()) {
            NetManager.ins.saveOpenId((success, result) => {
                if (!success) {
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '该微信账号已绑定过OPPO+账号啦，\n一个微信号只能绑定一个OPPO+账号哦，\n换回之前的OPPO+账号去领取红包吧～' });
                    return
                }
                NetManager.ins.getPrize((success2, result2) => {
                    if (!success2) {
                        PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '网络异常，请重试~' });
                        return
                    }
                    if (result2.data) {
                        let data = { prizedata: result2.data, type: 1 }
                        PanelCtrl.instance.show(ModuleTypes.REDLUCKY_PANEL, data);
                    }



                }, "1", "2")
            })
        } else {
            NetManager.ins.getPrize((success, result) => {
                if (!success) {
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '网络异常，请重试~' });
                    return
                }
                let data = { prizedata: result.data, type: 1 }
                PanelCtrl.instance.show(ModuleTypes.REDLUCKY_PANEL, data);

            }, "1", "1")
        }
    }

    private onTap_prizeBtn(): void {
        console.log('点击prizeBtn');
        NetManager.ins.clickLog(this.prizeExposure);
        PanelCtrl.instance.btnDelay(this.prizeBtn);
        PanelCtrl.instance.show(ModuleTypes.PRIZE_PANEL);
        //window.location.href = this.gotoRecord();
    }
    private onTap_ruleBtn(): void {
        NetManager.ins.clickLog(this.ruleExposure)
        PanelCtrl.instance.btnDelay(this.ruleBtn);
        PanelCtrl.instance.show(ModuleTypes.RULE_PANEL);
    }

    private openPush() {
        NetManager.ins.clickLog(this.pushExposure)
        this.closeExposure = GetBuriedData(4)
        NetManager.ins.showLog(this.closeExposure);
        NetManager.ins.subscibeNotice((success, result) => {
            if (!success) {
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '网络异常，请重试~' });
                return
            }
            PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '任务提醒设置成功' });
            this.pushstatus = 1;
            this.warn2Btn.visible = true;
            this.warnBtn.visible = false;
            this.warnBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
            this.warn2Btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
        }, 1)
    }

    private closePush() {
        NetManager.ins.clickLog(this.closeExposure);
        this.pushExposure = GetBuriedData(3)
        NetManager.ins.showLog(this.pushExposure);
        NetManager.ins.subscibeNotice((success, result) => {
            if (!success) {
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '网络异常，请重试~' });
                return
            }
            PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: '任务提醒已关闭' });
            this.pushstatus = 0;
            this.warn2Btn.visible = false;
            this.warnBtn.visible = true;
            this.warn2Btn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closePush, this);
            this.warnBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.openPush, this);
        }, 0)
    }

    private guanzhu() {
        window.location.href = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MjM5MDAyMDMwMA==&scene=124#wechat_redirect"
    }

    //循环播放动画
    private playAnimation(target: egret.tween.TweenGroup, isLoop: boolean = true): void {
        if (isLoop) {
            for (var key in target.items) {
                target.items[key].props = { loop: true };
            }
        }
        target.play();
    }


}
