{
    template:'${tmpl}',
    data:function(){
         var self=this; 
          var validmethod2=async function (rule,value,callback) {
            if(rule.field=="mobile"){
              if(/^1[23456789]\d{9}$/.test(value) == false){
                  return callback("请检查号码格式!");
              }
            }
            if(rule.field=="vcode"){
              if(self.vcode != self.admininfo.vcode){
                  return callback("校验码输入有误!");
              }
            }
            return callback();
        };
        return {
          selCompanyid:'',
          bizCode:'',
          currow:null,
          adminExist:false,
          vcode:null,
          isloadvcode:false,
          multipleSelection: [],
          isSingleSelect:false,
          cc:"ddddfsdfsd",
          dialogFormVisible:false,
          admininfo:{
            userName:"",
            mobile:"",
            vcode:""
          },
          rules:{
            userName:[
              { required: true, message: '请输入账号名称', trigger: 'blur' },
            ],
            mobile:[
              { validator: validmethod2, trigger: 'blur' },
              { required: true, message: '请检查电话号码格式', trigger: 'blur' },
            ],
            vcode:[
              { validator: validmethod2, trigger: 'blur' },
              { required: true, message: '验证码错误', trigger: 'blur' },
            ],
          }
        }
    },
    mounted:function(){
      var cmpid=this.$router.history.current.query.compid;
      this.selCompanyid=cmpid;
      this.$refs.cgrid.linkInInitQuery("companykey",cmpid);
    },
    created:function(){
      if(this.codePath.indexOf("myapps")>=0){
        this.bizCode="pmgmyapps";
      }
      if(this.codePath.indexOf("allapps")>=0){
        this.bizCode="allapps";
      }
      if(this.codePath.indexOf("comapps")>=0){
        this.bizCode="comapps";
        
      }
    },
    methods:{
      async fetchvcode(){
        if(/^1[23456789]\d{9}$/.test(this.admininfo.mobile) == false){
            return ;
        }
        this.isloadvcode=true;
        var d=await this.$root.postReq("/web/auth/userCtl/fetchVcode",{u:this.admininfo.mobile});
        if(d.status==0){
          this.vcode=d.data.vcodestr;
          setTimeout(()=>{
             this.isloadvcode=false;
          },3000);
        }           
      },
      async createUpdateAdmin(){
        this.admininfo.appid=this.currow.id;
        if(this.adminExist){
          var d=  await this.$root.postReq("/web/common/appCtl/resetPass", this.admininfo);
          if(d.status==0){
            this.$message("密码重置成功.");
          }else{
            this.$message("密码重置失败.");
          }
          this.dialogFormVisible=false;
          return ;
        }
        this.$refs.admininfo.validate(async v=>{
          if(v){
            console.log(this.admininfo);
            /* 发送*/
            var d=  await this.$root.postReq("/web/common/appCtl/createAdminUser", this.admininfo);
            if(d.status==0){
              this.$message("管理员创建成功");
            }else{
              this.$message("管理员创建失败");
            }
            this.dialogFormVisible=false;
          }else{
            
          }
        });
      
      },
   
      onColFormater(row,column,cellvalue,index){
        if(column.property=="isEnabled"){
          if(row["isEnabled"]){
            row["isEnabled"]=true;
            return "已启用";
          }else{
            row["isEnabled"]=false;
            return "停用";
          }
        }
        if(column.property=="isCommon"){
          if(row["isCommon"]){
            return "是";
          }else{
            return "否";
          }
        }
        if(column.property=="appType"){
            var at= { "api": "数据API", "web": "站点","app":"移动APP","xcx":"小程序","access":"接入"};
            return at[cellvalue];
        }
         return cellvalue;
       },
       handleSelectionChange:function(val){
         this.multipleSelection = val;
         console.log(this.cc);
       },
       headerCellStyle:function(){
         return {"background-color":"red"};
       },
       async onRowClick(row,key,e){
         console.log("adminModi");
          if(key=="adminModi"){
            this.dialogFormVisible=true;
            var d=  await this.$root.postReq("/web/auth/userCtl/findAppAdmin", {appid:row.id});
            if(d.status==0){
               this.admininfo=d.data;
               this.adminExist=true;
            }else{
              this.adminExist=false;
              this.admininfo.userName="";
              this.admininfo.mobile="";
              this.admininfo.vcode="";
            }
          }
          if(key=="appconfig"){
             this.$router.push({
               path:"/appconfig"
             });
          }
          if(key=="giveup"){
            var d=  await this.$root.postReq("/web/common/companyCtl/giveupApp", {compid: this.selCompanyid,appid:row.id});
            if(d.status==0){
              this.$refs.cgrid.linkInInitQuery("company_id",this.selCompanyid);
            }else{
              this.$message({
                type: 'warning',
                message: '应用已经产生数据，不能解除应用'
              });
            }

          }
          this.currow=row;
       }

    },
    computed:{
      headStyle:function(){
        return {"background-color":"white"};
      }
    },
    vname:"gsb-allapps"
}
