"use strict";

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

var _react = _interopRequireWildcard(require("react"));

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/* babel-plugin-inline-import '../assets/add-goods-disabled.png' */
var AddGoodsDisabled = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAXVBMVEUAAADJyM3NzdLIx83Jx83JyMzJyc3Kyc3Kyc7MyszOyM7i4uKQkJXIx83JyM3JyMzJyM3Jx83JyMzKyM3Kx87IyM3Kx83Lx86Pj5bJydHOzs7V1dX///+Pj5aPj5WrcgBQAAAAHnRSTlMA6xHkvKh0W0o0Jwjj2/nxy7evj3xmYE5JIRoGAuJeGBmiAAABL0lEQVRIx5WW25KDIBBEGwREvN+TePn/z1yrdjelkSh9HnigaIWZoQecSMe2zkVRiLxuxxQ3yKEplbFOTpN01qiyGeTF8rQTOj4skLEW3bffzH2kn+fpp476GR5elUrgJVHVyzMbGXzFRKdvxcLiAivij/W5wyUuPygS4XCDE8nuvJHFLTZ6n3yuDAIw1X90e4UgVP+X33PM8MiyhyfyvznvNE5k67qcZ3WHDSk89bBueKpEyG0cNEIF0MM2NHG4IG6AtJThAlmmGBXCBVAjWsMITIvaMgJbI3eMwOUQcpffZfWwz7kUKKZDfr0KvJkKWnDcklexHLZEH5oOK504ujTo4mPLm75A9BW9MIHMZwK0zbBGRlsla8as3bMNhW9ZfFPk2y7f2PmnA/84oZ8/P8ogIXAxMPAWAAAAAElFTkSuQmCC";

/* babel-plugin-inline-import '../assets/add-goods.png' */
var AddGoods = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAV1BMVEUAAADJyM3LyM7NzdLJyM3Ix832kD/Jx83JyMzJyc3Kyc3OyM7i4uLIx83JyM3Jx83Jx8zKyM3Kx87IyM3Kx834jz/Mx8zMzMzJydHOzs7V1dX////1jz4nRtjDAAAAHHRSTlMA60sR9eTjvK10WycI28u3pY98ZmBJNzIhGgYCCCmG3QAAASBJREFUSMeU0UmSgzAQRNGsKgnNzMYYuP852xHu6DAtbMRb6y9KiUzkrkmkFKWm44gTMlplHAdZFgnsjLKj4LPYk/W7B+It9RHH1kG3MzJzq4cVBx61uePQ3dQPZCbt8JHTE/7xxPiCyWPHp4CvQtoVEwWcCDS93asZp1j/Xb7WDgVcveJlMChiht99df7/t6q65Xvo1+Z9i0y1bRUybY8noRmZ7QmZmQTAaFEawI4ArC8PvAWikvJAVAQblAcwjM5dCVyHhq8E3CCFK0FIIHnfdzvwvrkQ1LLbN7fbfFE/ldYBDQAwDMMw/qyNwQAu/V+XtA/0lfrR/a09uI5Gh2/j3QvUK7oQaMwsyBqVC+PF/QrllfVSfO2+2L86fDnp+gOx8R9FxWHSUQAAAABJRU5ErkJggg==";

/* babel-plugin-inline-import '../assets/decrease-goods-disabled.png' */
var DecreaseGoodsDisabled = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAV1BMVEUAAADJyM3Kyc3LyM7NzdLJyM3Ix83Jx83JyMzJyc3OyM7i4uLIx83JyM3Jx83JyMzKyM3Kx87IyM3Mx8zMzMzJydHOzs7V1dX///+QkJWPj5aPj5aPj5V6HO85AAAAHHRSTlMA611LEfXkvKh0Jwjby7evj3xmNzIhGgYC40niKAcggQAAARlJREFUSMeU0VluwzAMBNChSO3yvqe5/zmLAK3QxnYsvw9+DUCQg53IbZ1Ia0p1yxEXRDXaeg6yLBLYW90owbnYkfsfEOWoO1uz9sZN2Jmc6VccmCs74tBoqxk7g/E45c2AN4oYHzCpt3wK+CgkhT8GCrgQaEA2G8YlNvnytfIo4Kvf7/YWRWz/068ZUWQ0ES+dQyHXvabQhEITCQDlUMwpAI1CMdUAUQuKiY5gixsso/W4wbeoGTdwjRRwQ0ggQfb4eh7YHsiEoBdk2/PQhmzR35XWSQ0AAAwCQSH498mbhM8IaNKDLnDBtnQrMi3x0LxWPhxLg8Wn8uYH4hdVCDBmFGSMSoWx4l4NxS3LTdFt143do4OHE44/BaEKFlXinRAcAAAAAElFTkSuQmCC";

