"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

var _rangePickerPop = _interopRequireDefault(require("../range-picker-pop"));

var _requestV = require("../../utils/request-v1");

var _Portals = _interopRequireDefault(require("../../components-v1/portals/Portals"));

var _transition = _interopRequireDefault(require("../../components-v1/transition"));

var _eReportListEmpty = _interopRequireDefault(require("../eReport/eReportListEmpty"));

var _eReportShare = _interopRequireDefault(require("../eReport/eReportShare"));

var _toast = _interopRequireDefault(require("../eReport/eReportShare/toast"));

var _style = require("./style");

var _getLocale = require("../../utils/getLocale");

require("./index.css");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

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

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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

var EReportList = /*#__PURE__*/function (_React$Component) {
  _inherits(EReportList, _React$Component);

  var _super = _createSuper(EReportList);

  function EReportList() {
    var _this;

    _classCallCheck(this, EReportList);

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

    return _possibleConstructorReturn(_this, (_this = _super.call.apply(_super, [this].concat(args)), _this.state = {
      selectedPeriodValue: "",
      showDatePick: false,
      eReportWeekList: [],
      timePickRef: /*#__PURE__*/_react["default"].createRef(),
      timePick: null,
      showMoreInfo: false,
      timePickResultsEmpty: false,
      isShowEReportSharePop: false,
      eReportId: 0,
      eReportDate: "",
      isShowToast: false,
      submitStatus: ""
    }, _this.setIsTimeSelected = function (v) {
      _this.setState({
        selectedPeriodValue: v
      });
    }, _this.handleClickReportListsDiv = function (e) {
      _this.setState({
        showDatePick: e.target.getAttribute("data-name") === "time-pick"
      });
    }, _this.handleTimePickConfirm = function (_ref) {
      var startDate = _ref.startDate,
          endDate = _ref.endDate;
      // 将2019-12-3改为2019年12月3日
      var start = startDate.substring(0, startDate.indexOf("T"));
      var end = endDate.substring(0, endDate.indexOf("T"));
      start = "".concat(start.replace(/-/i, "年").replace(/-/i, "月"), "\u65E5");
      end = "".concat(end.replace(/-/i, "年").replace(/-/i, "月"), "\u65E5");

      _this.setState({
        selectedPeriodValue: "".concat(start, " - ").concat(end),
        timePickResultsEmpty: true
      }); // 上面是控制时间筛选那个组件显示的文字更新的
      // 下面是筛选的逻辑


      var okrId = _this.props.okrId;
      var url = (0, _requestV.getApiUrl)("okr/weekStatistics/list?okrId=".concat(okrId, "&startDate=").concat(start, "&endDate=").concat(end));
      (0, _requestV.taker)(url, "get", null, {}).then(function (res) {
        _this.setState({
          eReportWeekList: res.Data
        });
      });
    }, _this.handleShowMoreInfoClick = function (id) {
      _this.setState({
        showMoreInfo: true
      });

      var url = (0, _requestV.getApiUrl)("okr/weekStatistics/info?id=".concat(id));
      (0, _requestV.taker)(url, "get", null).then(function (res) {
        window.open();
      });
    }, _this.handlerEReportShareSubmit = function (submitStatus, eReportId, startDate, endDate) {
      if (submitStatus === "success") {
        _this.setState({
          isShowEReportSharePop: false,
          isShowToast: true,
          submitStatus: "success"
        });

        setTimeout(function () {
          _this.setState({
            isShowToast: false
          });
        }, 2000);
      } else if (submitStatus === "failed") {
        _this.setState({
          isShowEReportSharePop: false,
          isShowToast: true,
          submitStatus: "error"
        });

        setTimeout(function () {
          _this.setState({
            isShowToast: false
          });
        }, 2000);
      } else if (submitStatus === "cancel") {
        _this.setState({
          isShowEReportSharePop: false
        });
      } else if (submitStatus === "showEReportShare") {
        _this.setState({
          isShowEReportSharePop: true,
          eReportId: eReportId || 0,
          eReportDate: "".concat(startDate, "-").concat(endDate)
        });
      }
    }, _this.getShare = function (showShare, id, date) {
      var _this$props = _this.props,
          isVisible = _this$props.isVisible,
          okrName = _this$props.okrName,
          okrId = _this$props.okrId;
      return /*#__PURE__*/_react["default"].createElement(_Portals["default"], null, /*#__PURE__*/_react["default"].createElement(_transition["default"], {
        visible: showShare,
        animate: true,
        transitionName: "modal",
        enterActiveTimeout: 450,
        enterEndTimeout: 200,
        leaveActiveTimeout: 200,
        leaveEndTimeout: 300
      }, /*#__PURE__*/_react["default"].createElement(_eReportShare["default"], {
        className: "ereport__share__wrapper",
        isVisible: isVisible,
        workName: okrName,
        workId: okrId,
        eReportId: id,
        eReportDate: date,
        onSubmit: function onSubmit(submitStatus) {
          return _this.handlerEReportShareSubmit(submitStatus);
        }
      })));
    }, _assertThisInitialized(_this)));
  }

  _createClass(EReportList, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      var okrId = this.props.okrId;
      var url = (0, _requestV.getApiUrl)("okr/weekStatistics/list?okrId=".concat(okrId));
      (0, _requestV.taker)(url, "get", null, {}).then(function (res) {
        _this2.setState({
          eReportWeekList: res.Data || [],
          timePick: _this2.state.timePickRef.current
        });
      });
    }
  }, {
    key: "getListItem",
    value: function getListItem(list) {
      var _this3 = this;

      var okrId = this.props.okrId;
      return list.map(function (v) {
        return /*#__PURE__*/_react["default"].createElement(_style.ListItemStyle, {
          key: v.id
        }, /*#__PURE__*/_react["default"].createElement(_style.ItemTimeDivStyle, null, /*#__PURE__*/_react["default"].createElement(_style.ItemTimeBackgroundStyle, {
          className: "tu-icon-OKRs-E"
        }), /*#__PURE__*/_react["default"].createElement(_style.ItemTimeTextStyle, null, "(", "".concat(v.startDate, "-").concat(v.endDate), ")")), /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsActionsDivStyle, null, /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsChildsDivStyle, null, /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsShareBackgroundStyle, {
          onClick: function onClick() {
            return _this3.handlerEReportShareSubmit("showEReportShare", v.id, v.startDate, v.endDate);
          },
          className: "tu-icon-share1"
        }), /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsShareTextStyle, {
          onClick: function onClick() {
            return _this3.handlerEReportShareSubmit("showEReportShare", v.id, v.startDate, v.endDate);
          }
        }, (0, _getLocale.getLocale)("OKR_MyO_Share"))), /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsChildsDivStyle, null, /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsMoreInfoTextStyle, {
          target: "_new",
          onClick: function onClick() {
            return window.open("".concat(location.pathname, "#okr/eReport?okrId=").concat(v.id, "&work_id=").concat(okrId));
          },
          href: void 0
        }, (0, _getLocale.getLocale)("Mod_Checkdetails")), /*#__PURE__*/_react["default"].createElement(_style.ItemOptionsMoreInfoBackgroundStyle, {
          onClick: function onClick() {
            window.open("".concat(location.pathname, "#okr/eReport?okrId=").concat(v.id, "&work_id=").concat(okrId));
          },
          className: "tu-icon-xiangqing"
        }))));
      });
    }
  }, {
    key: "getToast",
    value: function getToast(showToast, submitStatus) {
      return showToast && /*#__PURE__*/_react["default"].createElement(_Portals["default"], null, /*#__PURE__*/_react["default"].createElement(_toast["default"], {
        submitStatus: submitStatus
      }));
    }
  }, {
    key: "getTimePick",
    value: function getTimePick() {
      return /*#__PURE__*/_react["default"].createElement(_style.ListTopDivStyle, {
        ref: this.state.timePickRef
      }, /*#__PURE__*/_react["default"].createElement(_style.ListTopLabelStyle, null, (0, _getLocale.getLocale)("OKR_MyO_Ew_List")), /*#__PURE__*/_react["default"].createElement(_style.ListTopTimePickDivStyle, null, /*#__PURE__*/_react["default"].createElement(_style.TimePickStyle, {
        "data-name": "time-pick",
        className: "tu-icon-schedule"
      }), /*#__PURE__*/_react["default"].createElement(_rangePickerPop["default"], {
        className: "document-mouse-event-ignore ",
        popupPlacement: "bottomRight",
        format: "",
        container: document.body,
        onConfirm: this.handleTimePickConfirm
      }, /*#__PURE__*/_react["default"].createElement(_style.TimePickTextStyle, {
        "data-name": "time-pick"
      }, this.state.selectedPeriodValue || (0, _getLocale.getLocale)("OKR_MyO_Ew_Butt_Filterbytime")))));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$state = this.state,
          eReportWeekList = _this$state.eReportWeekList,
          timePickResultsEmpty = _this$state.timePickResultsEmpty,
          isShowEReportSharePop = _this$state.isShowEReportSharePop,
          eReportDate = _this$state.eReportDate,
          submitStatus = _this$state.submitStatus,
          isShowToast = _this$state.isShowToast,
          eReportId = _this$state.eReportId; // return <Replay show container={document.body}></Replay>

      return timePickResultsEmpty ? /*#__PURE__*/_react["default"].createElement(_style.ListStyle, {
        onClick: this.handleClickReportListsDiv
      }, this.getTimePick(), eReportWeekList.length === 0 ? /*#__PURE__*/_react["default"].createElement(_eReportListEmpty["default"], {
        text: (0, _getLocale.getLocale)("Mod_ lookingfor")
      }) : this.getListItem(eReportWeekList), this.getShare(isShowEReportSharePop, eReportId, eReportDate), this.getToast(isShowToast, submitStatus)) : eReportWeekList.length === 0 ? /*#__PURE__*/_react["default"].createElement(_eReportListEmpty["default"], {
        text: "\u8FD8\u672A\u5230E-\u5468\u62A5\u751F\u6210\u65F6\u95F4\u54E6~"
      }) : /*#__PURE__*/_react["default"].createElement(_style.ListStyle, {
        onClick: this.handleClickReportListsDiv
      }, this.getTimePick(), this.getListItem(eReportWeekList), this.getShare(isShowEReportSharePop, eReportId, eReportDate), this.getToast(isShowToast, submitStatus));
    }
  }]);

  return EReportList;
}(_react["default"].Component);

var _default = EReportList;
exports["default"] = _default;