{
    template:'${tmpl}',
    data:function(){
        return {
          headers: [
            {},
            {},
            {},
          ],
          activeName: 'first',
          onlines:[],
          currentTo:"",
          msgs:[
          ],
          caches:{},
          content:"",
        }
    },
    mounted:function(){
      this.$nextTick(()=>{
        this.fetchData();
      });
      if(this.$store.state.currentChatTo!=""){
        this.currentTo=this.$store.state.currentChatTo;
        var arry= this.currentTo.to.split("￥");
        var k="#"+arry[0]+"_"+arry[1];
        console.log(k);
        setTimeout(()=>{
          $(k).click();
        },500);

      }
    },
    created:function(){
      console.log(this.currentCodePath);
      this.socketClient.$on("chatmsg",msg=>{
        /*
        全局缓存当前目标聊天对象,当进入组件时，按照目标，trigger相应的对话

        如果当前打开了伙伴在线，但当前组件目标客户与消息来源目标不相同，那么显示新消息图标,在应用栏显示图标
        如果当前没有打开伙伴在线，那么右下角显示提示，加链接，点击进入伙伴在线
        */
        /*
        当前打开了伙伴在线，如果当前组件的目标客户与消息的来源相同，
        那么直接增加缓存，增加消息
        */
        var arrs=msg.from.split("￥");
        var tmp={imgurl:arrs[3],content:msg.content,left:true};
        if(this.currentTo.to==msg.from){
          this.caches[this.currentTo.to].push(tmp);
          this.msgs.push(tmp);
          this.$nextTick(()=>{
            $("#idcontent").scrollTop($("#idcontent")[0].scrollHeight);
          });
        }else{
          this.onlines.forEach(r=>{
            if(r.to==msg.from){
              r.newmsg=true;
              /*如果面板打开，非当前对话，有对过话*/
              if(this.caches[msg.from]){
                this.caches[msg.from].push(tmp);
              }
            }
          });
        }

      });
    },
    methods:{
      funcStyle:function (m) {
         return{
           "padding-left":"10px",
           "padding-right":"10px",
           "margin-top":"15px",
         };
      },
      searchEnter:function(){

      },
      selclick:function(item){
        var self=this;
        this.currentTo=item;
        item.newmsg=false;
        this.$store.state.currentChatTo=this.currentTo;
        if(!this.caches[this.currentTo.to]){
            this.caches[this.currentTo.to]=[];
            this.msgs=[];
            var uk=this.currentUser.appid+"￥"+this.currentUser.id+"￥"+
                 this.currentUser.nickName+"￥"+this.currentUser.imgUrl;
            var q={};
            q.pageInfo={pageSize:20,pageNo:1};
            q.search={};
            q.extra=this.currentTo.to;
            this.$root.postReq("/web/msghistoryCtl/findAndCountAll",q).then(d=>{
              d.data.rows.reverse().forEach(r=>{
                var tmp=null;
                if(r.sender==uk){
                  tmp={imgurl:this.currentUser.imgUrl,content:r.content,left:false};
                }else{
                  var arrs=r.sender.split("￥");
                  tmp={imgurl:arrs[3],content:r.content,left:true};
                }
                self.msgs.push(tmp);
                self.caches[this.currentTo.to].push(tmp);
              });
              /*滚动到底部*/
              this.$nextTick(()=>{
                $("#idcontent").scrollTop($("#idcontent")[0].scrollHeight);
              });
            });
        }else{
            this.msgs=[];
            this.caches[this.currentTo.to].forEach(r=>{
              this.msgs.push(r);
            });
            /*滚动到底部*/
            this.$nextTick(()=>{
              $("#idcontent").scrollTop($("#idcontent")[0].scrollHeight);
            });
        }

      },
      onsend:function(){
        if(this.currentTo!=""){
          var uk=this.currentUser.appid+"￥"+this.currentUser.id+"￥"+
               this.currentUser.nickName+"￥"+this.currentUser.imgUrl;
          var msg={
            from:uk,
            to:this.currentTo.to,
            content:this.content,
          };
          this.socketClient.chatReq(msg);
          var tmp={imgurl:this.currentUser.imgUrl,content:this.content,left:false};
          this.caches[this.currentTo.to].push(tmp);
          this.msgs.push(tmp);
          this.content="";
          this.$nextTick(()=>{
            $("#idcontent").scrollTop($("#idcontent")[0].scrollHeight);
          });
        }
      },
      handleClick:function(t,e){
        console.log(t.name);
      },
      fetchData:function(){
        var self=this;
         this.$root.postReq("/web/cacheCtl/findOnlines",{}).then(d=>{
           d.data.forEach(r=>{
             var arry= r.split("￥");
             var k=arry[0]+"￥"+arry[1];
             var idkey=arry[0]+"_"+arry[1];
             var tmp={uk:k,name:arry[2],imgurl:arry[3],to:r,key:idkey,newmsg:false};
             self.onlines.push(tmp);
           });
           this.$nextTick(()=>{
             $("#idcontent").scrollTop($("#idcontent")[0].scrollHeight);
           });
         });
      },
    },
    computed:{
    },
    vname:"gsb-msgs"
}
