"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("./resetpwd.css");

var _button = _interopRequireDefault(require("../button"));

var _tips = _interopRequireDefault(require("../tips"));

var _phoneNumber = _interopRequireDefault(require("./phone-number"));

var _input = _interopRequireDefault(require("../input"));

var _base = require("../../utils/base");

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

/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var __vue_script__ = {
  name: (0, _base.createComponentName)('auth-resetpwd'),
  components: {
    Button: _button.default,
    PhoneNumber: _phoneNumber.default,
    Input: _input.default
  },
  mixins: [_base.componentMixin],
  inject: ['vm'],

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

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

  methods: {
    sendVerifyCode() {
      var _this = 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 _this.vm.requestUms('sendVerifyCode', (0, _assign.default)({}, _this.vm.form, {
                  type: 'find_password'
                }));

              case 3:
                _this.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]]);
      }))();
    },

    resetPassword() {
      var _this2 = this;

      if (this.loading) return;
      this.loading = true;
      this.vm.requestUms('resetPassword', this.vm.form).then(function () {
        (0, _tips.default)('密码修改成功，去登录吧');

        _this2.vm.switchType('phone');

        _this2.vm.$emit('success', {
          action: 'resetpwd',
          type: 'password'
        });

        _this2.loading = false;
      }).catch(function (error) {
        _this2.loading = false;
        (0, _tips.default)(error);

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

    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: {
      nativeType: "button",
      disabled: !!_vm.codePendingRemain
    },
    on: {
      click: _vm.sendVerifyCode
    }
  }, [_vm._v(_vm._s(_vm.codePendingRemain ? _vm.codePendingRemain + "秒后获取" : "获取验证码") + "\n        ")])], 1), _vm._v(" "), _c("div", {
    class: _vm.bem("item")
  }, [_c("Input", {
    attrs: {
      id: "password",
      label: "新密码",
      type: "password",
      name: "new-password",
      autocomplete: "off",
      placeholder: "输入6-30位新密码",
      maxlength: "30"
    },
    on: {
      enter: _vm.resetPassword
    },
    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.resetPassword
    }
  }, [_vm._v("更改密码")]), _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;