/* babel-plugin-inline-import '../assets/decrease-goods.png' */
var DecreaseGoods = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAV1BMVEUAAADJyM3LyM7NzdLJyM3Ix83Jx83JyMzJyc3Kyc3OyM7i4uLIx832kD7JyM3Jx83Jx8zKyM3Kx87IyM3Kx83Mx8zMzMzJydHOzs7V1dX////4jz/1jz7Fa4D7AAAAHHRSTlMA60sR9eS8rXRbJwjb48u3pY98ZmA3MiEaBgJJvwCfPgAAARFJREFUSMeU0UmSwjAQBdHULEvC84BN3/+cvYBQBNhg+a3zLyqKnSi7JgmtRWo6GTmhRqetl0GtqwrSW+1GxXexF656C1TlRB85tg2mXdhZWjNsHLjXdubQbOs7O5PxfOXNxIdKSH6QovroU+CnkN4WkwicCGIiuxvJKWny5VvtKeDrjafBUsQOr/+amSKziQD0LYXaHkCJhUKLUMDoKOZGwFUUqxxErSimdERaLrCSznOB72gkF8iGFLggJIQie9z+DtweZEqgV7JXv1uQrfq/0jqgAQCGYRjGn7UxGMCl/+uS9oG+Uj+6v7UH19Ho8G28e4F6RRcCjZkFWaNyYby4X6G8sl6Kr90X+1eHLyddfwDJtxcFAvW6pAAAAABJRU5ErkJggg==";

