{
    template:'${tmpl}',
    data:function(){
        return {
          multipleSelection: [],
          isSingleSelect:false,
          treedata:[],
          defaultProps:{
            children: 'children',
            label: 'label'
          },
          currentRole:null,
          authshow:false,
        }
    },
    mounted:function(){
      this.$root.getReq("/web/metaCtl/getRsConfig",null).then(cfg=>{
         if(cfg){
           this.rsData=[];
           cfg.data.children.forEach(r=>{
             this.treedata.push(r);
           })
         }
         console.log("xgggggggggggggggggggggggggggggggggggg");
         console.log(JSON.stringify(this.treedata));
      });
    },
    created:function(){
    },
    methods:{
      authcancel(){
        this.authshow=false;
      },
      authsave(){
       var self=this;
       var auths=[];
       this.treedata.forEach((r)=>{
         var tfunc=function(x){
           if(x.children && x.children.length>0){
             x.children.forEach(t=>{
               tfunc(t);
             })
           }else{
             if(x.bizCode){
               var authstrs=x.auths.join(",");
               var codestr=x.code;
               var codepathstr=x.codePath;
               var rolestr=self.currentRole.code;
               var tmpauthObj={
                 rolecode:rolestr,
                 bizcode:codestr,
                 codepath:codepathstr,
                 authstrs:authstrs,
               };
               auths.push(tmpauthObj);
             }
           }
         };
         tfunc(r);

       });
       this.$root.showMask();
       this.$root.postReq("/web/authCtl/saveAuths",{aus:auths}).then(d=>{
         if(d.status==0){
             self.$root.hideMask();
             self.$message({
               type: 'success',
               message: '给角色'+self.currentRole.name+'授权成功!'
             });
             this.authshow=false;
         }

       });
      },
      rowclicktest:function(r,k){
        var self=this;
        this.currentRole=r;
        this.authshow=true;
        /*初始化授权信息*/
        this.$root.postReq("/web/authCtl/findAuthsByRole",{rolecode:[this.currentRole.code]}).then(d=>{
         if(d.status==0){
           var kdic={};
           d.data.forEach(n=>{
             /*注意auth表里存储的bizcode是code*/
             kdic[n.bizcode]=n.authstrs;
           });
           self.treedata.forEach((r)=>{
             var tfunc=function(x){
               if(x.children && x.children.length>0){
                 x.children.forEach(t=>{
                   tfunc(t);
                 })
               }else{
                 if(x.bizCode){
                    x.auths.splice(0,x.auths.length);
                    /*注意是code*/
                    if(kdic[x.code]){
                      var tattray=kdic[x.code].split(",");
                      tattray.forEach(m=>{
                        x.auths.push(m);
                      });
                    }
                 }
               }
             };
             tfunc(r);

           });

         }
        });

      },
      handleNodeClick(data){
        console.log(JSON.stringify(data));
        setTimeout(()=>{
          console.log(JSON.stringify(data.auths));
        },100);
      },
      onColFormater(row,column,cellvalue,index){
        console.log(column.property);
        if(column.property=="code" && !row.products){
          var tmp=[];
          var ids=[];
          row["Products"].forEach(s=>{
            tmp.push(s.name);
            ids.push(s.id);
          });
          row.products=ids;
        }
        return cellvalue;
      },
      handleSelectionChange:function(val){
         this.multipleSelection = val;
         console.log(val);
      }
    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      }
    }),
    vname:"gsb-roles"
}
