"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));

var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));

require("regenerator-runtime/runtime");

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));

require("./Register.css");

var _Button = _interopRequireDefault(require("../Button"));

var _Tips = _interopRequireDefault(require("../Tips"));

var _PhoneNumber = _interopRequireDefault(require("./PhoneNumber"));

var _Input = _interopRequireDefault(require("../Input"));

var _component = require("../_utils/component");

var _vueNormalizeComponent = _interopRequireDefault(require("../_utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var __vue_script__ = {
  name: (0, _component.createComponentName)('auth-register'),
  components: {
    Button: _Button.default,
    PhoneNumber: _PhoneNumber.default,
    Input: _Input.default
  },
  mixins: [_component.componentMixin],
  inject: ['vm'],

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

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

  methods: {
    onRegister() {
      var _this = this;

      if (this.loading) return;
      this.loading = true;
      this.vm.requestUms('register', this.vm.form).then(function () {
        (0, _Tips.default)('注册成功，现在去登录吧');

        _this.vm.switchType('login');

        _this.loading = false;

        _this.vm.$emit('success', {
          action: 'register',
          type: 'password'
        });
      }).catch(function (error) {
        _this.loading = false;
        (0, _Tips.default)(error);

        _this.vm.$emit('error', {
          action: 'register',
          type: 'password'
        });
      });
    },

    sendVerifyCode() {
      var _this2 = this;

      return (0, _asyncToGenerator2.default)(
      /*#__PURE__*/
      _regenerator.default.mark(function _callee() {
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.prev = 0;
                _context.next = 3;
                return _this2.vm.requestUms('sendVerifyCode', (0, _assign.default)({}, _this2.vm.form, {
                  type: 'register'
                }));

              case 3:
                _this2.startCheckCodePending();

                _context.next = 9;
                break;

              case 6:
                _context.prev = 6;
                _context.t0 = _context["catch"](0);
                (0, _Tips.default)(_context.t0);

              case 9:
              case "end":
                return _context.stop();
            }
          }
        }, _callee, this, [[0, 6]]);
      }))();
    },

    startCheckCodePending() {
      var _this3 = this;

      var check = function check() {
        _this3.codePendingRemain -= 1;

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

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

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

  }
};
/* template */

var __vue_render__ = function __vue_render__() {
  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 callback($$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 callback($$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 callback($$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 click($event) {
        _vm.vm.switchType("phone");
      }
    }
  }, [_vm._v("去登录")])], 1)])], 1);
};

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

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default = (0, _vueNormalizeComponent.default)({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default;