import "./register.css";
/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import Button from '../button';
import Tips from '../tips';
import PhoneNumber from './phone-number';
import Input from '../input';
import { componentMixin, createComponentName } from '../../utils/base';
const __vue_script__ = {
  name: createComponentName('auth-register'),
  components: {
    Button,
    PhoneNumber,
    Input
  },
  mixins: [componentMixin],
  inject: ['vm'],

  data() {
    return {
      loading: false,
      codePendingRemain: null
    };
  },

  beforeDestroy() {
    clearTimeout(this.codePendingTimer);
  },

  methods: {
    onRegister() {
      if (this.loading) return;
      this.loading = true;
      this.vm.requestUms('register', this.vm.form).then(() => {
        Tips('注册成功，现在去登录吧');
        this.vm.switchType('login');
        this.loading = false;
        this.vm.$emit('success', {
          action: 'register',
          type: 'password'
        });
      }).catch(error => {
        this.loading = false;
        Tips(error);
        this.vm.$emit('error', {
          action: 'register',
          type: 'password'
        });
      });
    },

    async sendVerifyCode() {
      try {
        await this.vm.requestUms('sendVerifyCode', { ...this.vm.form,
          type: 'register'
        });
        this.startCheckCodePending();
      } catch (error) {
        Tips(error);
      }
    },

    startCheckCodePending() {
      const check = () => {
        this.codePendingRemain -= 1;

        if (this.codePendingRemain <= 0) {
          this.codePendingRemain = null;
          return;
        }

        this.codePendingTimer = setTimeout(check, 1000);
      };

      clearTimeout(this.codePendingTimer);
      this.codePendingTimer = setTimeout(check, 1000);
      this.codePendingRemain = 60;
    }

  }
};
/* template */

var __vue_render__ = function () {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c("div", {
    class: _vm.bem()
  }, [_c("div", {
    class: _vm.bem("title")
  }, [_vm._v("注册账号")]), _vm._v(" "), _c("div", {
    class: _vm.bem("item")
  }, [_c("PhoneNumber", {
    attrs: {
      countries: _vm.vm.countries
    },
    model: {
      value: _vm.vm.form.phone,
      callback: function ($$v) {
        _vm.$set(_vm.vm.form, "phone", $$v);
      },
      expression: "vm.form.phone"
    }
  })], 1), _vm._v(" "), _c("div", {
    class: _vm.bem("item")
  }, [_c("Input", {
    attrs: {
      maxlength: "4",
      autocomplete: "off",
      placeholder: "输入短信中的验证码"
    },
    model: {
      value: _vm.vm.form.verifyCode,
      callback: function ($$v) {
        _vm.$set(_vm.vm.form, "verifyCode", $$v);
      },
      expression: "vm.form.verifyCode"
    }
  }), _vm._v(" "), _c("Button", {
    class: _vm.bem("sms-btn"),
    attrs: {
      rect: "",
      nativeType: "button",
      disabled: !!_vm.codePendingRemain
    },
    on: {
      click: _vm.sendVerifyCode
    }
  }, [_vm._v("\n            " + _vm._s(_vm.codePendingRemain ? _vm.codePendingRemain + "秒后获取" : "获取验证码") + "\n        ")])], 1), _vm._v(" "), _c("div", {
    class: _vm.bem("item")
  }, [_c("Input", {
    attrs: {
      id: "password",
      type: "password",
      label: "密码",
      name: "new-password",
      autocomplete: "off",
      placeholder: "输入6-30位密码",
      maxlength: "30"
    },
    model: {
      value: _vm.vm.form.password,
      callback: function ($$v) {
        _vm.$set(_vm.vm.form, "password", $$v);
      },
      expression: "vm.form.password"
    }
  })], 1), _vm._v(" "), _c("Button", {
    class: _vm.bem("submit"),
    attrs: {
      type: "primary",
      size: "large",
      nativeType: "submit",
      disabled: _vm.loading
    },
    on: {
      click: _vm.onRegister
    }
  }, [_vm._v("\n        " + _vm._s(_vm.loading ? "注册中..." : "注册账号") + "\n    ")]), _vm._v(" "), _c("div", {
    class: _vm.bem("footer")
  }, [_c("span", {
    class: _vm.bem("links")
  }, [_vm._v("已有账号？"), _c("Button", {
    attrs: {
      type: "text"
    },
    on: {
      click: function ($event) {
        _vm.vm.switchType("phone");
      }
    }
  }, [_vm._v("去登录")])], 1)])], 1);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = false;
/* component normalizer */

import __vue_normalize__ from '../../utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);