{
    template:'${tmpl}',
    data:function(){
        return {
            mds:[],
            emds:[],
            vcode:"",
            actname:"person",
            currentFrm:null,

        }
    },
    mounted:function(){
        this.mds=[
            {
                "title":"",
                "colnum": 1,
                "ctls":[
                  {"type":"input","label":"用户名","prop":"userName","placeHolder":"请输入用户名","style":"","rules": [{ "required": true, "message": '请输入用户名', "trigger": 'blur' }]},

                  {"type":"input","label":"用户密码","prop":"password","placeHolder":"请输入用户密码","style":"", "rules": [{ "required": true, "message": '请输入用户密码', "trigger": 'blur' }]},
                  {"type":"input","label":"确认密码","prop":"cfmpwd","placeHolder":"请输入确认密码","style":"","rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入确认密码', "trigger": 'blur' }]},

                  {"type":"input","label":"姓名","prop":"nickName","placeHolder":"请输入姓名","style":"","rules": [{ "required": true, "message": '请输入姓名', "trigger": 'blur' }]},

                  {"type":"input","label":"手机号","prop":"mobile","placeHolder":"请输入手机号","style":"","rules": [{ "required": true, "message": '请输入手机号', "trigger": 'blur' }]},
                  {"type":"btn","label":"获取验证码","prop":"vcodeget","placeHolder":"请输入手机号","style":{"margin-left":"8px"},"face":"primary"},

                  {"type":"input","label":"验证码","prop":"vcode","placeHolder":"请输入收到的手机验证码","style":"","rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入验证码', "trigger": 'blur' }]},
                  {"type":"input","label":"用户名","prop":"onlyCode","placeHolder":"请输入身份证号","style":""},
                ]
              },
        ];
       
        this.currentFrm=this.$refs.pregisterFrm;
    },
    created:function(){
       
    },
    methods:{
        rdochange:function(nv){
            if(nv=="person"){
                this.mds=[
                  {
                    "title":"",
                    "colnum": 1,
                    "ctls":[
                      {"type":"input","label":"用户名","prop":"userName","placeHolder":"请输入用户名","style":"","rules": [{ "required": true, "message": '请输入用户名', "trigger": 'blur' }]},

                      {"type":"input","label":"用户密码","prop":"password","placeHolder":"请输入用户密码","style":"","rules": [{ "required": true, "message": '请输入用户密码', "trigger": 'blur' }]},
                      {"type":"input","label":"确认密码","prop":"cfmpwd","placeHolder":"请输入确认密码","style":"", "rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入确认密码', "trigger": 'blur' }]},
                      {"type":"input","label":"用户名","prop":"nickName","placeHolder":"请输入姓名","style":"", "rules": [{ "required": true, "message": '请输入姓名', "trigger": 'blur' }]},

                      {"type":"input","label":"手机号","prop":"mobile","placeHolder":"请输入手机号","style":"","rules": [{ "required": true, "message": '请输入手机号', "trigger": 'blur' }]},
                      {"type":"btn","label":"获取验证码","prop":"vcodeget","placeHolder":"请输入手机号","style":{"margin-left":"8px"},"face":"primary"},

                      {"type":"input","label":"手机号","prop":"vcode","placeHolder":"请输入收到的手机验证码","style":"","rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入验证码', "trigger": 'blur' }]},

                      {"type":"input","label":"身份证号","prop":"onlyCode","placeHolder":"请输入身份证号","style":""},
                    ]
                  },
                ];
                this.currentFrm=this.$refs.pregisterFrm;
            }else{
                this.emds=[
                  {
                    "title":"",
                    "colnum": 1,
                    "ctls":[
                      {"type":"input","label":"用户名","prop":"userName","placeHolder":"请输入用户名","style":"", "rules": [{ "required": true, "message": '请输入用户名', "trigger": 'blur' }]},

                      {"type":"input","label":"用户密码","prop":"password","placeHolder":"请输入用户密码","style":"", "rules": [{ "required": true, "message": '请输入用户密码', "trigger": 'blur' }]},
                      {"type":"input","label":"确认密码","prop":"cfmpwd","placeHolder":"请输入确认密码","style":"","rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入确认密码', "trigger": 'blur' }]},

                      {"type":"input","label":"企业名称","prop":"companyName","placeHolder":"请输入企业名称","style":"","rules": [{ "required": true, "message": '请输入企业名称', "trigger": 'blur' }]},

                      {"type":"input","label":"联系人","prop":"nickName","placeHolder":"请输入联系人姓名","style":""},

                      {"type":"input","label":"手机号","prop":"mobile","placeHolder":"请输入手机号","style":"","rules": [{"required": true, "message": '请输入手机号', "trigger": 'blur' }]},
                      {"type":"btn","label":"获取验证码","prop":"vcodeget","placeHolder":"请输入手机号","style":{"margin-left":"8px"},"face":"primary"},

                      {"type":"input","label":"验证码","prop":"vcode","placeHolder":"请输入收到的手机验证码","style":"","rules": [{ "validator":"validatex","trigger": 'blur' },{ "required": true, "message": '请输入验证码', "trigger": 'blur' }]},
                    ]
                  },
                ];
                this.currentFrm=this.$refs.eregisterFrm;
            }
        },
        validmethod:function (rule,value,callback) { 
            console.log("code validdate");
            var self=this;
            var fm=this.currentFrm.getFormModel();
            if(rule.field=="cfmpwd"){
                if(fm.password!=value){
                    return callback(new Error("两次输入的密码不一致，请重新输入！"));
                }
            }
            if(rule.field=="vcode"){
                if(self.vcode!=value){
                    return callback(new Error("验证码输入错误，请重新输入或重新获取后输入！"));
                }
            }
            return callback();
        },
        sbhandler:function () {  
            var self=this;
            var fm=this.currentFrm.getFormModel();
            this.currentFrm.validate(function(v){
                if(v){
                    self.$root.postReq("/web/userCtl/register",{u:fm}).then(function(d){
                        if(d.status==0){
                          self.$root.removetab("/register");
                          self.$root.pushx({
                            title:"登录",
                            name:"/login"
                          });
                        } else {
                          self.$message.warning(d.msg || "注册失败, 请稍候重试");
                        }
                      });
                }
            });
         },
         btnclick:function(pfm,code){
            var fm=pfm;
            if(code=="vcodeget"){
                var that=this;
                if(/^1[23456789]\d{9}$/.test(fm.mobile) == false){
                  this.$alert('请输入正确格式的手机号码', '提示', {
                     confirmButtonText: '确定',
                     callback: action => {
                     }
                   });
                   return;
                }
                this.$root.showMask();
                /*ajax 调用获取手机验证码,并存储到*/
                this.$root.postReq("/web/userCtl/fetchVcode",{mobile:fm.mobile}).then(function(d){
                  if(d.status==0){
                    that.vcode=d.data.vcodestr;
                    setTimeout(()=>{
                        that.$root.hideMask();
                    },3000);
                  }
                });
            }
         },

    },
    vname:"gsb-register"
}
