"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.workDelete = exports.updateVisibility = exports.updateTaskStatus = exports.updateTaskPrincipal = exports.updateTaskDate = exports.updateProgressDesc = exports.updateProgress = exports.updateParentId = exports.updateOkrVisibility = exports.updateOkrPrincipal = exports.updateOkrName = exports.updateOScore = exports.updateOCommitType = exports.updateOClassify = exports.updateKrProgressAndStatus = exports.updateKrPrincipal = exports.updateKrName = exports.updateKrDate = exports.updateConfidenceIndex = exports.updateClassify = exports.updateChildOkrWeight = exports.transferPrincipal = exports.start = exports.setTaskPriority = exports.saveODesc = exports.remindAction = exports.krChangeOrder = exports.getRelWorks = exports.getRelProgress = exports.getProgress = exports.getPraiseComments = exports.getOrg = exports.getOkrUsers = exports.getOkrDetail = exports.getOkrApprovalSettingInfo = exports.getKrsByCondition = exports.getKrs = exports.getFeedById = exports.deleteUser = exports.deleteProgressDesc = exports.deleteKr = exports.createNewKr = exports.close = exports.cancelRel = exports.cancelPraise = exports.cancelParentOkr = exports.addUserRelation = exports.addUser = exports.addPraise = exports.addComment = void 0;

var _qs = _interopRequireDefault(require("qs"));

var _request = require("../../utils/request");

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

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

var _BSGlobal$loginUserIn;

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

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

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

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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

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

// @ts-ignore
var userId = BSGlobal && ((_BSGlobal$loginUserIn = BSGlobal.loginUserInfo) === null || _BSGlobal$loginUserIn === void 0 ? void 0 : _BSGlobal$loginUserIn.Id) || 0;

var getKrs = function getKrs(_ref) {
  var okrId = _ref.okrId;
  return (0, _request.rpost)('v1')("okr/task/kr?okrId=".concat(okrId), {
    sortType: 1,
    work_id: okrId,
    startNum: 1,
    count: 20,
    relation: 1,
    app_id: 1,
    app_type: 1,
    to_user_id: userId,
    detail_type: 'pq',
    appId: 1,
    appType: 1,
    taskType: 0,
    toLevel: 999
  }).then(function (krs) {
    return krs.Data || [];
  });
};

exports.getKrs = getKrs;

var updateKrPrincipal = function updateKrPrincipal(_ref2) {
  var kr = _ref2.kr,
      user = _ref2.user;
  return (0, _request.rpost)('v1')("WorkMileStone/UpdatePrincipal?workMileStoneId=".concat(kr.mileStoneId), {
    endDate: kr.endDate,
    mileStoneName: kr.mileStoneName,
    principalId: user.userId,
    startDate: kr.startDate,
    workId: kr.workId,
    workMileStoneId: kr.mileStoneId
  });
};

exports.updateKrPrincipal = updateKrPrincipal;

var updateConfidenceIndex = function updateConfidenceIndex(_ref3) {
  var kr = _ref3.kr,
      confidenceIndex = _ref3.confidenceIndex;
  return (0, _request.rpost)('v1')("kr/updateConfidenceIndex?workMileStoneId=".concat(kr.mileStoneId), {
    confidenceIndex: confidenceIndex
  });
};

exports.updateConfidenceIndex = updateConfidenceIndex;

var updateOkrName = function updateOkrName(_ref4) {
  var workId = _ref4.workId,
      workName = _ref4.workName,
      workNameRichText = _ref4.workNameRichText,
      aiteUsers = _ref4.aiteUsers;
  return (0, _request.rpost)('v1')('okr/name', {
    workId: workId,
    workName: workName,
    workNameRichText: workNameRichText,
    aiteUsers: aiteUsers
  });
};

exports.updateOkrName = updateOkrName;

var getOkrDetail = function getOkrDetail(_ref5) {
  var okrId = _ref5.okrId;
  return (0, _request.rget)('v1')("okr/detailInfo?okrId=".concat(okrId)).then(function (headInfo) {
    if (headInfo.Code != 1) {
      throw headInfo.Message.replace(/项目/g, (0, _getLocale.getLocale)('Mod_Objective'));
    }

    return headInfo.Data;
  });
};

exports.getOkrDetail = getOkrDetail;

