
// var Global = require("Global");
cc.Class({
    extends: cc.Component,

    properties: {
        game_main: {
            default: null,
            type: cc.Node,
        },
        game_rule: {
            default: null,
            type: cc.Node,
        },
        game_start: {
            default: null,
            type: cc.Node,
        },
        set_main: {
            default: null,
            type: cc.Node,
        },
        dollar: {
            default: null,
            type: cc.Node,
        },
        qiandao: {
            default: null,
            type: cc.Node,
        },
        gongzhonghao: {
            default: null,
            type: cc.Node,
        },
        rank_main:cc.Node,
        rankingView:cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        var self =this;
        // if(cc.sys.localStorage.getItem("node_msg_arr")){
        //     cc.loader.loadRes("images/jixuyouxi",cc.SpriteFrame,function (err, spriteFrame) {
        //         if (err) {
        //             cc.error(err.message || err);
        //             return;
        //         }
        //         // console.log(self.game_start.getChildByName("kaishianniu").name);
        //         self.game_start.getChildByName("kaishianniu").getComponent(cc.Sprite).spriteFrame = spriteFrame;
        //     })
        // }

        if(game_msg.node_msg_arr.length>1){
            cc.loader.loadRes("images/jixuyouxi",cc.SpriteFrame,function (err, spriteFrame) {
                if (err) {
                    cc.error(err.message || err);
                    return;
                }
                // console.log(self.game_start.getChildByName("kaishianniu").name);
                self.game_start.getChildByName("kaishianniu").getComponent(cc.Sprite).spriteFrame = spriteFrame;
            })
        }
        
    
    },

    start () {

    },
    gameStartReq: function(){
        var mydata = {"a":"init_game","m":"init","d":{'act':'init'}};
        // console.log('qqqqqqqqqqq',cc.HQ.PlayerMgr.info);
        cc.HQ.net.packAjaxSend(cc.HQ.Global.game_url,mydata,"POST");
    },
    
    start_click_fn(){
        this.game_start.active = false;
        this.game_main.active = true;
        this.dollar.destroy();
        // cc.HQ.WechatApi.ClubButton.hide();
        var play = cc.sys.localStorage.getItem("isplay");
        // console.log("play",play);
        if(play == "1"){

        }else{
            this.game_rule.active = true;
        }
        // if(game_msg.node_msg_arr.length>1){
        //     game_msg.danger_tip = false;
        // }else{
            game_msg.danger_tip = true;
        // }
        //游戏开始请求服务器
        // this.gameStartReq();
    },
    rule_click_fn(){
        var self = this;
        self.scheduleOnce(function(){
            self.game_rule.active = false;
            self.game_main.active = true;
        },2)
        return false;
    },
    rule_open_fn(){
        // this.game_main.active = false;
        this.game_rule.active = true;
    },
    set_show_fn(){
        this.set_main.active = true;
        return false;
    },
    set_close_fn(){
        this.set_main.active = false;
        return false;
    },
    qiandao_open(){
        var self = this;
        sdk.Post(sdk.ip2+"/Sign/check",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token},function(data){
            self.qiandao.active = true;
            // console.log(data,"wwwwwwwwwwwwwwwwwwwwwwwwwww");
            var signDay = data.d.signDay;
            if(data.d.signStatus == 0){
                self.qiandao.active = true;
            }else{
                self.qiandao.getChildByName("lingqu").getComponent(cc.Button).interactable = false;
                self.qiandao.getChildByName("day_7").children[signDay].getChildByName("ts_kuang").getChildByName("mask").active = true;
                // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
                cc.loader.loadRes("images/lingqu_huise",cc.SpriteFrame,function (err, spriteFrame) {
                    if (err) {
                        cc.error(err.message || err);
                        return;
                    }
                    self.qiandao.getChildByName("lingqu").getComponent(cc.Sprite).spriteFrame = spriteFrame;
                });
            }
            for(let i = 0;i<signDay;i++){
                self.qiandao.getChildByName("day_7").children[i].getChildByName("ts_kuang").getChildByName("mask").active = true;
            }
            // self.qiandao.getChildByName("day_7").children[signDay].getChildByName("ts_kuang").getChildByName("today").active = true;
            // var Sprite = self.qiandao.getChildByName("day_7").children[signDay].getChildByName("ts_kuang").getChildByName("jl_pic").getComponent(cc.Sprite).spriteFrame;
            // var label = self.qiandao.getChildByName("day_7").children[signDay].getChildByName("ts_kuang").getChildByName("jl_text").getComponent(cc.Label).string;
            // self.qiandao.getChildByName("qiandao_tc").getChildByName("jiangli").getComponent(cc.Sprite).spriteFrame = Sprite;
            // self.qiandao.getChildByName("qiandao_tc").getChildByName("jiangli_Label").getComponent(cc.Label).string = label;
        });
    },
    qiandao_close(){
        this.qiandao.active = false;
    },
    qiandao_tc(){
        this.qiandao.getChildByName("qiandao_tc").active = true;
    },
    qiandao_tc_close(){
        var self = this;
        sdk.Post(sdk.ip2+"/Sign/userSign",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"double_reward":2},function(data){
            console.log(data);
            self.qiandao.active = false;
            self.qiandao.getChildByName("qiandao_tc").active = false;
        })
    },
    qiandao_tc_double(){
        var self =this;
        sdk.shareAppMessage({type: 1, query: "" , success:function(){
            // console.log("分享成功");
            sdk.Post(sdk.ip2+"/Sign/userSign",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"double_reward":1},function(data){
                console.log(data);
                self.qiandao.active = false;
                self.qiandao.getChildByName("qiandao_tc").active = false;
            })
        }});
    },
    gongzhonghao_open(){
        this.gongzhonghao.active = true;
    },
    gongzhonghao_close(){
        this.gongzhonghao.active = false;
    },
    onShare2: function(){
        sdk.shareAppMessage({type: 2 });
    },
    //分享按钮
    onShare: function(){
        sdk.shareAppMessage({type: 1 });
        // //设置分享的值
        // cc.HQ.WechatApi.setShareInfo("",cc.HQ.WechatApi.shareInfoData.fs);
        // //处理分享
        // cc.HQ.WechatApi.shareAppMessage();

        //  //设置分享的值
        //  cc.HQ.WechatApi.setShareInfo(cc.HQ.WechatApi.NORMAL,cc.HQ.WechatApi.shareInfoData.bs);
        //  cc.HQ.WechatApi.shareAppMessage(function(res){
        //      console.log('分享成功',res);
        //      if(res.shareTickets){
        //         //  this._shareState =true;
        //          //分享后可以继续游戏了
        //         //  this.node.active =false;
        //      }else{
        //         //  console.log("分享给个人不给续命");
        //         //  this._shareState =false;      
        //      }
        //  }.bind(this),function(res){
        //      console.log('分享失败');
        //     //  this._shareState =false; 
        //  }.bind(this),function(){
        //      console.log('分享完成');
        //  }.bind(this))

        // sdk.shareAppMessage({type: 1, query: "" , success:function(){
        //     console.log("分享成功");
        // }});

        // sdk_out.shareAppMessage({
        //     title: '不要怂，全梭哈！赢了会所嫩模，输了下海干活！',
        //     query: 'shareConfigId=xxx',
        //     imageUrl: "https://res.g.llewan.com/uploadfile/houtai/share/20180930/20180930120435_2671.png",
        //     success: (res) => {
        //         console.log('分享成功！', res)
        //     }
        // });
    },

    //排行榜按钮
    onRank: function(){
        // // cc.HQ.WechatApi.ClubButton.hide();

        // this._isShowRank = !this._isShowRank;  //(this._isShowRank为true时显示排行榜)
        // this.rank_main.active = this._isShowRank;   //显示排行榜
        // this.rankingView.active = this._isShowRank;   //显示排行榜
        // if(this._isShowRank){
        //     this.onRankReq(1,0);
        // }

        this.rank_main.active = true;   //显示排行榜
        this.rankingView.active = true;
        this.onRankReq(1,0);
        banner_show(true);
        // this.bannerAd.hide();

        // var bannerAd = sdk_out.createBannerAd({
        //     adUnitId:  'adunit-79dab17cc25addbd',
        //     style: {
        //         left: self.w-150,
        //         top: self.h-10,
        //         width: 300
        //     },
        //     success: function(banner) {
        //         bannerAd.style.left = self.w - bannerAd.style.realWidth/2+0.1;
        //         bannerAd.style.top = self.h - bannerAd.style.realHeight+0.1;
        //         bannerAd.hide();
        //         console.log("bbbbbbbbbbbb",banner);
        //     },
        // })
    },
    // 排行榜返回
    rank_back_btn(){
        // var d = sdk.getConfig1();
        // if(d.sns == 1){cc.HQ.WechatApi.ClubButton.show();}
        this.rank_main.active = false;
        this.rankingView.active = false;
        // this.bannerAd.show();
        banner_show();
    },

    //排行榜的主域向子域发送请求
    onRankReq: function(n,score){
        //好友排行榜
        var mydata = {
            type:'FriendCloud',
            data:'',
            key:['score'],
            num:n,
            curScore:score
        };
        send_data_to_sub(mydata);
        // console.log("cc.HQ.PlayerMgr.info.openid--------->" +cc.HQ.PlayerMgr.info.openid);
        //我的数据
        var mydata1 ={
            type:'UserCloud',
            data:'',
            key:['score'],
            openid:game_msg.openid,
        };
        send_data_to_sub(mydata1);
        
    },

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