{
  template: '${tmpl}',
    data: function() {
      var that = this;
      var validateMethod = function (rule, value, callback) {
        console.log(rule, value);
        if (rule.field == "mobile") {
          if (/^1[23456789]\d{9}$/.test(value) == false) {
            return callback(new Error("请输入正确格式的手机号"));
          } else {
            return callback();
          }
        }
        if (rule.field == "code") {
          if (value.length != 6) {
            return callback(new Error("输入验证码有误，请重新输入"));
          }
        }
        return callback();
      };
      return {
        ldms: [],
        activeIndex: "1",
        loginUrl: "",
        form1: {
          mobile: "",
          code: "",
          password: "",
        },
        form2: {
          username: "",
          password: "",
        },
        form3: {
          mobile: "",
          code: "",
          password: "",
        },
        form4: {
          mobile: "",
          code: "",
          password: "",
        },
        a: true,
        b: false,
        c: false,
        Num: 60,
        Num2: 60,
        Num3: 60,
        rcode: "",
        rules1: {
          mobile: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
          code: [
            { required: true, message: '请输入手机接收到的验证码', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
        },
        rules2: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ],
        },
        rules3: {
          mobile: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
          code: [
            { required: true, message: '请输入手机接收到的验证码', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, max: 18, message: '长度在 6 到 18 个字符', trigger: 'blur' }
          ],
        },
        rules4: {
          mobile: [
            { required: true, message: '请输入手机号', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
          code: [
            { required: true, message: '请输入手机接收到的验证码', trigger: 'blur' },
            { validator: validateMethod, trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, max: 18, message: '长度在 6 到 18 个字符', trigger: 'blur' }
          ],
        },
        reqUrl: "",
        vCodeLoding: false,
      }
    },
  mounted: function() {
    if (this.$route.query.reqUrl != "") {
      this.reqUrl = this.$route.query.reqUrl;
    };

  },
  created: function() {
    if (this.$root.channelName == "bw") {
      this.loginUrl = "/imgs/loginbg.png";
    }
  },
  destroyed() {
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
      this.activeIndex = key;
    },
    resetall(){
      this.form1.mobile = "";
      this.form1.code = "";
      this.form1.password = "";
      this.form2.username = "";
      this.form2.password = "";
      this.form3.mobile = "";
      this.form3.code = "";
      this.form3.password = "";
      this.form4.mobile = "";
      this.form4.code = "";
      this.form4.password = "";
    },
    rsetpassword(){
      this.a = false;
      this.b = true;
      this.c = false;
      this.rcode = "";
      this.resetall();
    },
    login(){
      this.a = true;
      this.b = false;
      this.c = false;
      this.rcode = "";
      this.resetall();
    },
    register(){
      switch (this.$root.channelName) {
        case "bw":
          this.$router.push({ path: `/bw/register` });
          break;

        default:
          break;
      }
      this.a = false;
      this.b = false;
      this.c = true;
      this.rcode = "";
      this.resetall();
    },
    obtaincode1(){
      if (!(/^1[3456789]\d{9}$/.test(this.form1.mobile))) {
        this.$message("手机号有误");
        return false;
      } else {
        let obj = this.$root.copyParams({ mobile: this.form1.mobile }, "getVerifyCode", "/auth/accessAuth/springBoard");
        this.$root.postReq("/web/trademark/tmqueryCtl/doPost", obj).then((d) => {
          if (d.status == 0) {
            let date = 60;
            this.vCodeLoding = true;
            let timer = setInterval(() => {
              $('#loginCode').text(date--);
              if (date < 1) {
                clearInterval(timer);
                this.vCodeLoding = false;
                $('#loginCode').text('获取验证码');
              }
            }, 1000);
            console.log("返回信息", d);
          } else {
            this.$message(d.msg);
            console.log(d.msg);
          }
        });
      }

    },

    obtaincode2(){
      if (!(/^1[3456789]\d{9}$/.test(this.form3.mobile))) {
        this.$message("手机号有误");
        return false;
      } else {
        let obj = this.$root.copyParams({ mobile: this.form3.mobile }, "getVerifyCode", "/auth/accessAuth/springBoard");
        this.$root.loading = true;
        this.$root.postReq("/web/trademark/tmqueryCtl/doPost", obj).then((d) => {
          this.$root.loading = false;
          if (d.status == 0) {
            this.vCodeLoding = true;
            let date = 60;
            let timer = setInterval(() => {
              $('#resetCode').text(date--);
              if (date < 1) {
                clearInterval(timer);
                this.vCodeLoding = false;
                $('#resetCode').text('获取验证码');
              }
            }, 1000);
            console.log("返回信息", d);
          } else {
            console.log(d.msg);
            this.$message(d.msg);
          }
        });
      }


    },
    checklogin1(){
      var that = this;
      var userInfo = {
        mobile: that.form1.mobile,
        vcode: that.form1.code,
      };
      that.$refs.form1.validate(valid => {
        if (valid) {
          let obj = this.$root.copyParams(userInfo, "userPinByLgoinVcode", "/auth/accessAuth/springBoard");
          this.$root.loading = true;
          this.$root.postReq("/web/trademark/tmqueryCtl/doPost", obj).then((d) => {
            console.log(d.msg);
            this.$root.loading = false;
            if (d.status == 0) {
              d.data.isAdmin ? this.$root.superAdmin = d.data.isAdmin : this.$root.superAdmin = null;
              $.cookie('channelUserId', d.data.channelUserId);
              $.cookie('userName', d.data.userName);
              $.cookie('userpin', d.data.userpin);
              this.$root.user_Name = d.data.userName;
              this.$root.channelUserId = d.data.channelUserId;
              if (this.$store.state.reqUrl == `/${this.$root.channelName}/bwselftmreg`) {
                let { bwSubHistory } = localStorage;
                console.log(bwSubHistory, ".................................");
                if (bwSubHistory) {
                  this.$router.push({
                    path: `${this.$store.state.reqUrl}`,
                    query: { channelUserId: d.data.channelUserId, sdsId: 'zzsbzc', orderParams: { ...JSON.parse(bwSubHistory) } }
                  })
                }
                return;
              }
              if (!this.$store.state.reqUrl || this.$store.state.reqUrl == '/' || this.$store.state.reqUrl == `/${this.$root.channelName}/register`) {
                this.$router.push({
                  path: `/${this.$root.channelName}/jdtrademark`,
                  query: { channelUserId: d.data.channelUserId }
                })
              } else {
                this.$router.push({
                  path: `${this.$store.state.reqUrl}`,
                  query: { channelUserId: d.data.channelUserId, ...that.$store.state.reqQuery }
                })
              }
              console.log("返回信息", d)
            } else if (d.status == 2030) {
              this.$message({
                message: d.msg,
                type: 'warning'
              });
            } else if (d.status == 2060) {
              this.$message({
                message: d.msg,
                type: 'warning'
              });
            } else {
              this.$message({
                message: "请求失败",
                type: 'warning'
              });
            }
          });
        }
      })
    },
    /**密码登录2222222222 */
    checklogin2(){
      var that = this;
      var obj = {
        userName: that.form2.username,
        password: that.form2.password
      };
      that.$refs.form2.validate(valid => {
        if (valid) {
          var userInfo = that.$root.copyParams(obj, "userPinByLgoin", "/auth/accessAuth/springBoard");
          console.log(userInfo, 'mmmmmmmmmmmmmmmmmmmmmm');
          console.log(that.$store.state.reqQuery, "lllllllllllllllllllllllllllllllllllllllll");
          this.$root.loading = true;
          this.$root.postReq("/web/trademark/tmqueryCtl/doPost", userInfo).then((d) => {
            this.$root.loading = false;
            console.log(d.msg);
            if (d.status == 0) {
              d.data.isAdmin ? this.$root.superAdmin = d.data.isAdmin : this.$root.superAdmin = null;
              $.cookie('channelUserId', d.data.channelUserId);
              $.cookie('userName', d.data.userName);
              $.cookie('userpin', d.data.userpin);
              this.$root.user_Name = d.data.userName;
              this.$root.channelUserId = d.data.channelUserId;
              if (this.$store.state.reqUrl == `/${this.$root.channelName}/bwselftmreg`) {
                let { bwSubHistory } = localStorage;
                console.log(bwSubHistory, ".................................");
                if (bwSubHistory) {
                  this.$router.push({
                    path: `${this.$store.state.reqUrl}`,
                    query: { channelUserId: d.data.channelUserId, sdsId: 'zzsbzc', orderParams: { ...JSON.parse(bwSubHistory) } }
                  })
                }
                return;
              }

              if (!this.$store.state.reqUrl || this.$store.state.reqUrl == '/' || this.$store.state.reqUrl == `/${this.$root.channelName}/register`) {
                this.$router.push({
                  path: `/${this.$root.channelName}/jdtrademark`,
                  query: { channelUserId: d.data.channelUserId }
                })
              } else {
                this.$router.push({
                  path: `${this.$store.state.reqUrl}`,
                  query: { channelUserId: d.data.channelUserId, ...that.$store.state.reqQuery }
                })
              }
              console.log("返回信息", d)
            } else if (d.status == 2010) {
              this.$message({
                message: d.msg,
                type: 'warning'
              });
            } else if (d.status == 2060) {
              this.$message({
                message: d.msg,
                type: 'warning'
              });
            } else {
              this.$message({
                message: "请求失败",
                type: 'warning'
              });
            }
          });
        }
      });
    },
    sumbitreset(){
      var that = this;
      var obj = {
        mobile: this.form3.mobile,
        password: this.form3.password
      };
      that.$refs.form3.validate(valid => {
        if (valid) {
          var resetObj = {
            "mobile": this.form3.mobile,
            "vcode": this.form3.code,
            "newPwd": this.form3.password,
            "userpin": $.cookie('userpin')
          };
          var resetObj = that.$root.copyParams(resetObj, "putUserPwdByMobile", "/auth/accessAuth/springBoard");
          this.$root.loading = true;
          this.$root.postReq("/web/trademark/tmqueryCtl/doPost", resetObj).then((d) => {
            this.$root.loading = false;
            console.log(d);
            let userpin = $.cookie('userpin');
            switch (d.status) {
              case 0:
                if (userpin && userpin != "") {
                  $.removeCookie("userpin");
                  $.removeCookie("userName");
                  $.removeCookie("channelUserId");
                  this.$root.user_Name = "";
                  this.$root.channelUserId = '';
                  this.$message({ type: 'wraing', message: "修改成功,请重新登陆" });
                } else {
                  this.a = true;
                  this.b = false;
                  this.c = false;
                  this.activeIndex = 2;
                  this.$message({ type: 'wraing', message: "修改成功,请登陆" });
                }
                break;
              case 2030:
                this.$message({ type: 'wraing', message: "验证码错误,请重试" });
                break;

              default:
                this.$message({ type: 'wraing', message: "修改失败,请重试" });
                break;
            }
          });
        }
      })
    },
    submitregister(){
      var that = this;
      var obj = {
        mobile: this.form4.mobile,
        password: this.form4.password
      };
      that.$refs.form4.validate(valid => {
        if (valid) {
          that.$root.postReq("/web/userCtl/submitregister", obj).then(function (d) {
            if (d.status == 0) {
              that.$message({
                type: 'success',
                message: '注册成功,请登录'
              });
              that.login();
            } else if (d.status == 1) {
              that.$message({
                type: 'error',
                message: '该手机号码已注册'
              });
            }
          })
        }
      })
    },
    fetchVcode(mobilenum){
      var that = this;
      if (/^1[23456789]\d{9}$/.test(mobilenum) == false) {
        this.$alert('请输入正确格式的手机号码', '提示', {
          confirmButtonText: '确定',
          callback: action => {
          }
        });
        return;
      };
      var timer = setInterval(function () {
        console.log("----------getNumber-----------");
        $("#loginCode").attr("disabled", "disabled");
        $("#loginCode").css("cursor", "not-allowed");
        $("#loginCode").text(that.Num + "秒后重新获取");
        console.log(that.Num);
        if (that.Num > 0) {
          console.log(that.Num);
          that.Num--;
        } else {
          $("#loginCode").attr("disabled", false);
          $("#loginCode").text("获取验证码");
          that.Num = 60;
          clearInterval(timer);
        }
      }, 1000);
      this.$root.postReq("/web/userCtl/fetchVcode", { mobile: mobilenum }).then(function (d) {
        if (d.status == 0) {
          that.rcode = d.data.vcodestr;
        }
      })

    },
    validmethod: function (rule, value, callback) {
      console.log("code validdate");
      var self = this;
      var fm = this.currentFrm.getFormModel();
      return callback();
    },
    sbhandler: function () {
      var self = this;
      var fm = this.$refs.loginFrm.getFormModel();
      this.$refs.loginFrm.validate(function (v) {
        if (v) {
          self.$root.postReq("/web/userCtl/login", { u: fm }).then(function (d) {
            if (d.status == 0) {
              console.log("....................................................................................");
              self.$root.refreshLoginState(() => {
                console.log("....................................................................................innner");
                var afto = localStorage.getItem("afterLogin");
                if (afto) {
                  self.$root.pushx(JSON.parse(afto));
                  localStorage.removeItem("afterLogin");
                  self.$root.removetab("/login");
                } else {
                  location.reload();
                }
              });
            } else {
              self.$message({
                type: 'error',
                message: '用户名或密码错误，请重试.'
              });
            }
          });
        }
      });
    },

  },
  vname: "gsb-login"
}
