"use strict";

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

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

var _addGoodsDisabled = _interopRequireDefault(require("../assets/add-goods-disabled.png"));

var _addGoods = _interopRequireDefault(require("../assets/add-goods.png"));

var _decreaseGoodsDisabled = _interopRequireDefault(require("../assets/decrease-goods-disabled.png"));

var _decreaseGoods = _interopRequireDefault(require("../assets/decrease-goods.png"));

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; }

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["default"]
      }) : _react["default"].createElement("img", {
        className: "",
        src: _addGoods["default"]
      })), _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["default"]
      }) : _react["default"].createElement("img", {
        className: "",
        src: _decreaseGoods["default"]
      })))))), _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;