var getOkrApprovalSettingInfo = function getOkrApprovalSettingInfo() {
  return (0, _request.rget)('v1')('WorkManageSetting/GetOkrApproval');
};

exports.getOkrApprovalSettingInfo = getOkrApprovalSettingInfo;

var updateClassify = function updateClassify(_ref6) {
  var okrId = _ref6.okrId,
      okrClassify = _ref6.okrClassify;
  return (0, _request.rpost)('v1')("okr/update/classify?okrId=".concat(okrId), {
    okrClassify: okrClassify
  });
};

exports.updateClassify = updateClassify;

var updateOkrPrincipal = function updateOkrPrincipal(params) {
  return (0, _request.rpost)('v1')('Work/Deliver', _objectSpread({}, params), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateOkrPrincipal = updateOkrPrincipal;

var updateKrDate = function updateKrDate(_ref7) {
  var kr = _ref7.kr,
      startDate = _ref7.startDate,
      endDate = _ref7.endDate;
  return (0, _request.rpost)('v1')("WorkMileStone/UpdateDate?workMileStoneId=".concat(kr.mileStoneId), {
    startDate: startDate,
    endDate: endDate
  });
};

exports.updateKrDate = updateKrDate;

var updateKrProgressAndStatus = function updateKrProgressAndStatus(params) {
  return (0, _request.rpost)('v1')('kr/progressAndStatus/update', params);
};

exports.updateKrProgressAndStatus = updateKrProgressAndStatus;

var updateProgress = function updateProgress(params) {
  return (0, _request.rpost)('v2')('Work/progress', _objectSpread({}, params));
};

exports.updateProgress = updateProgress;

var createNewKr = function createNewKr(params) {
  return (0, _request.rpost)('v1')('kr/add', _objectSpread({
    MileStoneType: 3,
    confidenceIndex: 5
  }, params), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.createNewKr = createNewKr;

var getPraiseComments = function getPraiseComments(params) {
  var objId = params.objId,
      start = params.start,
      _params$count = params.count,
      count = _params$count === void 0 ? 9999 : _params$count,
      _params$objType = params.objType,
      objType = _params$objType === void 0 ? 10 : _params$objType;
  return (0, _request.rget)('v1')("praise/get?objId=".concat(objId, "&start=").concat(start, "&count=").concat(count, "&objType=").concat(objType));
};

exports.getPraiseComments = getPraiseComments;

var addPraise = function addPraise(feedId, type) {
  return (0, _request.rpost)('v1')("praise/feed?feedId=".concat(feedId, "&praiseType=").concat(type));
};

exports.addPraise = addPraise;

var cancelPraise = function cancelPraise(feedId) {
  return (0, _request.rpost)('v1')("praise/feed/cancel?feedId=".concat(feedId));
};

exports.cancelPraise = cancelPraise;

var getFeedById = function getFeedById(feedId, commentCount) {
  return (0, _request.rget)('v2')("user/feed/GetById?feed_id=".concat(feedId, "&comment_count=").concat(commentCount));
};

exports.getFeedById = getFeedById;

var updateParentId = /*#__PURE__*/function () {
  var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(params) {
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", (0, _request.rpost)('v1')("okr/updateParentId?okrId=".concat(params.okrId, "&parentId=").concat(params.parentId, "&parentType=").concat(params.parentId != 0 ? params.parentType : 0)));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));

  return function updateParentId(_x) {
    return _ref8.apply(this, arguments);
  };
}();

exports.updateParentId = updateParentId;

var cancelParentOkr = function cancelParentOkr(okrId) {
  return (0, _request.rpost)('v1')("okr/updateParentId?okrId=".concat(okrId, "&parentId=0&parentType=0"));
};

exports.cancelParentOkr = cancelParentOkr;

var getOrg = function getOrg() {
  return (0, _request.rget)('v1')('org/Get');
};

exports.getOrg = getOrg;

var getKrsByCondition = function getKrsByCondition(_ref9) {
  var okrId = _ref9.okrId,
      condition = _ref9.condition;
  return (0, _request.rpost)('v1')("okr/task/kr?okrId=".concat(okrId), condition, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  }).then(function (resp) {
    return resp.Data || [];
  });
};

exports.getKrsByCondition = getKrsByCondition;

var deleteKr = function deleteKr(mileStoneId) {
  return (0, _request.rpost)('v1')("WorkMileStone/Delete?workMileStoneId=".concat(mileStoneId));
};

exports.deleteKr = deleteKr;

var updateKrName = function updateKrName(params) {
  return (0, _request.rpost)('v1')("WorkMileStone/UpdateName?workMileStoneId=".concat(params.workMileStoneId), params).then(function (res) {
    if (res.Code) {
      return res;
    } else {
      _toast["default"].Error(res.Message || '操作异常，请刷新重试或联系客服');

      return false;
    }
  });
};

exports.updateKrName = updateKrName;

var updateTaskPrincipal = function updateTaskPrincipal(_ref10) {
  var task_id = _ref10.task_id,
      to_user_id = _ref10.to_user_id;
  return (0, _request.rpost)('v1')('task/UpdatePrincipal', {
    task_id: task_id,
    to_user_id: to_user_id
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateTaskPrincipal = updateTaskPrincipal;

var updateTaskDate = function updateTaskDate(_ref11) {
  var task_id = _ref11.task_id,
      endDate = _ref11.endDate,
      startDate = _ref11.startDate,
      isLongTerm = _ref11.isLongTerm;
  return (0, _request.rpost)('v1')("task/UpdateTaskDate?task_id=".concat(task_id), {
    task_id: task_id,
    Deadline: endDate,
    StartDate: startDate,
    IsLongTerm: isLongTerm
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateTaskDate = updateTaskDate;

var updateTaskStatus = function updateTaskStatus(_ref12) {
  var task_id = _ref12.task_id,
      status = _ref12.status;
  return (0, _request.rput)('v1')("PlanV2/UpdateStatus?plan_item_id=".concat(task_id, "&Status=").concat(status), {
    plan_item_id: task_id,
    Status: status
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateTaskStatus = updateTaskStatus;

var cancelRel = function cancelRel(_ref13) {
  var krId = _ref13.krId,
      objType = _ref13.objType,
      okrId = _ref13.okrId,
      taskId = _ref13.taskId;
  return (0, _request.rpost)('v1')('okr/task/cancelrel', {
    krId: krId,
    objType: objType,
    okrId: okrId,
    taskId: taskId
  });
}; // priority:5 非常低 4 低   3 中  2 高  1 最高


exports.cancelRel = cancelRel;

var setTaskPriority = function setTaskPriority(_ref14) {
  var task_id = _ref14.task_id,
      priority = _ref14.priority;
  return (0, _request.rpost)('v2')("task/SetTaskPriority?task_id=".concat(task_id, "&priority=").concat(priority), {});
};

exports.setTaskPriority = setTaskPriority;

var krChangeOrder = function krChangeOrder(params) {
  return (0, _request.rpost)('v1')("workMileStone/drag?workId=".concat(params.workId), params);
}; // type: 1 上级查看 2 更新


exports.krChangeOrder = krChangeOrder;

var remindAction = function remindAction(_ref15) {
  var toUserId = _ref15.toUserId,
      work_id = _ref15.work_id,
      _ref15$type = _ref15.type,
      type = _ref15$type === void 0 ? 1 : _ref15$type;
  return (0, _request.rpost)('v1')("work/notify/message?toUserId=".concat(toUserId), {
    objId: work_id,
    content: '',
    toUserId: toUserId,
    templateId: type === 1 ? 'TitaFeedSystem.Work.Okr.Message.RemindSuperiorLookOkrInfo' : 'TitaFeedSystem.Work.Okr.Message.RemindSubUpdateProgress'
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.remindAction = remindAction;

var getOkrUsers = function getOkrUsers(workId) {
  return (0, _request.rget)('v1')("okr/users?workId=".concat(workId));
};

exports.getOkrUsers = getOkrUsers;

var addComment = function addComment(data) {
  return (0, _request.rpost)('v2')('comment/Add', _objectSpread(_objectSpread({}, data), {}, {
    Content: data.Content || ' '
  }));
}; // okr request


exports.addComment = addComment;

var updateOkrVisibility = function updateOkrVisibility(data) {
  return (0, _request.rpost)('v2')('work/visiblity', data);
};

exports.updateOkrVisibility = updateOkrVisibility;

var addUser = function addUser(addUserId, okrId, relation) {
  return (0, _request.rpost)('v2')('work/addUser', {
    relation: relation,
    toUserIds: addUserId,
    workId: okrId
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.addUser = addUser;

var deleteUser = function deleteUser(delUserId, okrId, relation) {
  return (0, _request.rdelete)('v2')("work/deleteUser?toUserIds=".concat(delUserId, "&workId=").concat(okrId, "&relation=").concat(relation));
};

exports.deleteUser = deleteUser;

var workDelete = function workDelete(data) {
  return (0, _request.rdelete)('v1')("okr/deleteV2?workId=".concat(data.workId), {
    data: data
  });
};

exports.workDelete = workDelete;

var start = function start(okrId) {
  return (0, _request.rpost)('v1')('okr/Start', {
    work_id: okrId
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.start = start;

var close = function close(okrId) {
  return (0, _request.rpost)('v1')('okr/Close', {
    work_id: okrId
  }, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.close = close;

var updateOCommitType = function updateOCommitType(params) {
  return (0, _request.rpost)('v1')("okr/update/okrType?okrId=".concat(params.okrId), params, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateOCommitType = updateOCommitType;

var saveODesc = function saveODesc(workId, description) {
  return (0, _request.rpost)('v1')('okr/description', {
    workId: workId,
    description: description
  });
};

exports.saveODesc = saveODesc;

var transferPrincipal = function transferPrincipal(workId, email, toUserId) {
  return (0, _request.rpost)('v1')('Work/Deliver', "work_id=".concat(workId, "&to_user_id=").concat(toUserId), {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    }
  });
};

exports.transferPrincipal = transferPrincipal;

var updateOClassify = function updateOClassify(classify, workId) {
  return (0, _request.rpost)('v1')("okr/update/classify?okrId=".concat(workId), {
    work_id: workId,
    okrClassify: classify
  });
};

exports.updateOClassify = updateOClassify;

var updateVisibility = function updateVisibility(workId, visibility) {
  var areaUserIds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  var areaOrgIds = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  var areaGroupIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  return (0, _request.rpost)('v2')('work/visiblity', {
    workId: workId,
    visibility: visibility,
    areaUserIds: areaUserIds,
    areaOrgIds: areaOrgIds,
    areaGroupIds: areaGroupIds
  });
}; // relation 2：参与 3：关注


exports.updateVisibility = updateVisibility;

var addUserRelation = function addUserRelation(workId, relation, addUser) {
  return (0, _request.rpost)('v2')("work/addUserByObj?workId=".concat(workId, "&relation=").concat(relation), addUser);
};

exports.addUserRelation = addUserRelation;

var getProgress = function getProgress(workId) {
  return (0, _request.rget)('v1')("okr/GetProgress?work_id=".concat(workId, "&count=10000"));
};

exports.getProgress = getProgress;

var updateProgressDesc = function updateProgressDesc(commentId, workId, content) {
  return (0, _request.rpost)('v1')("progress/updateContent?commentId=".concat(commentId, "&objId=").concat(workId, "&objType=62"), {
    content: content
  });
};

exports.updateProgressDesc = updateProgressDesc;

var deleteProgressDesc = function deleteProgressDesc(commentId, workId) {
  return (0, _request.rpost)('v1')("progress/delete?commentId=".concat(commentId, "&objId=").concat(workId, "&objType=62"));
};

exports.deleteProgressDesc = deleteProgressDesc;

var getRelProgress = function getRelProgress(workId) {
  return (0, _request.rget)('v1')("okr/detail/relProgress?okrId=".concat(workId));
};

exports.getRelProgress = getRelProgress;

var getRelWorks = function getRelWorks(okrId) {
  return (0, _request.rget)('v1')("okr/detail/relWorks?okrId=".concat(okrId));
};

exports.getRelWorks = getRelWorks;

var updateChildOkrWeight = function updateChildOkrWeight(data) {
  return (0, _request.rpost)('v1')('okr/weight/save', {
    OkrWeights: _toConsumableArray(data)
  }, {
    // "headers": { "Content-Type": "application/x-www-form-urlencoded" },
    transformRequest: _qs["default"].stringify
  });
};

exports.updateChildOkrWeight = updateChildOkrWeight;

var updateOScore = function updateOScore(score, workId) {
  return (0, _request.rpost)('v2')('work/score', {
    manualScore: score,
    workId: workId
  });
};

exports.updateOScore = updateOScore;