var tmpl=`
  <div>
  </div>
`
module.exports=
`{
   template:'${tmpl}',
   props:[],
   data:function(){
     return {
       client:null,
       prevDisconnect:false,
     };
   },
   methods:{
     socketReplyReq:function(msg,cbk){
        this.client.emit("replymsg",msg,function(rtnData){
          cbk(rtnData);
        });
     },
     chatReq:function(msg){
       this.client.emit("chatmsg",msg);
     },
     initSocketClient(){
       var self=this;
       this.client = io(location.href);
       this.client.on('connect', function(){
         console.log("connect..................................");
         if(self.prevDisconnect && self.currentUser){
            console.log("relogin");
            self.client.emit("login",self.currentUser);
            self.prevDisconnect=false;
         }
       });
       this.client.on('disconnect', function(){
         console.log("dis connect...............................");
         self.prevDisconnect=true;
       });
       this.client.on("chatmsg",function(msg){
         console.log("recv msg");
         console.log("recv msg:"+msg);
         if(self.$store.state.currentCodePath.indexOf("msgs")<0 && !msg.type){
             var arry= msg.from.split("￥");
             var nickname=arry[2];
             var inner=self;
             self.$notify({
               title: '平台通知',
               dangerouslyUseHTMLString: true,
               message: '<a href="#">'+nickname+"刚刚给您发送了消息..."+"</a>",
               position: 'bottom-right',
               onClick:function(){
                 inner.$router.push("/uc/msgs");
                 /*当点击时进入聊天页面后，按照to进入对应的来源聊天*/
                 inner.$store.state.currentChatTo.to=msg.from;
               },
             });
         }
         if(msg.type && msg.type=="system"){
             self.$notify({
               title: '平台通知',
               dangerouslyUseHTMLString: true,
               message:msg.content,
               position: 'bottom-right',
               onClick:function(){

               },
             });
         }else{
           self.$emit("chatmsg",msg);
         }
       });
       this.client.on("brc",function(msg){
         console.log("xxxxxxxxxxxxxxxxxxuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu");
         console.log(JSON.stringify(msg));
         if(msg.type=="online"){
           self.$emit("onlinechange",msg.content);

         }
         /*self.$notify({
           title: '平台通知',
           message: msg,
           position: 'bottom-right'
         });*/
       });
       this.$store.state.socketClient=this;

     }
   },
   watch:{
     currentUser:function(n,o){
       console.log("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnCurrrent USer......");
       console.log(n);
       if(n){
          this.client.emit("login",n);
       }
     }
   },
   created:function(){

   },
   vname:"gsb-socketclient"
}`