var ConfirmBottom =
/*#__PURE__*/
function (_ref) {
  _inherits(ConfirmBottom, _ref);

  function ConfirmBottom() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, ConfirmBottom);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ConfirmBottom)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "state", {
      dataDetail: {},
      price: '',
      originalPrice: '',
      counts: '',
      num: 1,
      rentalDate: '',
      rulesId: []
    });

    _defineProperty(_assertThisInitialized(_this), "getCutprice", function (dataDetail) {
      if (Number(dataDetail.discountType === 2)) {
        return "| \u6EE1\u5929\u51CF".concat(dataDetail.cutPrice);
      }

      if (Number(dataDetail.discountType === 1)) {
        return "| \u6EE1".concat(dataDetail.fullPrice, "\u51CF").concat(dataDetail.cutPrice);
      }

      return '';
    });

    return _this;
  }

  _createClass(ConfirmBottom, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.initComponent(this.props);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      this.initComponent(nextProps);
    }
  }, {
    key: "initComponent",
    value: function initComponent(nextProps) {
      var _nextProps$dataDetail = nextProps.dataDetail,
          dataDetail = _nextProps$dataDetail === void 0 ? {} : _nextProps$dataDetail,
          _nextProps$price = nextProps.price,
          price = _nextProps$price === void 0 ? '' : _nextProps$price,
          _nextProps$counts = nextProps.counts,
          counts = _nextProps$counts === void 0 ? '' : _nextProps$counts,
          _nextProps$rulesId = nextProps.rulesId,
          rulesId = _nextProps$rulesId === void 0 ? [] : _nextProps$rulesId,
          rentalDate = nextProps.rentalDate,
          _nextProps$originalPr = nextProps.originalPrice,
          originalPrice = _nextProps$originalPr === void 0 ? '' : _nextProps$originalPr;
      this.setState({
        dataDetail: dataDetail,
        price: price,
        counts: counts,
        rulesId: rulesId,
        num: 1,
        rentalDate: rentalDate,
        originalPrice: originalPrice
      });
    }
  }, {
    key: "goNext",
    value: function goNext() {
      var _this2 = this;

      this.setState({
        loading: true
      });
      var _this$state = this.state,
          rentalDate = _this$state.rentalDate,
          num = _this$state.num,
          rulesId = _this$state.rulesId;
      var goNext = window.$$RESOURCECONTEXT.goNext;
      var rules = [];
      rulesId.forEach(function (ele) {
        rules.push({
          ruleId: ele,
          rentalCount: num || 1
        });
      });
      goNext(rules, rentalDate, num, rulesId, function () {
        _this2.setState({
          loading: false
        });
      });
    }
  }, {
    key: "onAdd",
    value: function onAdd() {
      var _this$state2 = this.state,
          num = _this$state2.num,
          counts = _this$state2.counts,
          originalPrice = _this$state2.originalPrice,
          dataDetail = _this$state2.dataDetail,
          price = _this$state2.price;
      var totalPrice = parseFloat(((num + 1) * originalPrice).toFixed(10));

      if (String(dataDetail.discountType) === '1') {
        if (totalPrice >= dataDetail.fullPrice) {
          totalPrice -= dataDetail.cutPrice;
        }
      } else if (String(dataDetail.discountType) === '2') {
        totalPrice = parseFloat(((num + 1) * (price / num)).toFixed(10));
      }

      if (num < counts) {
        this.setState({
          num: num + 1,
          price: totalPrice
        });
      }
    }
  }, {
    key: "onDecrease",
    value: function onDecrease() {
      var _this$state3 = this.state,
          num = _this$state3.num,
          originalPrice = _this$state3.originalPrice,
          dataDetail = _this$state3.dataDetail,
          price = _this$state3.price;
      var totalPrice = parseFloat(((num - 1) * originalPrice).toFixed(10));

      if (String(dataDetail.discountType) === '1') {
        if (totalPrice >= dataDetail.fullPrice) {
          totalPrice -= dataDetail.cutPrice;
        }
      } else if (String(dataDetail.discountType) === '2') {
        totalPrice = parseFloat(((num - 1) * (price / num)).toFixed(10));
      }

      if (num > 1) {
        this.setState({
          num: this.state.num - 1,
          price: totalPrice
        });
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;

      var self = this;
      var _window$$$RESOURCECON = window.$$RESOURCECONTEXT,
          notice = _window$$$RESOURCECON.notice,
          multiUnit = _window$$$RESOURCECON.multiUnit,
          autoAssign = _window$$$RESOURCECON.autoAssign;
      var _this$state4 = this.state,
          price = _this$state4.price,
          dataDetail = _this$state4.dataDetail,
          counts = _this$state4.counts,
          num = _this$state4.num,
          loading = _this$state4.loading;
      return _react["default"].createElement("div", {
        id: "rental-site-bottom",
        className: "rental-site-bottom"
      }, notice !== 'undefined' && notice ? _react["default"].createElement("div", {
        id: "rental-site-bottom-notice",
        className: "rental-site-bottom-notice"
      }, decodeURI(notice)) : '', String(multiUnit) === '1' && String(autoAssign) === '0' && _react["default"].createElement("div", {
        className: "rental-num-info"
      }, _react["default"].createElement("div", {
        className: "left"
      }, "\u9884\u8BA2\u6570\u91CF", counts && "(\u5E93\u5B58".concat(counts, ")")), counts && _react["default"].createElement("div", {
        className: "right"
      }, _react["default"].createElement("span", null, _react["default"].createElement("span", {
        className: "eh-stepper-add",
        onClick: function onClick() {
          return _this3.onAdd();
        }
      }, Number(counts) === Number(num) ? _react["default"].createElement("img", {
        alt: "",
        className: "",
        src: AddGoodsDisabled
      }) : _react["default"].createElement("img", {
        className: "",
        src: AddGoods
      })), _react["default"].createElement("span", null, _react["default"].createElement("input", {
        type: "number",
        value: num,
        readOnly: true,
        onChange: function onChange(event) {
          _this3.setState({
            num: event.target.value
          });
        },
        className: "eh-stepper-num"
      }), _react["default"].createElement("span", {
        className: "eh-stepper-add",
        onClick: function onClick() {
          return _this3.onDecrease();
        }
      }, Number(num) === 1 ? _react["default"].createElement("img", {
        alt: "",
        className: "",
        src: DecreaseGoodsDisabled
      }) : _react["default"].createElement("img", {
        className: "",
        src: DecreaseGoods
      })))))), _react["default"].createElement("div", {
        className: "rental-site-bottom-container",
        style: {
          lineHeight: "".concat(70 * window.devicePixelRatio, "px"),
          height: "".concat(70 * window.devicePixelRatio, "px")
        }
      }, _react["default"].createElement("div", {
        className: "rental-site-bottom-container-info"
      }, _react["default"].createElement("div", {
        className: "rental-site-bottom-container-info-price"
      }, "\uFFE5", _react["default"].createElement("span", {
        className: "price-num"
      }, price || 0)), _react["default"].createElement("div", {
        className: "rental-site-bottom-container-info-discount"
      }, this.getCutprice(dataDetail))), _react["default"].createElement(_button["default"], {
        loading: loading,
        type: "primary",
        onClick: function onClick() {
          self.goNext();
        }
      }, "\u4E0B\u4E00\u6B65")));
    }
  }]);

  return ConfirmBottom;
}(_react.PureComponent || _react.Component);

var _default = ConfirmBottom;
exports["default"] = _default;
module.exports = exports.default;