"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.workRelateOkr = exports.workData = exports.updateLable = exports.relationWorks = exports.relateOkr = exports.planTableTask = exports.okrSearch = exports.getWorks = exports.getUserById = exports.getCategory = void 0;

var _request = require("@titaui/request");

var _helpers = require("../../utils/helpers");

var _getLoginUserInfo2;

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

var okrSearch = function okrSearch(params) {
  return (0, _request.rpost)("v1")("okr/search", _objectSpread(_objectSpread({}, params), {}, {
    orderType: 1,
    includeCreateFailApprovalOkr: false
  })).then(function (res) {
    return res.Data;
  });
};

exports.okrSearch = okrSearch;

var getCategory = function getCategory(params) {
  var pageSize = params.pageSize,
      pageNum = params.pageNum,
      _params$type = params.type,
      type = _params$type === void 0 ? 0 : _params$type,
      _params$keyWords = params.keyWords,
      keyWords = _params$keyWords === void 0 ? "" : _params$keyWords;
  var query = "pageSize=".concat(pageSize, "&pageNum=").concat(pageNum, "&type=").concat(type, "&keyWords=").concat(keyWords);
  return (0, _request.rget)("v1")("lable/get?".concat(query)).then(function (res) {
    return res.Data;
  });
};

exports.getCategory = getCategory;

var getWorks = function getWorks(params) {
  return (0, _request.rpost)("v2")("Work/GetByConditions", _objectSpread(_objectSpread({}, params), {}, {
    orderType: 1
  })).then(function (res) {
    return res.Data || {};
  });
}; // 任务关联


exports.getWorks = getWorks;

var updateLable = function updateLable(params) {
  var task_id = params.task_id,
      lab_id = params.lab_id,
      lab_type = params.lab_type,
      _params$mileStoneId = params.mileStoneId,
      mileStoneId = _params$mileStoneId === void 0 ? 0 : _params$mileStoneId;
  var url = "task/UpdateLable?task_id=".concat(task_id, "&lab_id=").concat(lab_id, "&lab_type=").concat(lab_type, "&mileStoneId=").concat(mileStoneId);
  return (0, _request.rpost)("v1")(url, _objectSpread({}, params)).then(function (res) {
    return res;
  });
}; // 关联其他


exports.updateLable = updateLable;

var relationWorks = function relationWorks(params) {
  return (0, _request.rpost)("v2")("task/relationWorkV2", _objectSpread({}, params)).then(function (res) {
    return res;
  });
};

exports.relationWorks = relationWorks;

var getUserById = function getUserById(userId) {
  return (0, _request.rget)("v2")("user/GetById?touserid=".concat(userId)).then(function (res) {
    return res.Data;
  });
};

exports.getUserById = getUserById;

var workData = function workData(params, pageNum, pageSize) {
  var _getLoginUserInfo;

  var _params$keyWords2 = params.keyWords,
      keyWords = _params$keyWords2 === void 0 ? "" : _params$keyWords2,
      _params$status = params.status,
      status = _params$status === void 0 ? 0 : _params$status,
      _params$relation = params.relation,
      relation = _params$relation === void 0 ? 0 : _params$relation,
      userIds = params.userIds;
  var url = "work/list?toUserId=".concat(userIds || ((_getLoginUserInfo = (0, _helpers.getLoginUserInfo)()) === null || _getLoginUserInfo === void 0 ? void 0 : _getLoginUserInfo.Id));
  return (0, _request.rpost)("v1")(url, {
    keyWords: keyWords,
    orderType: 1,
    pageNum: pageNum,
    pageSize: pageSize,
    relation: relation,
    status: status,
    userIds: userIds
  }).then(function (res) {
    return res;
  });
};

exports.workData = workData;

var dealMessage = function dealMessage(res) {
  var Code = res.Code,
      Data = res.Data;

  if (!!Code) {
    return Data;
  } else {
    return false;
  }
};

var id = (_getLoginUserInfo2 = (0, _helpers.getLoginUserInfo)()) === null || _getLoginUserInfo2 === void 0 ? void 0 : _getLoginUserInfo2.Id;

var planTableTask = function planTableTask(params, pageNum, pageSize) {
  var url = "task/search";
  var _params$startDate = params.startDate,
      startDate = _params$startDate === void 0 ? '' : _params$startDate,
      _params$endDate = params.endDate,
      endDate = _params$endDate === void 0 ? '' : _params$endDate,
      _params$keyWords3 = params.keyWords,
      keyWords = _params$keyWords3 === void 0 ? '' : _params$keyWords3,
      _params$status2 = params.status,
      status = _params$status2 === void 0 ? 10 : _params$status2,
      _params$planTableId = params.planTableId,
      planTableId = _params$planTableId === void 0 ? '' : _params$planTableId,
      _params$planTableType = params.planTableType,
      planTableType = _params$planTableType === void 0 ? '' : _params$planTableType,
      _params$relation2 = params.relation,
      relation = _params$relation2 === void 0 ? 0 : _params$relation2;

  if (status == 10) {
    status = '0,1,2,3,4,6';
  }

  if (!relation) {
    relation = '1,2';
  }

  var endDateResult = new Date(endDate || new Date().valueOf());
  endDateResult.setDate(endDateResult.getDate() + 1);
  return (0, _request.rpost)('v2')(url, {
    type: 'personal',
    to_user_id: id,
    StartDate: startDate,
    EndDate: "".concat(endDateResult.getFullYear(), "/").concat(endDateResult.getMonth() + 1, "/").concat(endDateResult.getDate()),
    startNum: pageNum,
    count: pageSize,
    planTableId: planTableId,
    planTableType: planTableType,
    fromLevel: 1,
    toLevel: 1,
    RelationType: relation,
    Status: status,
    FilterKey: keyWords,
    includeCreateFailApprovalOkr: false,
    userIds: "" + id
  }).then(function (res) {
    return dealMessage(res);
  });
};

exports.planTableTask = planTableTask;

var relateOkr = function relateOkr(selected, labelKrId, labelOId) {
  var taskRelationModel = {
    workId: labelOId,
    krId: labelKrId
  };
  var ids = [];
  selected.forEach(function (ele) {
    ids.push(ele.id);
  });
  var url = "task/relateOkrV2";
  return (0, _request.rpost)('v2')(url, {
    taskId: ids.join(','),
    taskRelationModels: [taskRelationModel]
  });
};

exports.relateOkr = relateOkr;

var workRelateOkr = function workRelateOkr(selected, labelKrId, labelOId) {
  var taskRelationModel = {
    workId: labelOId,
    krId: labelKrId
  };
  var ids = [];
  selected.forEach(function (ele) {
    ids.push(ele.id);
  });
  var url = "work/batch/relationOkr";
  return (0, _request.rpost)('v2')(url, {
    workId: ids.join(','),
    taskRelationModels: [taskRelationModel]
  });
};

exports.workRelateOkr = workRelateOkr;