{
    template:'${tmpl}',
    data:function(){
      var that=this;
      var validateMethod=function(rule, value, callback){
        console.log(rule);
         if(rule.field=="mobile"){
           if(/^1[23456789]\d{9}$/.test(value) == false){
              return  callback(new Error("请输入正确格式的手机号"));
           }else{
              return  callback();
           }
         }
         if(rule.field=="vcode"){
           if(that.rcode!=value){
             return  callback(new Error("输入验证码有误，请重新输入"));
           }
         }
         return callback();
      };
      return {
        btnloading:false,
        rcode:"",
        form:{
          mobile:"",
          vcode:""
        },
        rs:{
          mobile: [
                     {required: true, message: '请输入手机号', trigger: 'blur' },
                     { validator: validateMethod, trigger: 'blur' },
          ],
          vcode: [
                     {required: true, message: '请输入手机接收到的验证码', trigger: 'blur' },
                     { validator: validateMethod, trigger: 'blur' },
          ],
        },

      };
    },
    mounted:function(){

    },
    created:function(){


    },
    methods:{
      fetchVcode(){
        var that=this;
        if(/^1[23456789]\d{9}$/.test(this.form.mobile) == false){
          this.$alert('请输入正确格式的手机号码', '提示', {
             confirmButtonText: '确定',
             callback: action => {
             }
           });
           return;
        };
        that.btnloading=true;
        that.$root.postReq("/web/userCtl/fetchVcode",{mobile:that.form.mobile}).then(function(d){
          if(d.status==0){
            that.rcode=d.data.vcodestr;
            setTimeout(()=>{
                that.btnloading=false;
            },3000);
          }
        });
      },
      bindmobile(){
        var that=this;
        that.$refs.form.validate(valid=>{
          if(valid){
            that.$root.postReq("/web/userCtl/updateMobile", {mobile:that.form.mobile}).then(d=>{
              if(d.status == 0) {
                that.$root.postReq("web/userCtl/loginByMobile",{mobile:that.form.mobile,app_id:20}).then(function(d){
                  console.log("--------------loginByMobile----------------");
                  console.log(d);
                  if(d.status==0){
                    that.$root.checkLogin(that.$root.checkcallback);
                  }
                });
              }
            });
          }
        });
      },
      giveup(){
        this.$router.push("/magicsearch");
      }

    },
    vname:"gsb-magicbindmobile"
}
