{
    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 {
          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(){
       
    },
    created:function(){
      if(this.codePath.indexOf("myapps")>=0){
        this.bizCode="pmgmyapps";
      }else{
        this.bizCode="allapps";
      }
    },
    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"
             });
          }
          this.currow=row;
       }

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