"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _tslib = require("tslib");

var _mobx = require("mobx");

var CountDown = /*#__PURE__*/function () {
  function CountDown() {
    var _this = this;

    (0, _classCallCheck2["default"])(this, CountDown);
    (0, _mobx.runInAction)(function () {
      _this.count = 0;
    });
  }

  (0, _createClass2["default"])(CountDown, [{
    key: "setCount",
    value: function setCount() {
      // 计算时间差
      var millis = Date.now() - this.startTime;
      this.count = 60 - Math.floor(millis / 1000);
    }
  }, {
    key: "start",
    value: function start() {
      var _this2 = this;

      this.startTime = Date.now();
      var timer = setInterval(function () {
        _this2.setCount(); // 倒计时结束


        if (_this2.count <= 0) {
          clearInterval(timer);

          _this2.setVerifyType();
        }
      }, 1000);
    } // 获取验证码时的验证方式

  }, {
    key: "setVerifyType",
    value: function setVerifyType(value) {
      this.verifyType = value || null;
    }
  }]);
  return CountDown;
}();

(0, _tslib.__decorate)([_mobx.observable], CountDown.prototype, "count", void 0);
(0, _tslib.__decorate)([_mobx.action], CountDown.prototype, "setCount", null);
var _default = CountDown;
exports["default"] = _default;
//# sourceMappingURL=CountDown.js.map
