
cc.Class({
    extends: cc.Component,

    properties: {
        leave_node: cc.Node,
        online_main: cc.Node,
        online_already: cc.Node,
        goldStacksTipsUI: cc.Node,  //领取奖励节点
        //公告的节点
        noticeNode: cc.Node,
        labRichText: cc.RichText,
        tishitubiao: cc.Node,
        videoIcon1: cc.Node,  //看视频图标1
        videoIcon2: cc.Node,  //看视频图标2
        _notice: null,  //公告显示内容
        _type: null,  //显不显示公告内容
        _sysid: null,  //公告id
    },

    // LIFE-CYCLE CALLBACKS:

    init: function(data,sysid,type){
        this._notice =data;
        this._type =type;
        this._sysid =sysid;
        console.log("公告内容",this._notice,this._type);
        this.labRichText.string =this._notice;
        if(this._type){
            //显示公告节点
            this.noticeNode.active =true;
            //关闭小红点
            this.tishitubiao.active =false;
            cc.HQ.GameMgr.setNotice(String(this._sysid),String(this._sysid));
        }
    },

    onEnable: function(){
        //收益翻倍，点我翻倍按钮上，要不要显示视频图片
        let state =cc.HQ.GameMgr.onShareVideoState(sdk.getConfig2().model.v6);
        if(state){
            this.videoIcon1.active =true;
            this.videoIcon2.active =true;
        }else{
            this.videoIcon1.active =false;
            this.videoIcon2.active =false;
        }
    },
    
    //关闭
    onClose:function(){
        var self = this;
        if(this.leave_node.active == true){
            // 关闭时给用户加金币
            console.log(" 关闭时给用户加金币");
            sdk.getServerTime(function(d){
                sdk.setToServer("UserLeave","UserLeave",d.nowTime,-1);
            });
            let tempGold =self.leave_node.getChildByName("green_box").getChildByName("much").getComponent(cc.Label).string;
            self.goldStacksTipsUI.getComponent("goldStacksTipsUI").init(self._data,3,Number(tempGold));
            self.goldStacksTipsUI.active =true;
        }
        this.node.active = false;
        this.leave_node.active =false;
        //埋点
        // sdk.setSceneEvent("果汁店","点击","收取按钮",{},null);
    },

    //当前收益翻倍
    onDoubleShouyi:function(){ 
        //分享或视频模式
        cc.HQ.GameMgr.shareOrVideo(sdk.getConfig2().model.v6,this.onVideo,this.onShare,1);
        //埋点
        // sdk.setSceneEvent("果汁店","点击","收益翻倍按钮",{},null);
    },

    //点我离线翻倍
    onDianwo:function(){
        //分享或视频模式
        cc.HQ.GameMgr.shareOrVideo(sdk.getConfig2().model.v7,this.onVideo1,this.onShare1,1);
        //埋点
        // sdk.setSceneEvent("果汁店","点击","点我翻倍按钮",{},null);
    },

    //公告按钮
    onNotice: function(){
        if(this.noticeNode.active){
            return;
        }else{
            if(!this._notice){  //公告内容为空时,提示暂无公告！
                cc.HQ.Global.showTips(2,"暂无公告!",0.3);
            }else{
                //显示公告节点
                this.noticeNode.active =true;    
            }   
        }

        // sdk.Post(sdk.ip2+ sdk.notice,{},function(data){
        //     console.log("公告返回",data);
        //     if(data.c ==1){
        //         self.labRichText.string =data.d.content;
        //         //显示公告节点
        //         self.noticeNode.active =true;
        //         //关闭小红点
        //         self.tishitubiao.active =false;
        //         self.tishitubiao1.active =false;
        //     }else{
        //         cc.HQ.Global.showTips(2,"暂无公告!",0.3);
        //     }
        // });
    },

    //公告关闭按钮
    onNoticeClose: function(){
        console.log("关闭");
        //关闭公告节点
        this.noticeNode.active =false;  
    },

    //调视频
    onVideo: function(data,type,isValue){
        sdk.videoSuccess = function(){
            //视频成功处理逻辑
            var guozhidianJS =cc.find("Canvas").getChildByName("guozhidianUI").getComponent("guozhidianUI");
            //收益翻倍
            guozhidianJS.node.active = false;
            guozhidianJS.leave_node.active =false;
            let tempGold =guozhidianJS.leave_node.getChildByName("yellow_box").getChildByName("much").getComponent(cc.Label).string;
            guozhidianJS.goldStacksTipsUI.getComponent("goldStacksTipsUI").init(guozhidianJS._data,3,Number(tempGold));
            guozhidianJS.goldStacksTipsUI.active =true;
            console.log("视频收益翻倍",guozhidianJS.leave_node);
            sdk.getServerTime(function(d){
                sdk.setToServer("UserLeave","UserLeave",d.nowTime,-1);
            });
            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                guozhidianJS.videoIcon1.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                guozhidianJS.videoIcon1.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                guozhidianJS.videoIcon1.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                guozhidianJS.videoIcon1.active =false;
            }
            sdk.setToServer("VideoOrShareKey1","VideoOrShareData1",data,86400);
        }.bind(this);
        sdk.videoFail = function(){
            //视频失败处理逻辑
            console.log("视频未看完");
        };
        var videoAd = sdk.createRewardedVideoAd(sdk.getConfig2().videoIdArr[0]);
        videoAd.load().then(() => videoAd.show());
    },

    onShare: function(data,type,isValue){
        
        sdk.shareAppMessage({type:8,query:""});
        let shareFun6 = ()=>{
            console.log("老子响应的是离线收益");
            var guozhidianJS =cc.find("Canvas").getChildByName("guozhidianUI").getComponent("guozhidianUI");
            //收益翻倍
            guozhidianJS.node.active = false;
            guozhidianJS.leave_node.active =false;
            let tempGold =guozhidianJS.leave_node.getChildByName("yellow_box").getChildByName("much").getComponent(cc.Label).string;
            guozhidianJS.goldStacksTipsUI.getComponent("goldStacksTipsUI").init(guozhidianJS._data,3,Number(tempGold));
            guozhidianJS.goldStacksTipsUI.active =true;
            
            sdk.getServerTime(function(d){
                sdk.setToServer("UserLeave","UserLeave",d.nowTime,-1);
                console.log("设置离线时间成功");
                
            });
            console.log("分享收益翻倍");

            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                guozhidianJS.videoIcon1.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                guozhidianJS.videoIcon1.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                guozhidianJS.videoIcon1.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                guozhidianJS.videoIcon1.active =false;
            }
            sdk.setToServer("VideoOrShareKey1","VideoOrShareData1",data,86400);
        }
        cc.HQ.GameMgr.clickShare =true;
        cc.HQ.GameMgr.shareNum4++;
        cc.HQ.GameMgr.onSimulateShareBack(shareFun6,4);
    },

    //调视频
    onVideo1: function(data,type,isValue){
        sdk.videoSuccess = function(){
            //视频成功处理逻辑
            var guozhidianJS =cc.find("Canvas").getChildByName("guozhidianUI").getComponent("guozhidianUI");
            guozhidianJS.online_already.active = true;
            guozhidianJS.online_already.getChildByName("rest_time").getComponent(cc.Label).string = "12小时内有效";
            guozhidianJS.online_main.active = false;
            // guozhidianJS.node.getChildByName("spine").active = true;
            sdk.getServerTime(function(d){
                var timer = Number(d.nowTime)+43300;//给多一点时间100
                sdk.setToServer("DoubleTime","DoubleTime",timer,-1);
            })
            
            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                guozhidianJS.videoIcon2.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                guozhidianJS.videoIcon2.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                guozhidianJS.videoIcon2.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                guozhidianJS.videoIcon2.active =false;
            }
            sdk.setToServer("VideoOrShareKey1","VideoOrShareData1",data,86400);
        }.bind(this);
        sdk.videoFail = function(){
            //视频失败处理逻辑
            console.log("视频未看完");
        };
        var videoAd = sdk.createRewardedVideoAd(sdk.getConfig2().videoIdArr[0]);
        videoAd.load().then(() => videoAd.show());
    },

    onShare1: function(data,type,isValue){
        
        sdk.shareAppMessage({type:9,query:""});
        let shareFun7 = ()=>{
            console.log("老子响应的是离线收益");
            var guozhidianJS =cc.find("Canvas").getChildByName("guozhidianUI").getComponent("guozhidianUI");
            sdk.getServerTime(function(d){
                var timer = Number(d.nowTime)+43300;//给多一点时间100
                sdk.setToServer("DoubleTime","DoubleTime",timer,-1);
            })
            guozhidianJS.online_already.active = true;
            guozhidianJS.online_already.getChildByName("rest_time").getComponent(cc.Label).string = "12小时内有效";
            guozhidianJS.online_main.active = false;
            // guozhidianJS.node.getChildByName("spine").active = true;
            
            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                guozhidianJS.videoIcon2.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                guozhidianJS.videoIcon2.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                guozhidianJS.videoIcon2.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                guozhidianJS.videoIcon2.active =false;
            }
            sdk.setToServer("VideoOrShareKey1","VideoOrShareData1",data,86400);
        }
        cc.HQ.GameMgr.clickShare =true;
        cc.HQ.GameMgr.shareNum5++;
        cc.HQ.GameMgr.onSimulateShareBack(shareFun7,5);
    },
    

    // update (dt) {},
});
