"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 = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _filterButtons = _interopRequireDefault(require("../../components/filter-buttons"));

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

var _formatTime = require("../../utils/format-time");

var _bsGlobal = require("../../utils/bs-global");

var _auth = require("../../utils/auth");

var _table = _interopRequireDefault(require("../../components/table"));

var _column = require("./column");

var _requestApi = require("./request-api");

require("./index.css");

require("./new-ui.css");

var _window$BSGlobal$tena;

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var preCls = (_window$BSGlobal$tena = window.BSGlobal.tenantInfo) !== null && _window$BSGlobal$tena !== void 0 && _window$BSGlobal$tena.isNewIndex ? "titaui-new-ui-ranking-page" : "like-ranking-page";
var hasAuth = new _auth.DynamicManagerAuth();

var LikeRanking = function LikeRanking() {
  var _useState = (0, _react.useState)(function () {
    var depIds = "";

    if (hasAuth.isOnlyLeader()) {
      depIds = "".concat((0, _bsGlobal.getUserInfo)().DepartmentId);
    }

    return {
      date: {
        createDate: "",
        endDate: ""
      },
      depIds: depIds
    };
  }),
      _useState2 = _slicedToArray(_useState, 2),
      parmas = _useState2[0],
      setParmas = _useState2[1];

  var _useState3 = (0, _react.useState)(10),
      _useState4 = _slicedToArray(_useState3, 2),
      pageSize = _useState4[0],
      setPageSize = _useState4[1];

  var _useState5 = (0, _react.useState)(1),
      _useState6 = _slicedToArray(_useState5, 2),
      pageNum = _useState6[0],
      setPageNum = _useState6[1];

  var _useState7 = (0, _react.useState)(0),
      _useState8 = _slicedToArray(_useState7, 2),
      total = _useState8[0],
      setTotal = _useState8[1];

  var _useState9 = (0, _react.useState)([]),
      _useState10 = _slicedToArray(_useState9, 2),
      pariseInfos = _useState10[0],
      setPariseInfos = _useState10[1];

  var _useState11 = (0, _react.useState)(false),
      _useState12 = _slicedToArray(_useState11, 2),
      isLoading = _useState12[0],
      setIsloading = _useState12[1];

  var _useState13 = (0, _react.useState)((0, _getLocale.getLocale)("Mod_all")),
      _useState14 = _slicedToArray(_useState13, 2),
      type = _useState14[0],
      setType = _useState14[1];

  var setParma = function setParma(key, value) {
    var obj = _objectSpread({}, parmas);

    obj[key] = value;

    switch (key) {
      case "depIds":
        obj.groupIds = "";
        break;

      case "groupIds":
        obj.depIds = "";
        break;
    }

    setPageNum(1);
    setParmas(obj);
  };

  (0, _react.useEffect)(function () {
    setIsloading(true);
    (0, _requestApi.getRanking)({
      ToDepIds: parmas.depIds || "",
      ToGroupIds: parmas.groupIds || "",
      CreateDate: parmas.date ? parmas.date.createDate || "" : "",
      EndDate: parmas.date ? parmas.date.endDate || "" : "",
      ObjectType: parmas.ObjectType || "",
      ObjectTypeAction: 0,
      PageNum: pageNum,
      PageSize: pageSize
    }).then(function (res) {
      if (res.Code === 1) {
        var _res$Data = res.Data,
            _total = _res$Data.total,
            userPariseinfos = _res$Data.userPariseinfos;
        setTotal(_total);
        setPariseInfos(userPariseinfos);
        setIsloading(false);
      }
    });
  }, [parmas, pageNum, pageSize]);

  var handlerChangeDate = function handlerChangeDate(item) {
    setType(item);
    var createDate = "";
    var endDate = "";

    if (item == (0, _getLocale.getLocale)("Feed_Tab_Title_Thismonth")) {
      createDate = (0, _formatTime.showMonthFirstDay)();
      endDate = (0, _formatTime.showNextMonthFirstDay)();
    } else if (item == (0, _getLocale.getLocale)("Feed_Tab_Title_Thisweek")) {
      createDate = (0, _formatTime.showWeekFirstDay)();
      endDate = (0, _formatTime.showNextWeekFirstDay)();
    } else if (item == (0, _getLocale.getLocale)("Feed_Tab_Title_Thisyear")) {
      createDate = (0, _formatTime.getFirstDayOfYear)();
      endDate = (0, _formatTime.getNextDayOfYear)();
    }

    var date = {
      createDate: createDate,
      endDate: endDate
    };
    setParma("date", date);
  };

  function TabBar() {
    var typeData = ["".concat((0, _getLocale.getLocale)("Mod_all")), "".concat((0, _getLocale.getLocale)("Feed_Tab_Title_Thisweek")), "".concat((0, _getLocale.getLocale)("Tasks_Menu_Thismonth")), (0, _getLocale.getLocale)("Feed_Tab_Title_Thisyear")];
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__tab-bar")
    }, typeData.map(function (item, key) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        key: key,
        className: (0, _classnames["default"])("".concat(preCls, "__tab-bar-item"), _defineProperty({}, "".concat(preCls, "__tab-bar-item--selected"), type === item)),
        onClick: function onClick() {
          return handlerChangeDate(item);
        }
      }, item);
    }));
  }

  var renderEmpty = function renderEmpty() {
    if (isLoading || pariseInfos && pariseInfos.length > 0) return;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__empty")
    }, /*#__PURE__*/_react["default"].createElement("img", {
      className: "".concat(preCls, "__empty-img"),
      src: require("./image/dynamic-empty.png")
    }), /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(preCls, "__empty-text")
    }, (0, _getLocale.getLocale)("Pro_Butt_Nodata")));
  };

  var isLoadingPage = function isLoadingPage() {
    if (!isLoading) return;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__loading")
    }, /*#__PURE__*/_react["default"].createElement("img", {
      className: "".concat(preCls, "__loading-image"),
      src: require("./image/loading.gif"),
      alt: ""
    }));
  };

  var handleLinkToPraiseRaking = function handleLinkToPraiseRaking() {
    // window.history.go(-1)
    var href = window.location.href;
    var url = "".concat(href.split("#")[0], "#dynamic");
    window.open(url, "self");
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls)
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__header")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(preCls, "__header-back"),
    onClick: handleLinkToPraiseRaking
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "tu-icon-fanhui ".concat(preCls, "__header-back-icon")
  }), (0, _getLocale.getLocale)("Mod_Back")), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(preCls, "__header-line")
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(preCls, "__header-text")
  }, (0, _getLocale.getLocale)("Feed_Title_Likeranking"))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__bottom")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__btns")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__btns-left")
  }, /*#__PURE__*/_react["default"].createElement(_filterButtons["default"], {
    setParma: setParma,
    parmas: parmas,
    setType: setType
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__content")
  }, TabBar(), renderEmpty(), isLoadingPage(), !isLoading && /*#__PURE__*/_react["default"].createElement(_table["default"], {
    tableLayout: "fixed",
    columns: (0, _column.columns)(),
    tableData: pariseInfos,
    total: total,
    pageSize: pageSize,
    setPageSize: setPageSize,
    pageNum: pageNum,
    setPageNum: setPageNum
  }))));
};

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